我目前正在玩ThreeJS decals。我已经能够在我的球体上涂上一个漂亮的污点。
这是我用来在球体上“应用”贴花的一段代码。(我有一些自定义类,但不用担心这个。
// Create sphere
var mainMesh = new THREE.Mesh(
new THREE.SphereGeometry(7, 16, 16),
new THREE.MeshBasicMaterial({ color: 0x00a1fd })
);
// Declare decal material
var decalMaterial = new THREE.MeshPhongMaterial({
color : 0xff0000,
specular : 0x444444,
map : TextureLoader.instance.getTexture('http://threejs.org/examples/textures/decal/decal-diffuse.png'),
normalMap : TextureLoader.instance.getTexture('http://threejs.org/examples/textures/decal/decal-normal.jpg'),
normalScale : new THREE.Vector2( 1, 1 ),
shininess : 30,
transparent : true,
depthTest : true,
depthWrite : false,
polygonOffset : true,
polygonOffsetFactor : -4,
wireframe : false
});
// Create decal itself
var decal = new THREE.Mesh(
new THREE.DecalGeometry(
mainMesh,
new THREE.Vector3(0, 2.5, 3),
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(8, 8, 8),
new THREE.Vector3(1, 1, 1)
),
decalMaterial.clone()
);
// Add mesh + decal + helpers
scene.add(
mainMesh,
new THREE.HemisphereLight(0xffffff, 0, 1),
decal,
new THREE.WireframeHelper(decal, 0xffff00)
);
decal.add(new THREE.BoxHelper(decal, 0xffff00));现在,我想要移动这个污点在我的球体上,因此,更新我的贴花的几何形状。
不幸的是,当我调用decal.geometry.computeDecal()时,贴花的网格没有更新。对此我找不到任何解决方案。
function moveDecal()
{
decal.translateX(1);
decal.geometry.computeDecal();
};根据DecalGeometry类,函数computeDecal已经设置为true更新顶点、颜色、UV、...所需的各种成员。
this.computeDecal = function() {
// [...]
this.verticesNeedUpdate = true;
this.elementsNeedUpdate = true;
this.morphTargetsNeedUpdate = true;
this.uvsNeedUpdate = true;
this.normalsNeedUpdate = true;
this.colorsNeedUpdate = true;
};谢谢你的帮助!:D
PS:ThreeJS r80
发布于 2016-09-22 03:28:36
您正在尝试更新几何体的顶点。
您可以更改顶点组件的值,
geometry.vertices[ 0 ].x += 1;但是你不能添加新的顶点
geometry.vertices.push( new THREE.Vector3( x, y, z ) ); // not allowed或者指定一个新的顶点数组
geometry.vertices = new_array; // not allowed在几何图形至少渲染一次之后。
类似地,用于其他属性,如UV。
有关更多信息,请参阅此答案:verticesNeedUpdate in Three.js。
three.js r.80
https://stackoverflow.com/questions/39619870
复制相似问题