Pass preferred shading type to three.js conversion instead of preferred material type.
This commit is contained in:
parent
a689614e52
commit
b901a9ab30
@ -207,23 +207,3 @@ OV.ReplaceDefaultMaterialColor = function (model, color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
OV.GetRepresentativeMaterialType = function (model)
|
|
||||||
{
|
|
||||||
let maxType = OV.MaterialType.Phong;
|
|
||||||
let maxCount = 0;
|
|
||||||
let materialTypeToIndex = new Map ();
|
|
||||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
|
||||||
let material = model.GetMaterial (i);
|
|
||||||
if (!materialTypeToIndex.has (material.type)) {
|
|
||||||
materialTypeToIndex.set (material.type, 0);
|
|
||||||
}
|
|
||||||
let typeCount = materialTypeToIndex.get (material.type) + 1;
|
|
||||||
materialTypeToIndex.set (material.type, typeCount);
|
|
||||||
if (typeCount > maxCount) {
|
|
||||||
maxType = material.type;
|
|
||||||
maxCount = typeCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return maxType;
|
|
||||||
};
|
|
||||||
|
|||||||
@ -86,7 +86,7 @@ OV.ThreeNodeTree = class
|
|||||||
|
|
||||||
OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
||||||
{
|
{
|
||||||
function CreateThreeMaterial (stateHandler, model, materialIndex, materialType, params, output)
|
function CreateThreeMaterial (stateHandler, model, materialIndex, shadingType, params, output)
|
||||||
{
|
{
|
||||||
function SetTextureParameters (texture, threeTexture)
|
function SetTextureParameters (texture, threeTexture)
|
||||||
{
|
{
|
||||||
@ -136,7 +136,7 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
|||||||
}
|
}
|
||||||
|
|
||||||
let threeMaterial = null;
|
let threeMaterial = null;
|
||||||
if (materialType === OV.MaterialType.Phong) {
|
if (shadingType === OV.ShadingType.Phong && material.type === OV.MaterialType.Phong) {
|
||||||
threeMaterial = new THREE.MeshPhongMaterial (materialParams);
|
threeMaterial = new THREE.MeshPhongMaterial (materialParams);
|
||||||
let specularColor = new THREE.Color (material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0);
|
let specularColor = new THREE.Color (material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0);
|
||||||
if (OV.IsEqual (material.shininess, 0.0)) {
|
if (OV.IsEqual (material.shininess, 0.0)) {
|
||||||
@ -147,7 +147,7 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
|||||||
LoadTexture (stateHandler, threeMaterial, material.specularMap, (threeTexture) => {
|
LoadTexture (stateHandler, threeMaterial, material.specularMap, (threeTexture) => {
|
||||||
threeMaterial.specularMap = threeTexture;
|
threeMaterial.specularMap = threeTexture;
|
||||||
});
|
});
|
||||||
} else if (materialType === OV.MaterialType.Physical) {
|
} else if (shadingType === OV.ShadingType.Physical && 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;
|
||||||
@ -314,11 +314,11 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
|||||||
}
|
}
|
||||||
|
|
||||||
let stateHandler = new OV.ThreeConversionStateHandler (callbacks);
|
let stateHandler = new OV.ThreeConversionStateHandler (callbacks);
|
||||||
let materialType = OV.GetRepresentativeMaterialType (model);
|
let shadingType = OV.GetShadingType (model);
|
||||||
|
|
||||||
let modelThreeMaterials = [];
|
let modelThreeMaterials = [];
|
||||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||||
let threeMaterial = CreateThreeMaterial (stateHandler, model, materialIndex, materialType, params, output);
|
let threeMaterial = CreateThreeMaterial (stateHandler, model, materialIndex, shadingType, params, output);
|
||||||
modelThreeMaterials.push (threeMaterial);
|
modelThreeMaterials.push (threeMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ OV.HasHighpDriverIssue = function ()
|
|||||||
scene.add (ambientLight);
|
scene.add (ambientLight);
|
||||||
|
|
||||||
let light = new THREE.DirectionalLight (0x888888);
|
let light = new THREE.DirectionalLight (0x888888);
|
||||||
light.position.set (0.0, 0.0, 1.0);
|
light.position.set (0.0, 0.0, 1.0);
|
||||||
scene.add (light);
|
scene.add (light);
|
||||||
|
|
||||||
let camera = new THREE.PerspectiveCamera (45.0, 1.0, 0.1, 1000.0);
|
let camera = new THREE.PerspectiveCamera (45.0, 1.0, 0.1, 1000.0);
|
||||||
@ -45,7 +45,7 @@ OV.HasHighpDriverIssue = function ()
|
|||||||
context.UNSIGNED_BYTE,
|
context.UNSIGNED_BYTE,
|
||||||
pixels
|
pixels
|
||||||
);
|
);
|
||||||
|
|
||||||
document.body.removeChild (canvas);
|
document.body.removeChild (canvas);
|
||||||
|
|
||||||
let blackThreshold = 50;
|
let blackThreshold = 50;
|
||||||
@ -55,6 +55,31 @@ OV.HasHighpDriverIssue = function ()
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OV.ShadingType =
|
||||||
|
{
|
||||||
|
Phong : 1,
|
||||||
|
Physical : 2
|
||||||
|
};
|
||||||
|
|
||||||
|
OV.GetShadingType = function (model)
|
||||||
|
{
|
||||||
|
let phongCount = 0;
|
||||||
|
let physicalCount = 0;
|
||||||
|
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||||
|
let material = model.GetMaterial (i);
|
||||||
|
if (material.type === OV.MaterialType.Phong) {
|
||||||
|
phongCount += 1;
|
||||||
|
} else if (material.type === OV.MaterialType.Physical) {
|
||||||
|
physicalCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (phongCount >= physicalCount) {
|
||||||
|
return OV.ShadingType.Phong;
|
||||||
|
} else {
|
||||||
|
return OV.ShadingType.Physical;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
||||||
{
|
{
|
||||||
let mesh = new OV.Mesh ();
|
let mesh = new OV.Mesh ();
|
||||||
@ -73,7 +98,7 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
|||||||
let y = normals[i + 1];
|
let y = normals[i + 1];
|
||||||
let z = normals[i + 2];
|
let z = normals[i + 2];
|
||||||
mesh.AddNormal (new OV.Coord3D (x, y, z));
|
mesh.AddNormal (new OV.Coord3D (x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let hasUVs = (threeGeometry.attributes.uv !== undefined);
|
let hasUVs = (threeGeometry.attributes.uv !== undefined);
|
||||||
if (hasUVs) {
|
if (hasUVs) {
|
||||||
@ -82,7 +107,7 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
|||||||
let x = uvs[i];
|
let x = uvs[i];
|
||||||
let y = uvs[i + 1];
|
let y = uvs[i + 1];
|
||||||
mesh.AddTextureUV (new OV.Coord2D (x, y));
|
mesh.AddTextureUV (new OV.Coord2D (x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let indices = null;
|
let indices = null;
|
||||||
if (threeGeometry.index !== null) {
|
if (threeGeometry.index !== null) {
|
||||||
@ -108,6 +133,6 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
|
|||||||
triangle.SetMaterial (materialIndex);
|
triangle.SetMaterial (materialIndex);
|
||||||
}
|
}
|
||||||
mesh.AddTriangle (triangle);
|
mesh.AddTriangle (triangle);
|
||||||
}
|
}
|
||||||
return mesh;
|
return mesh;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,9 +1,3 @@
|
|||||||
OV.ShadingModelType =
|
|
||||||
{
|
|
||||||
Phong : 1,
|
|
||||||
Physical : 2
|
|
||||||
};
|
|
||||||
|
|
||||||
OV.GetDefaultCamera = function (direction)
|
OV.GetDefaultCamera = function (direction)
|
||||||
{
|
{
|
||||||
if (direction === OV.Direction.X) {
|
if (direction === OV.Direction.X) {
|
||||||
@ -48,9 +42,9 @@ OV.GetShadingTypeOfObject = function (mainObject)
|
|||||||
if (obj.isMesh) {
|
if (obj.isMesh) {
|
||||||
for (const material of obj.material) {
|
for (const material of obj.material) {
|
||||||
if (material.type === 'MeshPhongMaterial') {
|
if (material.type === 'MeshPhongMaterial') {
|
||||||
shadingType = OV.ShadingModelType.Phong;
|
shadingType = OV.ShadingType.Phong;
|
||||||
} else if (material.type === 'MeshStandardMaterial') {
|
} else if (material.type === 'MeshStandardMaterial') {
|
||||||
shadingType = OV.ShadingModelType.Physical;
|
shadingType = OV.ShadingType.Physical;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -257,7 +251,7 @@ OV.ShadingModel = class
|
|||||||
{
|
{
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
|
|
||||||
this.type = OV.ShadingModelType.Phong;
|
this.type = OV.ShadingType.Phong;
|
||||||
this.ambientLight = new THREE.AmbientLight (0x888888);
|
this.ambientLight = new THREE.AmbientLight (0x888888);
|
||||||
this.directionalLight = new THREE.DirectionalLight (0x888888);
|
this.directionalLight = new THREE.DirectionalLight (0x888888);
|
||||||
this.environment = null;
|
this.environment = null;
|
||||||
@ -269,11 +263,11 @@ OV.ShadingModel = class
|
|||||||
SetType (type)
|
SetType (type)
|
||||||
{
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
if (this.type === OV.ShadingModelType.Phong) {
|
if (this.type === OV.ShadingType.Phong) {
|
||||||
this.ambientLight.color.set (0x888888);
|
this.ambientLight.color.set (0x888888);
|
||||||
this.directionalLight.color.set (0x888888);
|
this.directionalLight.color.set (0x888888);
|
||||||
this.scene.environment = null;
|
this.scene.environment = null;
|
||||||
} else if (this.type === OV.ShadingModelType.Physical) {
|
} else if (this.type === OV.ShadingType.Physical) {
|
||||||
this.ambientLight.color.set (0x000000);
|
this.ambientLight.color.set (0x000000);
|
||||||
this.directionalLight.color.set (0x555555);
|
this.directionalLight.color.set (0x555555);
|
||||||
this.scene.environment = this.environment;
|
this.scene.environment = this.environment;
|
||||||
@ -296,12 +290,12 @@ OV.ShadingModel = class
|
|||||||
|
|
||||||
CreateHighlightMaterial (highlightColor)
|
CreateHighlightMaterial (highlightColor)
|
||||||
{
|
{
|
||||||
if (this.type === OV.ShadingModelType.Phong) {
|
if (this.type === OV.ShadingType.Phong) {
|
||||||
return new THREE.MeshPhongMaterial ({
|
return new THREE.MeshPhongMaterial ({
|
||||||
color : highlightColor,
|
color : highlightColor,
|
||||||
side : THREE.DoubleSide
|
side : THREE.DoubleSide
|
||||||
});
|
});
|
||||||
} else if (this.type === OV.ShadingModelType.Physical) {
|
} else if (this.type === OV.ShadingType.Physical) {
|
||||||
return new THREE.MeshStandardMaterial ({
|
return new THREE.MeshStandardMaterial ({
|
||||||
color : highlightColor,
|
color : highlightColor,
|
||||||
side : THREE.DoubleSide
|
side : THREE.DoubleSide
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user