Add utility function for color conversion.
This commit is contained in:
parent
74134c94a4
commit
31f622dede
@ -250,14 +250,14 @@ OV.Importer3ds = class extends OV.ImporterBase
|
||||
hasLinColor = true;
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_COLOR_F) {
|
||||
if (!hasLinColor) {
|
||||
color.r = parseInt (reader.ReadFloat32 () * 255.0, 10);
|
||||
color.g = parseInt (reader.ReadFloat32 () * 255.0, 10);
|
||||
color.b = parseInt (reader.ReadFloat32 () * 255.0, 10);
|
||||
color.r = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
|
||||
color.g = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
|
||||
color.b = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
|
||||
}
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_LIN_COLOR_F) {
|
||||
color.r = parseInt (reader.ReadFloat32 () * 255.0, 10);
|
||||
color.g = parseInt (reader.ReadFloat32 () * 255.0, 10);
|
||||
color.b = parseInt (reader.ReadFloat32 () * 255.0, 10);
|
||||
color.r = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
|
||||
color.g = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
|
||||
color.b = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
|
||||
hasLinColor = true;
|
||||
} else {
|
||||
this.SkipChunk (reader, chunkLength);
|
||||
|
||||
@ -39,10 +39,10 @@ OV.GltfConstants =
|
||||
|
||||
OV.GetGltfColor = function (color)
|
||||
{
|
||||
return new OV.Color (
|
||||
parseInt (Math.round (OV.LinearToSRGB (color[0]) * 255.0), 10),
|
||||
parseInt (Math.round (OV.LinearToSRGB (color[1]) * 255.0), 10),
|
||||
parseInt (Math.round (OV.LinearToSRGB (color[2]) * 255.0), 10)
|
||||
return OV.ColorFromFloatComponents (
|
||||
OV.LinearToSRGB (color[0]),
|
||||
OV.LinearToSRGB (color[1]),
|
||||
OV.LinearToSRGB (color[2])
|
||||
);
|
||||
};
|
||||
|
||||
@ -54,7 +54,7 @@ OV.GetGltfVertexColor = function (color, componentType)
|
||||
if (componentType !== OV.GltfComponentType.FLOAT) {
|
||||
normalized /= 255.0;
|
||||
}
|
||||
return parseInt (Math.round (OV.LinearToSRGB (normalized) * 255.0), 10);
|
||||
return OV.ColorComponentFromFloat (OV.LinearToSRGB (normalized));
|
||||
}
|
||||
|
||||
return new OV.Color (
|
||||
|
||||
@ -194,11 +194,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
|
||||
|
||||
GetMaterialIndexByColor (ifcColor)
|
||||
{
|
||||
const color = new OV.Color (
|
||||
parseInt (ifcColor.x * 255.0, 10),
|
||||
parseInt (ifcColor.y * 255.0, 10),
|
||||
parseInt (ifcColor.z * 255.0, 10)
|
||||
);
|
||||
const color = OV.ColorFromFloatComponents (ifcColor.x, ifcColor.y, ifcColor.z);
|
||||
|
||||
const materialName = 'Color ' +
|
||||
OV.IntegerToHexString (color.r) +
|
||||
|
||||
@ -193,15 +193,6 @@ OV.ImporterObj = class extends OV.ImporterBase
|
||||
|
||||
ProcessMaterialParameter (keyword, parameters, line)
|
||||
{
|
||||
function CreateColor (parameters)
|
||||
{
|
||||
return new OV.Color (
|
||||
parseInt (parseFloat (parameters[0] * 255.0), 10),
|
||||
parseInt (parseFloat (parameters[1] * 255.0), 10),
|
||||
parseInt (parseFloat (parameters[2] * 255.0), 10)
|
||||
);
|
||||
}
|
||||
|
||||
function CreateTexture (keyword, line, callbacks)
|
||||
{
|
||||
let texture = new OV.TextureMap ();
|
||||
@ -275,19 +266,19 @@ OV.ImporterObj = class extends OV.ImporterBase
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.ambient = CreateColor (parameters);
|
||||
this.currentMaterial.ambient = OV.ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
|
||||
return true;
|
||||
} else if (keyword === 'kd') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.color = CreateColor (parameters);
|
||||
this.currentMaterial.color = OV.ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
|
||||
return true;
|
||||
} else if (keyword === 'ks') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.specular = CreateColor (parameters);
|
||||
this.currentMaterial.specular = OV.ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
|
||||
return true;
|
||||
} else if (keyword === 'ns') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
|
||||
@ -20,6 +20,20 @@ OV.Color = class
|
||||
}
|
||||
};
|
||||
|
||||
OV.ColorComponentFromFloat = function (component)
|
||||
{
|
||||
return parseInt (Math.round (component * 255.0), 10);
|
||||
};
|
||||
|
||||
OV.ColorFromFloatComponents = function (r, g, b)
|
||||
{
|
||||
return new OV.Color (
|
||||
OV.ColorComponentFromFloat (r),
|
||||
OV.ColorComponentFromFloat (g),
|
||||
OV.ColorComponentFromFloat (b)
|
||||
);
|
||||
};
|
||||
|
||||
OV.SRGBToLinear = function (component)
|
||||
{
|
||||
if (component < 0.04045) {
|
||||
|
||||
@ -82,11 +82,7 @@ OV.GetShadingType = function (model)
|
||||
|
||||
OV.ConvertThreeColorToColor = function (threeColor)
|
||||
{
|
||||
return new OV.Color (
|
||||
parseInt (Math.round (threeColor.r * 255.0), 10),
|
||||
parseInt (Math.round (threeColor.g * 255.0), 10),
|
||||
parseInt (Math.round (threeColor.b * 255.0), 10)
|
||||
);
|
||||
return OV.ColorFromFloatComponents (threeColor.r, threeColor.g, threeColor.b);
|
||||
};
|
||||
|
||||
OV.ConvertColorToThreeColor = function (color)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user