Merge branch 'dev' into three_importer
# Conflicts: # source/threejs/threeconverter.js
This commit is contained in:
commit
0727048cc8
@ -14,9 +14,45 @@ OV.ModelToThreeConversionOutput = class
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OV.ThreeConversionStateHandler = class
|
||||||
|
{
|
||||||
|
constructor (callbacks)
|
||||||
|
{
|
||||||
|
this.callbacks = callbacks;
|
||||||
|
this.texturesNeeded = 0;
|
||||||
|
this.texturesLoaded = 0;
|
||||||
|
this.threeMeshes = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
OnTextureNeeded ()
|
||||||
|
{
|
||||||
|
this.texturesNeeded += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
OnTextureLoaded ()
|
||||||
|
{
|
||||||
|
this.texturesLoaded += 1;
|
||||||
|
this.callbacks.onTextureLoaded ();
|
||||||
|
this.Finish ();
|
||||||
|
}
|
||||||
|
|
||||||
|
OnModelLoaded (threeMeshes)
|
||||||
|
{
|
||||||
|
this.threeMeshes = threeMeshes;
|
||||||
|
this.Finish ();
|
||||||
|
}
|
||||||
|
|
||||||
|
Finish ()
|
||||||
|
{
|
||||||
|
if (this.threeMeshes !== null && this.texturesNeeded === this.texturesLoaded) {
|
||||||
|
this.callbacks.onModelLoaded (this.threeMeshes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
||||||
{
|
{
|
||||||
function CreateThreeMaterial (model, materialIndex, params, output)
|
function CreateThreeMaterial (stateHandler, model, materialIndex, params, output)
|
||||||
{
|
{
|
||||||
function SetTextureParameters (texture, threeTexture)
|
function SetTextureParameters (texture, threeTexture)
|
||||||
{
|
{
|
||||||
@ -29,17 +65,25 @@ OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
|||||||
threeTexture.repeat.y = texture.scale.y;
|
threeTexture.repeat.y = texture.scale.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
function LoadTexture (threeMaterial, texture, onLoad)
|
function LoadTexture (stateHandler, threeMaterial, texture, onTextureLoaded)
|
||||||
{
|
{
|
||||||
if (texture === null || !texture.IsValid ()) {
|
if (texture === null || !texture.IsValid ()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let loader = new THREE.TextureLoader ();
|
let loader = new THREE.TextureLoader ();
|
||||||
loader.load (texture.url, (threeTexture) => {
|
stateHandler.OnTextureNeeded ();
|
||||||
SetTextureParameters (texture, threeTexture);
|
loader.load (texture.url,
|
||||||
threeMaterial.needsUpdate = true;
|
(threeTexture) => {
|
||||||
onLoad (threeTexture);
|
SetTextureParameters (texture, threeTexture);
|
||||||
});
|
threeMaterial.needsUpdate = true;
|
||||||
|
onTextureLoaded (threeTexture);
|
||||||
|
stateHandler.OnTextureLoaded ();
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
(err) => {
|
||||||
|
stateHandler.OnTextureLoaded ();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let material = model.GetMaterial (materialIndex);
|
let material = model.GetMaterial (materialIndex);
|
||||||
@ -66,44 +110,38 @@ OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
|||||||
}
|
}
|
||||||
threeMaterial.specular = specularColor;
|
threeMaterial.specular = specularColor;
|
||||||
threeMaterial.shininess = material.shininess * 100.0;
|
threeMaterial.shininess = material.shininess * 100.0;
|
||||||
LoadTexture (threeMaterial, material.specularMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.specularMap, (threeTexture) => {
|
||||||
threeMaterial.specularMap = threeTexture;
|
threeMaterial.specularMap = threeTexture;
|
||||||
callbacks.onTextureLoaded ();
|
|
||||||
});
|
});
|
||||||
} else if (material.type === OV.MaterialType.Physical) {
|
} else if (material.type === OV.MaterialType.Physical) {
|
||||||
threeMaterial = new THREE.MeshStandardMaterial (materialParams);
|
threeMaterial = new THREE.MeshStandardMaterial (materialParams);
|
||||||
threeMaterial.metalness = material.metalness;
|
threeMaterial.metalness = material.metalness;
|
||||||
threeMaterial.roughness = material.roughness;
|
threeMaterial.roughness = material.roughness;
|
||||||
LoadTexture (threeMaterial, material.metalnessMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.metalnessMap, (threeTexture) => {
|
||||||
threeMaterial.metalness = 1.0;
|
threeMaterial.metalness = 1.0;
|
||||||
threeMaterial.roughness = 1.0;
|
threeMaterial.roughness = 1.0;
|
||||||
threeMaterial.metalnessMap = threeTexture;
|
threeMaterial.metalnessMap = threeTexture;
|
||||||
threeMaterial.roughnessMap = threeTexture;
|
threeMaterial.roughnessMap = threeTexture;
|
||||||
callbacks.onTextureLoaded ();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let emissiveColor = new THREE.Color (material.emissive.r / 255.0, material.emissive.g / 255.0, material.emissive.b / 255.0);
|
let emissiveColor = new THREE.Color (material.emissive.r / 255.0, material.emissive.g / 255.0, material.emissive.b / 255.0);
|
||||||
threeMaterial.emissive = emissiveColor;
|
threeMaterial.emissive = emissiveColor;
|
||||||
|
|
||||||
LoadTexture (threeMaterial, material.diffuseMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.diffuseMap, (threeTexture) => {
|
||||||
if (!material.multiplyDiffuseMap) {
|
if (!material.multiplyDiffuseMap) {
|
||||||
threeMaterial.color.setRGB (1.0, 1.0, 1.0);
|
threeMaterial.color.setRGB (1.0, 1.0, 1.0);
|
||||||
}
|
}
|
||||||
threeMaterial.map = threeTexture;
|
threeMaterial.map = threeTexture;
|
||||||
callbacks.onTextureLoaded ();
|
|
||||||
});
|
});
|
||||||
LoadTexture (threeMaterial, material.bumpMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.bumpMap, (threeTexture) => {
|
||||||
threeMaterial.bumpMap = threeTexture;
|
threeMaterial.bumpMap = threeTexture;
|
||||||
callbacks.onTextureLoaded ();
|
|
||||||
});
|
});
|
||||||
LoadTexture (threeMaterial, material.normalMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.normalMap, (threeTexture) => {
|
||||||
threeMaterial.normalMap = threeTexture;
|
threeMaterial.normalMap = threeTexture;
|
||||||
callbacks.onTextureLoaded ();
|
|
||||||
});
|
});
|
||||||
LoadTexture (threeMaterial, material.emissiveMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.emissiveMap, (threeTexture) => {
|
||||||
threeMaterial.emissiveMap = threeTexture;
|
threeMaterial.emissiveMap = threeTexture;
|
||||||
callbacks.onTextureLoaded ();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (material.isDefault) {
|
if (material.isDefault) {
|
||||||
@ -209,9 +247,11 @@ OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
|||||||
return threeMesh;
|
return threeMesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let stateHandler = new OV.ThreeConversionStateHandler (callbacks);
|
||||||
|
|
||||||
let modelThreeMaterials = [];
|
let modelThreeMaterials = [];
|
||||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||||
let threeMaterial = CreateThreeMaterial (model, materialIndex, params, output);
|
let threeMaterial = CreateThreeMaterial (stateHandler, model, materialIndex, params, output);
|
||||||
modelThreeMaterials.push (threeMaterial);
|
modelThreeMaterials.push (threeMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +269,7 @@ OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
|||||||
ready ();
|
ready ();
|
||||||
},
|
},
|
||||||
onReady : () => {
|
onReady : () => {
|
||||||
callbacks.onModelLoaded (threeMeshes);
|
stateHandler.OnModelLoaded (threeMeshes);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user