Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified parser.DAE to deal with specular textures #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/parsers/parserDAE.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ var parserDAE = {
material.opacity = material.transparency; //why? dont know but works
}

//Litescene expects a single value for specular_factor, some exporters provide RGB,
//which is parsed to a Float32Array by collada.js
if(material.specular_factor) {
if (material.specular_factor instanceof Float32Array) {
//then we need to convert from (RGB) array to single value
var sum = 0;
for (var i = 0; i < material.specular_factor.length; i++) {
sum += material.specular_factor[i];
}
sum /= material.specular_factor.length;
//reassign property to the average
material.specular_factor = sum;
}
}

if(material.textures)
{
for(var i in material.textures)
Expand All @@ -299,6 +314,16 @@ var parserDAE = {
};
material.textures[i] = tex_info;
}

//if the specular node of the collada was a texture, it will appear as a texture
//but with the wrong name ("specular_factor" instead of "specular")
//also the material.specular_factor property won't be set
//so here we fix all that
if (material.textures.hasOwnProperty("specular_factor")) {
material.textures["specular"] = material.textures["specular_factor"];
delete material.textures["specular_factor"];
material.specular_factor = 1.0;
}
}
}
};
Expand Down