提交 51528e26 编写于 作者: J jonobr1

added vertex color picking from fbxloader2

上级 28d0cd70
......@@ -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}
......@@ -1399,7 +1445,7 @@
/**
* @type {{
curves: Map<number, {
curves: Map<number, {
T: {
id: number;
attr: string;
......@@ -1519,7 +1565,7 @@
}
}>,
layers: Map<number, {
T: {
T: {
id: number;
attr: string;
internalID: number;
......@@ -1943,7 +1989,7 @@
/**
* @type {{
T: {
T: {
id: number;
attr: string;
internalID: number;
......@@ -3084,6 +3130,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 +3171,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 +3179,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorBuffer: colorBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
};
......@@ -3167,6 +3221,7 @@
var vertexBuffer = [];
var normalBuffer = [];
var uvBuffer = [];
var colorsBuffer = [];
var skinIndexBuffer = [];
var skinWeightBuffer = [];
......@@ -3178,6 +3233,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 +3243,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorsBuffer: colorsBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
};
......@@ -3245,6 +3302,7 @@
var vertexBuffer = [];
var normalBuffer = [];
var uvBuffer = [];
var colorsBuffer = [];
var skinIndexBuffer = [];
var skinWeightBuffer = [];
......@@ -3259,6 +3317,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 +3328,7 @@
vertexBuffer: vertexBuffer,
normalBuffer: normalBuffer,
uvBuffer: uvBuffer,
colorsBuffer: colorsBuffer,
skinIndexBuffer: skinIndexBuffer,
skinWeightBuffer: skinWeightBuffer,
materialIndexBuffer: materialIndexBuffer
......@@ -3305,6 +3365,7 @@
var vertexBuffer = [];
var normalBuffer = [];
var uvBuffer = [];
var colorsBuffer = [];
var skinIndexBuffer = [];
var skinWeightBuffer = [];
......@@ -3317,6 +3378,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 +3389,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.
先完成此消息的编辑!
想要评论请 注册