From 1213bbee2258e26ae433c13dd461e521a5bf5014 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Tue, 28 Dec 2021 17:19:26 +0100 Subject: [PATCH] Add helper function for color conversion. --- source/import/importerthree.js | 13 ++----------- source/threejs/threeutils.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/source/import/importerthree.js b/source/import/importerthree.js index b514117..b863ea8 100644 --- a/source/import/importerthree.js +++ b/source/import/importerthree.js @@ -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); diff --git a/source/threejs/threeutils.js b/source/threejs/threeutils.js index 884e8b9..e272005 100644 --- a/source/threejs/threeutils.js +++ b/source/threejs/threeutils.js @@ -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)); } }