I have encountered an issue while attempting to merge two PLY files using the PLYLoader method. How can I simultaneously access the Geometry of both loaders?
After loading the two ply files and defining a new BufferGeometry for the combined shape, I found that the variables mesh1
and mesh2
were undefined when trying to access the geometry properties.
Below is the code snippet:
// ...
var mesh1, material1;
var mesh2, material2;
var singleGeometry, material, mesh;
// ...
init();
animate();
singleGeometry = BufferGeometry();
function init() {
// ...
singleGeometry = new THREE.BufferGeometry();
// ...
var loader = new THREE.PLYLoader();
loader.load("path/ply1.ply", function(geometry) {
geometry.computeVertexNormals();
material = new THREE.MeshStandardMaterial({ color: 0x0055ff, flatShading: true });
mesh1 = new THREE.Mesh(geometry, material);
mesh1.position.y = -0.2;
mesh1.position.z = 0.3;
mesh1.rotation.x = -Math.PI / 2;
mesh1.scale.multiplyScalar(0.01);
mesh1.castShadow = true;
mesh1.receiveShadow = true;
});
loader.load("path/ply2.ply", function(geometry) {
geometry.computeVertexNormals();
material = new THREE.MeshStandardMaterial({ color: 0x0055ff, flatShading: true });
mesh2 = new THREE.Mesh(geometry, material);
mesh2.position.x = -0.2;
mesh2.position.y = -0.02;
mesh2.position.z = -0.2;
mesh2.scale.multiplyScalar(0.0006);
mesh2.castShadow = true;
mesh2.receiveShadow = true;
});
singleGeometry.mergeBufferGeometries([mesh1.geometry, mesh2.geometry]);
material = new THREE.MeshPhongMaterial({ color: 0xff0000 });
mesh = new THREE.Mesh(singleGeometry, material);
scene.add(mesh);
}