Add helper function for color conversion.

This commit is contained in:
kovacsv 2021-12-28 17:19:26 +01:00
parent 53a7193d4c
commit 1213bbee22
2 changed files with 13 additions and 15 deletions

View File

@ -209,15 +209,6 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
ConvertThreeMaterial (threeMaterial)
{
function SetColor (color, threeColor)
{
color.Set (
parseInt (threeColor.r * 255.0, 10),
parseInt (threeColor.g * 255.0, 10),
parseInt (threeColor.b * 255.0, 10)
);
}
function CreateTexture (threeMap, objectUrlToFileName)
{
function GetDataUrl (img)
@ -270,12 +261,12 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
let material = new OV.PhongMaterial ();
material.name = threeMaterial.name;
SetColor (material.color, threeMaterial.color);
material.color = OV.ConvertThreeColorToColor (threeMaterial.color);
material.opacity = threeMaterial.opacity;
material.transparent = threeMaterial.transparent;
material.alphaTest = threeMaterial.alphaTest;
if (threeMaterial.type === 'MeshPhongMaterial') {
SetColor (material.specular, threeMaterial.specular);
material.specular = OV.ConvertThreeColorToColor (threeMaterial.specular);
material.shininess = threeMaterial.shininess / 100.0;
}
material.diffuseMap = CreateTexture (threeMaterial.map, this.objectUrlToFileName);

View File

@ -80,6 +80,15 @@ 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)
);
};
OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
{
let mesh = new OV.Mesh ();
@ -97,10 +106,8 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
let colors = threeGeometry.attributes.color.array;
let itemSize = threeGeometry.attributes.color.itemSize;
for (let i = 0; i < colors.length; i += itemSize) {
let x = colors[i];
let y = colors[i + 1];
let z = colors[i + 2];
mesh.AddVertexColor (new OV.Color (x * 255.0, y * 255.0, z * 255.0));
let threeColor = new THREE.Color (colors[i], colors[i + 1], colors[i + 2]);
mesh.AddVertexColor (OV.ConvertThreeColorToColor (threeColor));
}
}