THREE.js custom tangent attribute how do i load it

2019-09-09 06:42发布

I'm looking at this example:

http://threejs.org/examples/webgl_custom_attributes.html

and notice that the custom displacement attribute gets filled by vertices.length

for ( var v = 0; v < vertices.length; v++ ) {
    values[ v ] = 0;
    noise[ v ] = Math.random() * 5;
    }

My question is, how does this relate to the number of normals, uvs and tangents?

When i export my model from 3ds max, i have more UVs than vertices. I need to assign tangents per this UV number because they are different at seams. I can't export a mesh that has double vertices at seams but while still keeping the averaged normals. But i have been able to export tangents and bitangents as another JSON model (i export them as vertex pos).

How exactly does all of this work, because i assume, even though that there are less vertices than UVs, the GPU actually breaks this apart and doubles the vertices at every UV seam, but i have no idea how to map all of this in the attribute buffer.

updated

I wrote a little exporter for max, basically mimicking the JSON structure:

"vertices": [floats],
"vertices_count": 486,
"uvs": [[floats]],
"uv_count": 364,
"PH_normal":[floats],
"PH_normal_count": 546,
"PH_tangent":[floats],
"PH_tangent_count": 546,
"PH_binormal":[floats],
"PH_binormals_count": 546,
"faces":[integers, actually the 42 structure from the json, i did it for comparison],
"PH_customIndex":[integers, this is how i mapped the values from exported normals,tangents and binormals to face3],
"PH_customIndexNum":960,
"PH_UVindex":[integers, this is how i mapped the values |faceVertexUvs[ 0 ][ 0 ]| from the exported uvs above],
"PH_UVindexNum":960,
"PH_FaceIndex":[integers, this is how i mapped the faces to vertices],
"PH_FaceIndexNum":960

My .geometry.faces[0] has an additional array called vertexBinormals in addition to vertexTangents and vertexNormals.

Essentially, i don't understand how to map these vertexBinormals values to an attribute and map it according to the rest. I was able to succeed in rendering what i wanted by copying the code for the tangent buffer (although i resized it to hold 3 values);

update2*

This actually seems to work fine (will post something live).

But the question would be, in case of the above export results, using:

var attributes= {
    bitangents: {
        type: 'v3',
        value: []
    }
};

The model has 320 faces, 162 vertices, and 182 uvs, normals, tangents and binormals. How should i fill this array in order to just give it to a shaderMaterial?

update initWebGLObjects() geometry.geometryGroupsList[A].faces3[]

gives a "faces3" array of 320 in the case above, then further down

if (Ha.tangentsNeedUpdate && Ha.hasTangents) {
    //loops through things and fills 
    j.bindBuffer(j.ARRAY_BUFFER, w.__webglTangentBuffer);

this buffer gets written in 3,840 times, 3 times per face 4 values each time. i filled another one in the same manner only using 3 values, and this seemed to have worked, the tangent normal map maps 1:1 to what i exported.

0条回答
登录 后发表回答