in packages/miew/src/io/exporters/fbx/FBXInfoExtractor.js [210:266]
_collectCylindersInfo(mesh) {
const {
geometry: {
attributes: {
position,
color,
color2,
},
index,
},
matrix,
} = mesh;
const model = new FBXModel();
const instCount = mesh.geometry.instanceCount;
const oneCCylinder = new FBX1CGeometry();
oneCCylinder.init(mesh.geometry);
const splittingInfo = this._gatherCylindersColoringInfo(mesh.geometry);
let twoCCylinder = null;
if (splittingInfo.needToSplit > 0) {
twoCCylinder = new FBX2CCylinder();
twoCCylinder.init(mesh.geometry, splittingInfo);
}
const additionalVertsCount = splittingInfo.addPerCylinder * splittingInfo.needToSplit;
const vertCount = position.count;
const indsCount = index.count;
model.init(instCount * vertCount + additionalVertsCount, instCount * indsCount);
const instMatrix = new THREE.Matrix4();
const objMatrix = new THREE.Matrix4();
const colorStart = new THREE.Color();
const colorEnd = new THREE.Color();
let geo = {};
for (let instanceIndex = 0; instanceIndex < instCount; ++instanceIndex) {
// update colors in geometry
const colorIdx = instanceIndex * color.itemSize;
if (splittingInfo.is2Colored[instanceIndex]) {
// .color2 contains starting color, and .color contains starting color (see uber.frag ATTR_COLOR2)
colorStart.fromArray(color2.array, colorIdx);
colorEnd.fromArray(color.array, colorIdx);
if (twoCCylinder) {
twoCCylinder.setColors(colorStart, colorEnd);
geo = twoCCylinder;
}
} else {
// has one color per cylinder
colorStart.fromArray(color.array, colorIdx);
oneCCylinder.setColors(colorStart);
geo = oneCCylinder;
}
// add instance to the model
this._getCylinderInstanceMatrix(mesh.geometry, instanceIndex, instMatrix);
objMatrix.multiplyMatrices(matrix, instMatrix);
model.addInstance(objMatrix, geo);
}
const material = this._collectMaterialInfo(mesh);
this._addToPool(model, material);
}