How to access and console.log the points size of the imported PCD file?
Here is the list of the scene's attributes and within it is the PCD object:
enter image description here
Here is the part of the code for loading my PCD model and how I accessed the children's length array but I can't access the size points:
const loader = new PCDLoader();
loader.load( 'pointcloud.pcd', function ( points ) {
scene.add( points );
render() } );
const obj = scene.getObjectByProperty('pointcloud.pcd').children.length
console.log(obj)
console.log(scene)
Related
I would like to rotate the coordinate axes of specific segments of a .fbx model. E.g. as illustrated on the image I would like to rotate the coordinate axes of the right arm 90 degress around the Z-axis.
I can see that THREE.Object3D.DefaultUp can change the default coordinate system of an object, but I cannot apply it to the fbx segment objects.
Just to be clear, I dont want to rotate the mesh/arm, but only the coordinate axes that define the arms rotation. Is that possible?
I load the .fbx model and define the arm as so:
// model
const loader = new THREE.FBXLoader();
loader.load( '{{ url_for('static', filename='ybot.fbx') }}', function ( object ) {
myObj = object;
myObj.traverse( function ( child ) {
if ( child.isMesh ) {
child.castShadow = true;
child.receiveShadow = true;
}
});
rightArm = myObj.getObjectByName('mixamorigRightArm');
// Do the rotations here
scene.add( myObj );
});
}
I'm importing a .glb model and have in this file some materials that are not applied to any meshes.
So my question is in in THREE.JS exist something like a array of all materials that are in the scene or if I can get some how my materials when load the model with GLTFLoader.
You can traverse through the parsed glTF asset and collect all materials in a set. Something like:
const materials = new Set();
const scene = gltf.scene;
scene.traverse( function( object ) {
if ( object.material ) materials.add( object.material );
} );
How can I call textureLoader.load only once and assign a map name to each texture and so that it I can call creating the material when all the textures have loaded?
Otherwise I can't control when to create the material and assign the textures correctly.
I am working with obj without loading mtl.
Thank you for your help
This is the code I'm asking to replace for one function textureLoader.load
var textureLoader = new THREE.TextureLoader(manager);
var albedoM = textureLoader.load( "vaseTextures/albedo.png", onLoad, onProgress, onError );
var normalMap = textureLoader.load( "vaseTextures/normal.png", onLoad, onProgress, onError );
var aoMap = textureLoader.load( "vaseTextures/cavity.png", onLoad, onProgress, onError );
Expected result: I call once function onLoad( texture) after the textures are loaded and saving a name for each texture, and so that I can then create one material that holds each texture and assign the textures to it.
In this case, it's best to use the onLoad() callback of THREE.LoadingManager. It will be executed as soon as all resources are loaded. Since you already pass an instance of THREE.LoadingManager to your texture loader, you just have to implement onLoad(). For example like so:
manager.onLoad = function ( ) {
const material = new THREE.MeshPhongMaterial();
material.map = albedoM;
material.normalMap = normalMap;
material.aoMap = aoMap;
// do something with your material
};
three.js R103
I am using OBJloader to load an .obj file in WEBGL , Three.js.
I want to access the vertices and faces of the objects but the geometry.vertices does not return the vertices positions and it gives me undefined.
Here is a piece of code:
var tool= new THREE.OBJLoader();
tool.load( '../obj/tool.obj', function ( object ) {
var material = new THREE.MeshLambertMaterial({color:0xA0A0A0});
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = material;
console.log( "child" + child.geometry.vertices);} }
r.70
I am thankful for your helps in advance.
This answer only applies to versions of three.js prior to r.125.
If the loader you are using is returning BufferGeometry, you can convert the returned geometry to Geometry in the loader callback using a pattern like so:
var geometry = new THREE.Geometry().fromBufferGeometry( bufferGeometry );
three.js r.124
I create a scene, add a couple of boxes and I can move the camera with the keyboard just fine.
I want to add a 3D model. In several tutorials, I saw something like:
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load( "test.js", function( geometry ) { createScene( geometry) } );
function createScene( geometry ) {
var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial({color: 0xbbbbbb}) );
mesh.scale.set(10, 10, 10);
mesh.position.y = -350;
mesh.position.x = -650;
group.add(mesh);
}
But for the other element I wrote something like:
MovingCube = new THREE.Mesh(MovingCubeGeom, new THREE.MeshFaceMaterial());
MovingCube.position.set(0, 25, 0);
scene.add(MovingCube);
How can I add a 3D model from a .js converted .obj at my scene?
The first one loads the model from and external file which contains a JSON representation of the geometry and sends it to the createScene function as an instance of the THREE.Geometry class when the external file has finished loading.
The second one the geometry is already in the variable MovingCubeGeom.
The second example is basically the same as what is in the createScene function of the first example.
You don't need to convert an obj to js, you can just use the THREE.OBJLoader class