From 8062aec93d52d5c4159b920a18657906b8f5ec63 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sun, 8 Aug 2021 09:16:55 +0200 Subject: [PATCH] Minor modification. --- source/threejs/threeimporter.js | 39 ++++++++++++++++++++++++++++++++- source/threejs/threeutils.js | 37 ------------------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/source/threejs/threeimporter.js b/source/threejs/threeimporter.js index c0a42d8..dfd1f77 100644 --- a/source/threejs/threeimporter.js +++ b/source/threejs/threeimporter.js @@ -116,13 +116,50 @@ OV.ThreeImporter = class extends OV.ImporterBase OnThreeObjectsLoaded (scene, onFinish) { + function ConvertThreeMaterialToMaterial (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) + { + if (threeMap.image === undefined || threeMap.image === null) { + return null; + } + let base64Buffer = OV.Base64DataURIToArrayBuffer (threeMap.image.currentSrc); + let texture = new OV.TextureMap (); + texture.name = 'Embedded.' + OV.GetFileExtensionFromMimeType (base64Buffer.mimeType); + texture.url = OV.CreateObjectUrlWithMimeType (base64Buffer.buffer, base64Buffer.mimeType); + texture.buffer = base64Buffer.buffer; + return texture; + } + + let material = new OV.Material (OV.MaterialType.Phong); + material.name = threeMaterial.name; + SetColor (material.color, threeMaterial.color); + if (threeMaterial.type === 'MeshPhongMaterial') { + SetColor (material.specular, threeMaterial.specular); + material.shininess = threeMaterial.shininess / 100.0; + } + if (threeMaterial.map !== undefined && threeMaterial.map !== null) { + material.diffuseMap = CreateTexture (threeMaterial.map); + } + return material; + } + this.loadedScene = scene; scene.traverse ((child) => { if (child.isMesh) { // TODO: merge same materials // TODO: PBR materials console.log (child); - let material = OV.ConvertThreeMaterialToMaterial (child.material); + let material = ConvertThreeMaterialToMaterial (child.material); const materialIndex = this.model.AddMaterial (material); let mesh = OV.ConvertThreeGeometryToMesh (child.geometry, materialIndex); if (child.matrixWorld !== undefined && child.matrixWorld !== null) { diff --git a/source/threejs/threeutils.js b/source/threejs/threeutils.js index 4fa19ea..ac2b62e 100644 --- a/source/threejs/threeutils.js +++ b/source/threejs/threeutils.js @@ -55,43 +55,6 @@ OV.HasHighpDriverIssue = function () return false; }; -OV.ConvertThreeMaterialToMaterial = function (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) - { - if (threeMap.image === undefined || threeMap.image === null) { - return null; - } - let base64Buffer = OV.Base64DataURIToArrayBuffer (threeMap.image.currentSrc); - let texture = new OV.TextureMap (); - texture.name = 'Embedded.' + OV.GetFileExtensionFromMimeType (base64Buffer.mimeType); - texture.url = OV.CreateObjectUrlWithMimeType (base64Buffer.buffer, base64Buffer.mimeType); - texture.buffer = base64Buffer.buffer; - return texture; - } - - let material = new OV.Material (OV.MaterialType.Phong); - material.name = threeMaterial.name; - SetColor (material.color, threeMaterial.color); - if (threeMaterial.type === 'MeshPhongMaterial') { - SetColor (material.specular, threeMaterial.specular); - material.shininess = threeMaterial.shininess / 100.0; - } - if (threeMaterial.map !== undefined && threeMaterial.map !== null) { - material.diffuseMap = CreateTexture (threeMaterial.map); - } - return material; -}; - OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex) { // TODO: check if buffergeometry