未验证 提交 799f87a9 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #13490 from Mugen87/dev3

ColladaLoader: Better support of textured/non-textured materials
......@@ -2044,7 +2044,8 @@ THREE.ColladaLoader.prototype = {
material: xml.getAttribute( 'material' ),
count: parseInt( xml.getAttribute( 'count' ) ),
inputs: {},
stride: 0
stride: 0,
hasUV: false
};
for ( var i = 0, l = xml.childNodes.length; i < l; i ++ ) {
......@@ -2061,6 +2062,7 @@ THREE.ColladaLoader.prototype = {
var offset = parseInt( child.getAttribute( 'offset' ) );
primitive.inputs[ semantic ] = { id: id, offset: offset };
primitive.stride = Math.max( primitive.stride, offset + 1 );
if ( semantic === 'TEXCOORD' ) primitive.hasUV = true;
break;
case 'vcount':
......@@ -2097,6 +2099,30 @@ THREE.ColladaLoader.prototype = {
}
function checkUVCoordinates( primitives ) {
var count = 0;
for ( var i = 0, l = primitives.length; i < l; i ++ ) {
var primitive = primitives[ i ];
if ( primitive.hasUV === true ) {
count ++;
}
}
if ( count > 0 && count < primitives.length ) {
primitives.uvsNeedsFix = true;
}
}
function buildGeometry( data ) {
var build = {};
......@@ -2114,9 +2140,15 @@ THREE.ColladaLoader.prototype = {
for ( var type in groupedPrimitives ) {
// second, we create for each type of primitives (polylist,triangles or lines) a buffer geometry
var primitiveType = groupedPrimitives[ type ];
// second, ensure consistent uv coordinates for each type of primitives (polylist,triangles or lines)
checkUVCoordinates( primitiveType );
build[ type ] = buildGeometryType( groupedPrimitives[ type ], sources, vertices );
// third, create a buffer geometry for each type of primitives
build[ type ] = buildGeometryType( primitiveType, sources, vertices );
}
......@@ -2193,6 +2225,7 @@ THREE.ColladaLoader.prototype = {
switch ( key ) {
case 'POSITION':
var prevLength = position.array.length;
buildGeometryData( primitive, sources[ id ], input.offset, position.array );
position.stride = sources[ id ].stride;
......@@ -2201,6 +2234,22 @@ THREE.ColladaLoader.prototype = {
buildGeometryData( primitive, sources.skinIndices, input.offset, skinIndex.array );
buildGeometryData( primitive, sources.skinWeights, input.offset, skinWeight.array );
}
// see #3803
if ( primitive.hasUV === false && primitives.uvsNeedsFix === true ) {
var count = ( position.array.length - prevLength ) / position.stride;
for ( var i = 0; i < count; i ++ ) {
// fill missing uv coordinates
uv.array.push( 0, 0 );
}
}
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册