THREE.ExplodeModifier黑客攻击

时间:2015-12-14 23:03:26

标签: javascript three.js

我正在使用ExplodeModifier来复制顶点,这样我就可以对Face3个对象进行单独控制。 就我的具体例子来说,这一点看起来看起来很差,所以我决定添加3个额外的面(每个现有的面),这样我可以有一个金字塔形状指向几何体。

我设法修改了ExplodeModifier并创建了额外的面,但是我遇到了几个错误:

  

THREE.DirectGeometry.fromGeometry():未定义的vertexUv和THREE.BufferAttribute.copyVector3sArray():vector未定义

据我所知,现在每个脸上有9个额外的顶点,所以我需要根据uv的,因为我不需要纹理而是纯色我不介意错误的uvs ...所以,我也是重复uvs并避免第一次警告,但我无法摆脱copyVector2sArray ......

伪代码:

var geometry = new THREE.IcosahedronGeometry( 200, 1 );
var material = new THREE.MeshPhongMaterial( { shading: THREE.FlatShading } );

var explodeModifier = new THREE.ExplodeModifier();
explodeModifier.modify( geometry );

var mesh = new THREE.Mesh( geometry, material );
scene.addChild( mesh );

爆炸修改器具有以下伪代码:

var vertices = [];
var faces = [];

for ( var i = 0, il = geometry.faces.length; i < il; i ++ ) {
    (...)

    var extraFace1 = new THREE.Face3().copy(face)
    extraFace1.c = geometry.vertices[0]

    var extraFace2 = new THREE.Face3().copy(face)
    extraFace2.b = geometry.vertices[0]

    var extraFace3 = new THREE.Face3().copy(face)
    extraFace3.a = geometry.vertices[0]

    faces.push( extraFace1 );
    faces.push( extraFace2 );
    faces.push( extraFace3 );
}

geometry.vertices = vertices;
geometry.faces = faces;

```

我添加了一个示例HERE。它有效,但我想避免控制台警告...

1 个答案:

答案 0 :(得分:2)

正如@mrdoob指出的那样,我为添加的THREE.Vector3分配了index而非THREE.Face3

 var extraFace1 = new THREE.Face3().copy(face)
 extraFace1.a = geometry.faces.length * 3 - 1

 var extraFace2 = new THREE.Face3().copy(face)
 extraFace2.b = geometry.faces.length * 3 - 1

 var extraFace3 = new THREE.Face3().copy(face)
 extraFace3.c = geometry.faces.length * 3 - 1

jsfiddle updated