Estoy tratando de jugar con partículas en three.js pero hay un problema al convertir el archivo obj (modelo 3D) en partículas en three.js. Los siguientes son los fragmentos de código. Lo intenté pero, todo falló.
¿Hay alguien que pueda ayudar a corregir los errores o proporcionar algún ejemplo de cómo obtener vértices/partículas de un modelo 3D en obj?
Muchas gracias.
var p_geom = new THREE.Geometry(); var p_material = new THREE.ParticleBasicMaterial({ color: 0xFFFFFF, size: 1.5 }); var loader = new THREE.OBJLoader(); loader.load( 'human.obj',function(object){ object.traverse( function(child){ if ( child instanceof THREE.Mesh ) { // child.material.map = texture; var scale = 10.0; object.attributes.position.array.forEach(function() { p_geom.vertices.push(new THREE.Vector3(this.x * scale, this.y * scale, this.z * scale)); }) } }); scene.add(p) }); p = new THREE.ParticleSystem( p_geom, p_material );Está utilizando una referencia de código obsoleta. Con la versión reciente three.js , el código se parece más al siguiente:
const loader = new THREE.OBJLoader(); loader.load('human.obj', function(object) { const vertices = []; object.traverse(function(child) { if (child.isMesh) { vertices.push(...child.geometry.attributes.position.array); } }); const p_geom = new THREE.BufferGeometry(); const p_material = new THREE.PointsMaterial({ color: 0xFFFFFF, size: 1.5 }); p_geom.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3)); const p = new THREE.Points(p_geom, p_material); p.scale.set(10, 10, 10); scene.add(p) });