提交 8df16442 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #10781 from jonobr1/fbx2-vertex-colors

added vertex color picking from fbxloader2
......@@ -599,6 +599,12 @@
}
if ( 'LayerElementColor' in geometryNode.subNodes ) {
var colorInfo = getColors( geometryNode );
}
if ( 'LayerElementMaterial' in geometryNode.subNodes ) {
var materialInfo = getMaterials( geometryNode );
......@@ -698,6 +704,12 @@
}
if ( colorInfo ) {
vertex.color.fromArray( getData( polygonVertexIndex, polygonIndex, vertexIndex, colorInfo ) );
}
faceVertexBuffer.push( vertex );
if ( endOfFace ) {
......@@ -733,6 +745,11 @@
geo.addAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( bufferInfo.uvBuffer ), 2 ) );
}
if ( bufferInfo.colorsBuffer.length > 0 ) {
geo.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( bufferInfo.colorsBuffer ), 4 ) );
}
if ( deformer ) {
......@@ -828,6 +845,35 @@
}
/**
* Parses Vertex Color information for geometry.
* @param {FBXGeometryNode} geometryNode
* @returns {{dataSize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}}
*/
function getColors( geometryNode ) {
var ColorNode = geometryNode.subNodes.LayerElementColor[ 0 ];
var mappingType = ColorNode.properties.MappingInformationType;
var referenceType = ColorNode.properties.ReferenceInformationType;
var buffer = parseFloatArray( ColorNode.subNodes.Colors.properties.a );
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
indexBuffer = parseFloatArray( ColorNode.subNodes.ColorIndex.properties.a );
}
return {
dataSize: 4,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
}
/**
* Parses material application information for geometry.
* @param {FBXGeometryNode}
......@@ -1165,6 +1211,11 @@
material = new THREE.MeshBasicMaterial( { color: 0x3300ff } );
}
if ( 'color' in geometry.attributes && geometry.attributes.color.count > 0 ) {
material.vertexColors = THREE.VertexColors;
}
if ( geometry.FBX_Deformer ) {
......@@ -1399,7 +1450,7 @@
/**
* @type {{
curves: Map<number, {
curves: Map<number, {
T: {
id: number;
attr: string;
......@@ -1519,7 +1570,7 @@
}
}>,
layers: Map<number, {
T: {
T: {
id: number;
attr: string;
internalID: number;
......@@ -1943,7 +1994,7 @@
/**
* @type {{
T: {
T: {
id: number;
attr: string;
internalID: number;
......@@ -3084,6 +3135,12 @@
*/
this.uv = new THREE.Vector2( );
/**
* Color of the vertex
* @type {THREE.Vector4}
*/
this.color = new THREE.Vector4();
/**
* Indices of the bones vertex is influenced by.
* @type {THREE.Vector4}
......@@ -3119,6 +3176,7 @@
var vertexBuffer = this.position.toArray();
var normalBuffer = this.normal.toArray();
var uvBuffer = this.uv.toArray();
var colorBuffer = this.color.toArray();
var skinIndexBuffer = this.skinIndices.toArray();
var skinWeightBuffer = this.skinWeights.toArray();
......@@ -3126,6 +3184,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorBuffer: colorBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
};
......@@ -3167,6 +3226,7 @@
var vertexBuffer = [];
var normalBuffer = [];
var uvBuffer = [];
var colorsBuffer = [];
var skinIndexBuffer = [];
var skinWeightBuffer = [];
......@@ -3178,6 +3238,7 @@
vertexBuffer = vertexBuffer.concat( flatVertex.vertexBuffer );
normalBuffer = normalBuffer.concat( flatVertex.normalBuffer );
uvBuffer = uvBuffer.concat( flatVertex.uvBuffer );
colorsBuffer = colorsBuffer.concat( flatVertex.colorBuffer );
skinIndexBuffer = skinIndexBuffer.concat( flatVertex.skinIndexBuffer );
skinWeightBuffer = skinWeightBuffer.concat( flatVertex.skinWeightBuffer );
......@@ -3187,6 +3248,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorsBuffer: colorsBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
};
......@@ -3245,6 +3307,7 @@
var vertexBuffer = [];
var normalBuffer = [];
var uvBuffer = [];
var colorsBuffer = [];
var skinIndexBuffer = [];
var skinWeightBuffer = [];
......@@ -3259,6 +3322,7 @@
vertexBuffer = vertexBuffer.concat( flatTriangle.vertexBuffer );
normalBuffer = normalBuffer.concat( flatTriangle.normalBuffer );
uvBuffer = uvBuffer.concat( flatTriangle.uvBuffer );
colorsBuffer = colorsBuffer.concat( flatTriangle.colorsBuffer );
skinIndexBuffer = skinIndexBuffer.concat( flatTriangle.skinIndexBuffer );
skinWeightBuffer = skinWeightBuffer.concat( flatTriangle.skinWeightBuffer );
materialIndexBuffer = materialIndexBuffer.concat( [ materialIndex, materialIndex, materialIndex ] );
......@@ -3269,6 +3333,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorsBuffer: colorsBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
materialIndexBuffer: materialIndexBuffer
......@@ -3305,6 +3370,7 @@
var vertexBuffer = [];
var normalBuffer = [];
var uvBuffer = [];
var colorsBuffer = [];
var skinIndexBuffer = [];
var skinWeightBuffer = [];
......@@ -3317,6 +3383,7 @@
vertexBuffer = vertexBuffer.concat( flatFace.vertexBuffer );
normalBuffer = normalBuffer.concat( flatFace.normalBuffer );
uvBuffer = uvBuffer.concat( flatFace.uvBuffer );
colorsBuffer = colorsBuffer.concat( flatFace.colorsBuffer );
skinIndexBuffer = skinIndexBuffer.concat( flatFace.skinIndexBuffer );
skinWeightBuffer = skinWeightBuffer.concat( flatFace.skinWeightBuffer );
materialIndexBuffer = materialIndexBuffer.concat( flatFace.materialIndexBuffer );
......@@ -3327,6 +3394,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorsBuffer: colorsBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
materialIndexBuffer: materialIndexBuffer
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册