Add helper function for color conversion.
This commit is contained in:
parent
53a7193d4c
commit
1213bbee22
@ -209,15 +209,6 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
|
|||||||
|
|
||||||
ConvertThreeMaterial (threeMaterial)
|
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 CreateTexture (threeMap, objectUrlToFileName)
|
||||||
{
|
{
|
||||||
function GetDataUrl (img)
|
function GetDataUrl (img)
|
||||||
@ -270,12 +261,12 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
|
|||||||
|
|
||||||
let material = new OV.PhongMaterial ();
|
let material = new OV.PhongMaterial ();
|
||||||
material.name = threeMaterial.name;
|
material.name = threeMaterial.name;
|
||||||
SetColor (material.color, threeMaterial.color);
|
material.color = OV.ConvertThreeColorToColor (threeMaterial.color);
|
||||||
material.opacity = threeMaterial.opacity;
|
material.opacity = threeMaterial.opacity;
|
||||||
material.transparent = threeMaterial.transparent;
|
material.transparent = threeMaterial.transparent;
|
||||||
material.alphaTest = threeMaterial.alphaTest;
|
material.alphaTest = threeMaterial.alphaTest;
|
||||||
if (threeMaterial.type === 'MeshPhongMaterial') {
|
if (threeMaterial.type === 'MeshPhongMaterial') {
|
||||||
SetColor (material.specular, threeMaterial.specular);
|
material.specular = OV.ConvertThreeColorToColor (threeMaterial.specular);
|
||||||
material.shininess = threeMaterial.shininess / 100.0;
|
material.shininess = threeMaterial.shininess / 100.0;
|
||||||
}
|
}
|
||||||
material.diffuseMap = CreateTexture (threeMaterial.map, this.objectUrlToFileName);
|
material.diffuseMap = CreateTexture (threeMaterial.map, this.objectUrlToFileName);
|
||||||
|
|||||||
@ -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)
|
OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
||||||
{
|
{
|
||||||
let mesh = new OV.Mesh ();
|
let mesh = new OV.Mesh ();
|
||||||
@ -97,10 +106,8 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
|||||||
let colors = threeGeometry.attributes.color.array;
|
let colors = threeGeometry.attributes.color.array;
|
||||||
let itemSize = threeGeometry.attributes.color.itemSize;
|
let itemSize = threeGeometry.attributes.color.itemSize;
|
||||||
for (let i = 0; i < colors.length; i += itemSize) {
|
for (let i = 0; i < colors.length; i += itemSize) {
|
||||||
let x = colors[i];
|
let threeColor = new THREE.Color (colors[i], colors[i + 1], colors[i + 2]);
|
||||||
let y = colors[i + 1];
|
mesh.AddVertexColor (OV.ConvertThreeColorToColor (threeColor));
|
||||||
let z = colors[i + 2];
|
|
||||||
mesh.AddVertexColor (new OV.Color (x * 255.0, y * 255.0, z * 255.0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user