Minor modification.
This commit is contained in:
parent
c14da66704
commit
8062aec93d
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user