Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions examples/jsm/exporters/ColladaExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,31 @@ class ColladaExporter {

// gets the attribute array. Generate a new array if the attribute is interleaved
const getFuncs = [ 'getX', 'getY', 'getZ', 'getW' ];
const tempColor = new Color();

function attrBufferToArray( attr ) {
function attrBufferToArray( attr, isColor = false ) {

if ( attr.isInterleavedBufferAttribute ) {
console.log( attr, attr.count, isColor )
if ( isColor ) {

// convert the colors to srgb before export
// colors are always written as floats
const arr = new Float32Array( attr.count * 3 );
for ( let i = 0, l = attr.count; i < l; i ++ ) {

tempColor
.fromBufferAttribute( attr, i )
.convertLinearToSRGB();

arr[ 3 * i + 0 ] = tempColor.r;
arr[ 3 * i + 1 ] = tempColor.g;
arr[ 3 * i + 2 ] = tempColor.b;

}

return arr;

} else if ( attr.isInterleavedBufferAttribute ) {

// use the typed array constructor to save on memory
const arr = new attr.array.constructor( attr.count * attr.itemSize );
Expand Down Expand Up @@ -183,9 +204,9 @@ class ColladaExporter {
}

// Returns the string for a geometry's attribute
function getAttribute( attr, name, params, type ) {
function getAttribute( attr, name, params, type, isColor = false ) {

const array = attrBufferToArray( attr );
const array = attrBufferToArray( attr, isColor );
const res =
`<source id="${ name }">` +

Expand Down Expand Up @@ -296,8 +317,9 @@ class ColladaExporter {
// serialize colors
if ( 'color' in bufferGeometry.attributes ) {

// colors are always written as floats
const colName = `${ meshid }-color`;
gnode += getAttribute( bufferGeometry.attributes.color, colName, [ 'X', 'Y', 'Z' ], 'uint8' );
gnode += getAttribute( bufferGeometry.attributes.color, colName, [ 'R', 'G', 'B' ], 'float', true );
triangleInputs += `<input semantic="COLOR" source="#${ colName }" offset="0" />`;

}
Expand Down Expand Up @@ -419,6 +441,10 @@ class ColladaExporter {
const shininess = m.shininess || 0;
const reflectivity = m.reflectivity || 0;

emissive.convertLinearToSRGB();
specular.convertLinearToSRGB();
diffuse.convertLinearToSRGB();

// Do not export and alpha map for the reasons mentioned in issue (#13792)
// in three.js alpha maps are black and white, but collada expects the alpha
// channel to specify the transparency
Expand Down