1

我有这样的输出日期:

geom[0] = {

texturesindexT: new Int16Array([0,1,2,3]),
texturesindexS: new Int16Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,...]),

materialsindexT: new Int16Array([-1,-1,-1,-1]),
materialsindexS: new Int16Array([-1,0,1,2,3,4,5,0,6,2,7,8,-1,0,...]),

startIndicesT: new Uint32Array([0,288,606,897,1380]),
startIndicesS: new Uint32Array([1380,1431,1479,1485,1497,1515,1659,...]),

m_indices: new Uint16Array([0,1,2,3,0,2,4,2,5,4,6,2,7,3,2,8,9,10,...]),

m_vertices: new Float32Array([-81.93996,25.7185,-85.53822,-81.93996,...]),

m_normals: new Float32Array([-0.004215205,0.9999894,-0.001817489,-0.004215205,...]),

m_texCoords: new Float32Array([0,0.04391319,0,0.2671326,0.009521127,0.03514284,...]),

}

var textures = new Array("-1_-1/t0.jpg","-1_-1/t1.jpg","-1_-1/t2.jpg",...);

数据用于索引、顶点和法线缓冲区,但部分必须使用其他纹理和 Maretials 渲染。

我试图从索引、顶点和 texCoords/UVCoords 中创建一个 THREE.Geometry ,但这没有用。

现在我正在尝试使用 THREE.BufferGeometry() 和这项工作,但我需要使用纹理“纹理 [0]”渲染索引 0 到 287,使用“纹理 [1]”渲染索引 288 到 605,依此类推。

我的第一次尝试是为索引为 288 到 605 的每个部分制作一个 BufferGeometry ,但由于索引是为了孔模型,我必须将完整的顶点、法线和 UVCoords 放在缓冲区中,只为几个面。

有没有办法用其他纹理渲染 BufferGeometry 的部分或为每个面设置纹理索引?

或者是否可以创建一个材质,用纹理 A 渲染第一个 X 面,然后用纹理 B 渲染下一个?

4

2 回答 2

1

您可以创建两个具有相同顶点缓冲区和不同索引的几何图形:

var position = new THREE.BufferAttribute(positionArray, 3);
var normal = new THREE.BufferAttribute(normalArray, 3);
var uv = new THREE.BufferAttribute(uvArray, 2);

var indices1 = new THREE.BufferAttribute(indexArray1, 1);
var geometry1 = new THREE.BufferGeometry();
geometry1.addAttribute('position', position);
geometry1.addAttribute('normal', normal);
geometry1.addAttribute('uv', uv);
geometry1.addAttribute('index', indices1);

var indices2 = new THREE.BufferAttribute(indexArray2, 1);
var geometry2 = new THREE.BufferGeometry();
geometry2.addAttribute('position', position);
geometry2.addAttribute('normal', normal);
geometry2.addAttribute('uv', uv);
geometry2.addAttribute('index', indices2);

然后像往常一样使用不同的材料创建 2 个网格。据我了解,这将在两个网格中重复使用相同的数据。

于 2015-02-21T20:14:42.783 回答
1

如果你想使用两个不同的纹理BufferGeometry,你可以使用这个模式,它设置drawcalls

var geometry1 = new THREE.BufferGeometry();
// ...and set the data...
var geometry2 = geometry1.clone();

// set drawcalls
geometry1.offsets = geometry1.drawcalls = []; // currently required
geometry1.addDrawCall( start1, count1, 0 );

geometry2.offsets = geometry2.drawcalls = []; // currently required
geometry2.addDrawCall( start2, count2, 0 );

var material1 = new THREE.MeshPhongMaterial( { map: map1 } );
var material2 = new THREE.MeshPhongMaterial( { map: map2 } );

var mesh1 = new THREE.Mesh( geometry1, material1 );
var mesh2 = new THREE.Mesh( geometry2, material2 );

三.js r.70

于 2015-02-21T16:46:25.770 回答