three.js - 更新(复制?)对象位置

时间:2017-07-10 08:34:29

标签: javascript three.js

我只是为另一个网格的每个顶点实例化一个对象,并将一些变形目标应用到最后一个网格。不幸的是,当我调整大网格的形状时,实例化的小网格根本不会移动!他们像英国女王的守卫一样静止不动。 我的问题是:有没有办法让小家伙跟随另一个人的顶点?请记住,我正在使用带有数组的for循环,我会为每个顶点推送object2.clone()

提前致谢!

更新:这是我正在使用的代码的一部分:

// some stuff before
var mesh = new THREE.Mesh( geometry, material );
// SFERETTE
var sfera = new THREE.SphereGeometry(1.5, 24, 20, 0, Math.PI * 2, 0, Math.PI * 2);
var material2 = new THREE.MeshLambertMaterial( {
    color: 0x005c6c
} );

var mesh2 = new THREE.Mesh( sfera, material2 );

// ARRAY POSIZIONAMENTO VERTICI
var sferetta = mesh2.clone();
sferetta.matrixWorldNeedsUpdate = true;
sferetta.position.needsUpdate = true;
//  sferetta.matrixAutoUpdate = false;

var vertexArray = [];
for (var i = 0; i < geometry.vertices.length; i++) {
    vertexArray.push(geometry.vertices[i])
}
for (var i = 0; i < vertexArray.length; i++) {
    sferetta.position.set(vertexArray[i].x, vertexArray[i].y, vertexArray[i].z)

    mesh.add(sferetta.clone())
}
// TUTTA LA GIOSTRA SM

scene.add( mesh );

// MORPHING
var params = {
    influence1: 0,
    influence2: 0,
    influence3: 0,
    influence4: 0,
    influence5: 0,
    influence6: 0,
    influence7: 0,
    influence8: 0,
    influence9: 0,
    influence10: 0,
    influence11: 0,
    influence12: 0,
    influence13: 0,
    influence14: 0,
    influence15: 0,
    influence16: 0
};
var gui = new dat.GUI();
var folder = gui.addFolder( 'Morph Targets' );
folder.add( params, 'influence1', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 0 ] = value; } );
folder.add( params, 'influence2', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 1 ] = value; } );
folder.add( params, 'influence3', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 2 ] = value; } );
folder.add( params, 'influence4', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 3 ] = value; } );
folder.add( params, 'influence5', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 4 ] = value; } );
folder.add( params, 'influence6', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 5 ] = value; } );
folder.add( params, 'influence7', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 6 ] = value; } );
folder.add( params, 'influence8', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 7 ] = value; } );
folder.add( params, 'influence9', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 8 ] = value; } );
folder.add( params, 'influence10', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 9 ] = value; } );
folder.add( params, 'influence11', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 10 ] = value; } );
folder.add( params, 'influence12', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 11 ] = value; } );
folder.add( params, 'influence13', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 12 ] = value; } );
folder.add( params, 'influence14', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 13 ] = value; } );
folder.add( params, 'influence15', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 14 ] = value; } );
folder.add( params, 'influence16', 0, 1 ).step( 0.01 ).onChange( function( value ) { mesh.morphTargetInfluences[ 15 ] = value; } );
folder.open();

0 个答案:

没有答案