Create separate material classes for phong and physical materials.

This commit is contained in:
kovacsv 2021-12-04 18:26:58 +01:00
parent b901a9ab30
commit 65ab4aa9f5
20 changed files with 308 additions and 211 deletions

View File

@ -71,9 +71,11 @@ OV.Exporter3dm = class extends OV.ExporterBase
let material = model.GetMaterial (primitive.material); let material = model.GetMaterial (primitive.material);
let rhinoMaterial = new this.rhino.Material (); let rhinoMaterial = new this.rhino.Material ();
rhinoMaterial.name = this.GetExportedMaterialName (material.name); rhinoMaterial.name = this.GetExportedMaterialName (material.name);
rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient); if (material.type === OV.MaterialType.Phong) {
rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient);
rhinoMaterial.specularColor = ColorToRhinoColor (material.specular);
}
rhinoMaterial.diffuseColor = ColorToRhinoColor (material.color); rhinoMaterial.diffuseColor = ColorToRhinoColor (material.color);
rhinoMaterial.specularColor = ColorToRhinoColor (material.specular);
rhinoMaterial.transparency = 1.0 - material.opacity; rhinoMaterial.transparency = 1.0 - material.opacity;
let rhinoMaterialIndex = rhinoDoc.materials ().count (); let rhinoMaterialIndex = rhinoDoc.materials ().count ();

View File

@ -426,12 +426,14 @@ OV.ExporterGltf = class extends OV.ExporterBase
} }
jsonMaterial.pbrMetallicRoughness.baseColorTexture = baseColorTexture; jsonMaterial.pbrMetallicRoughness.baseColorTexture = baseColorTexture;
} }
let metallicTexture = GetTextureParams (mainJson, material.metalnessMap, addTexture); if (material.type === OV.MaterialType.Physical) {
if (metallicTexture !== null) { let metallicTexture = GetTextureParams (mainJson, material.metalnessMap, addTexture);
jsonMaterial.pbrMetallicRoughness.metallicRoughnessTexture = metallicTexture; if (metallicTexture !== null) {
} else { jsonMaterial.pbrMetallicRoughness.metallicRoughnessTexture = metallicTexture;
jsonMaterial.pbrMetallicRoughness.metallicFactor = material.metalness; } else {
jsonMaterial.pbrMetallicRoughness.roughnessFactor = material.roughness; jsonMaterial.pbrMetallicRoughness.metallicFactor = material.metalness;
jsonMaterial.pbrMetallicRoughness.roughnessFactor = material.roughness;
}
} }
let normalTexture = GetTextureParams (mainJson, material.normalMap, addTexture); let normalTexture = GetTextureParams (mainJson, material.normalMap, addTexture);
if (normalTexture !== null) { if (normalTexture !== null) {

View File

@ -41,13 +41,17 @@ OV.ExporterObj = class extends OV.ExporterBase
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) { for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
let material = model.GetMaterial (materialIndex); let material = model.GetMaterial (materialIndex);
mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]); mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]);
mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]);
mtlWriter.WriteArrayLine (['Kd', material.color.r / 255.0, material.color.g / 255.0, material.color.b / 255.0]); mtlWriter.WriteArrayLine (['Kd', material.color.r / 255.0, material.color.g / 255.0, material.color.b / 255.0]);
mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]);
mtlWriter.WriteArrayLine (['Ns', material.shininess * 1000.0]);
mtlWriter.WriteArrayLine (['d', material.opacity]); mtlWriter.WriteArrayLine (['d', material.opacity]);
if (material.type === OV.MaterialType.Phong) {
mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]);
mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]);
mtlWriter.WriteArrayLine (['Ns', material.shininess * 1000.0]);
}
WriteTexture (mtlWriter, 'map_Kd', material.diffuseMap, files); WriteTexture (mtlWriter, 'map_Kd', material.diffuseMap, files);
WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files); if (material.type === OV.MaterialType.Phong) {
WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files);
}
WriteTexture (mtlWriter, 'bump', material.bumpMap, files); WriteTexture (mtlWriter, 'bump', material.bumpMap, files);
} }
mtlFile.SetTextContent (mtlWriter.GetText ()); mtlFile.SetTextContent (mtlWriter.GetText ());

View File

@ -203,7 +203,7 @@ OV.Importer = class
importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, { importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, {
getDefaultMaterial : () => { getDefaultMaterial : () => {
let material = new OV.Material (OV.MaterialType.Phong); let material = new OV.PhongMaterial ();
material.color = settings.defaultColor; material.color = settings.defaultColor;
return material; return material;
}, },
@ -311,7 +311,7 @@ OV.Importer = class
} }
for (let i = 0; i < this.model.MaterialCount (); i++) { for (let i = 0; i < this.model.MaterialCount (); i++) {
let material = this.model.GetMaterial (i); let material = this.model.GetMaterial (i);
OV.EnumerateMaterialTextureMaps (material, (texture) => { material.EnumerateTextureMaps ((texture) => {
if (texture.url !== null) { if (texture.url !== null) {
OV.RevokeObjectUrl (texture.url); OV.RevokeObjectUrl (texture.url);
} }

View File

@ -248,16 +248,16 @@ OV.Importer3dm = class extends OV.ImporterBase
let material = null; let material = null;
if (rhinoMaterial === null) { if (rhinoMaterial === null) {
material = new OV.Material (OV.MaterialType.Phong); material = new OV.PhongMaterial ();
material.color.Set (255, 255, 255); material.color.Set (255, 255, 255);
} else { } else {
let physicallyBased = rhinoMaterial.physicallyBased (); let physicallyBased = rhinoMaterial.physicallyBased ();
if (physicallyBased.supported) { if (physicallyBased.supported) {
material = new OV.Material (OV.MaterialType.Physical); material = new OV.PhysicalMaterial ();
material.metalness = physicallyBased.metallic ? 1.0 : 0.0; material.metalness = physicallyBased.metallic ? 1.0 : 0.0;
material.roughness = physicallyBased.roughness; material.roughness = physicallyBased.roughness;
} else { } else {
material = new OV.Material (OV.MaterialType.Phong); material = new OV.PhongMaterial ();
SetColor (material.ambient, rhinoMaterial.ambientColor); SetColor (material.ambient, rhinoMaterial.ambientColor);
SetColor (material.specular, rhinoMaterial.specularColor); SetColor (material.specular, rhinoMaterial.specularColor);
} }
@ -275,7 +275,7 @@ OV.Importer3dm = class extends OV.ImporterBase
} }
for (let i = 0; i < model.MaterialCount (); i++) { for (let i = 0; i < model.MaterialCount (); i++) {
let current = model.GetMaterial (i); let current = model.GetMaterial (i);
if (OV.MaterialIsEqual (current, material)) { if (current.IsEqual (material)) {
return i; return i;
} }
} }

View File

@ -166,7 +166,7 @@ OV.Importer3ds = class extends OV.ImporterBase
ReadMaterialChunk (reader, length) ReadMaterialChunk (reader, length)
{ {
let material = new OV.Material (OV.MaterialType.Phong); let material = new OV.PhongMaterial ();
let endByte = this.GetChunkEnd (reader, length); let endByte = this.GetChunkEnd (reader, length);
let shininess = null; let shininess = null;
let shininessStrength = null; let shininessStrength = null;

View File

@ -263,41 +263,46 @@ OV.GltfExtensions = class
} }
if (gltfMaterial.extensions === undefined) { if (gltfMaterial.extensions === undefined) {
return; return null;
} }
let khrSpecularGlossiness = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness; let khrSpecularGlossiness = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
if (khrSpecularGlossiness !== undefined) { if (khrSpecularGlossiness === undefined) {
material.type = OV.MaterialType.Phong; return null;
let diffuseColor = khrSpecularGlossiness.diffuseFactor;
if (diffuseColor !== undefined) {
material.color = new OV.Color (
GetMaterialComponent (diffuseColor[0]),
GetMaterialComponent (diffuseColor[1]),
GetMaterialComponent (diffuseColor[2])
);
material.opacity = diffuseColor[3];
}
let diffuseTexture = khrSpecularGlossiness.diffuseTexture;
if (diffuseTexture !== undefined) {
material.diffuseMap = imporTextureFn (diffuseTexture);
}
let specularColor = khrSpecularGlossiness.specularFactor;
if (specularColor !== undefined) {
material.specular = new OV.Color (
GetMaterialComponent (specularColor[0]),
GetMaterialComponent (specularColor[1]),
GetMaterialComponent (specularColor[2])
);
}
let specularTexture = khrSpecularGlossiness.specularGlossinessTexture;
if (specularTexture !== undefined) {
material.specularMap = imporTextureFn (specularTexture);
}
let glossiness = khrSpecularGlossiness.glossinessFactor;
if (glossiness !== undefined) {
material.shininess = glossiness;
}
} }
let phongMaterial = new OV.PhongMaterial ();
let diffuseColor = khrSpecularGlossiness.diffuseFactor;
if (diffuseColor !== undefined) {
phongMaterial.color = new OV.Color (
GetMaterialComponent (diffuseColor[0]),
GetMaterialComponent (diffuseColor[1]),
GetMaterialComponent (diffuseColor[2])
);
phongMaterial.opacity = diffuseColor[3];
}
let diffuseTexture = khrSpecularGlossiness.diffuseTexture;
if (diffuseTexture !== undefined) {
phongMaterial.diffuseMap = imporTextureFn (diffuseTexture);
}
let specularColor = khrSpecularGlossiness.specularFactor;
if (specularColor !== undefined) {
phongMaterial.specular = new OV.Color (
GetMaterialComponent (specularColor[0]),
GetMaterialComponent (specularColor[1]),
GetMaterialComponent (specularColor[2])
);
}
let specularTexture = khrSpecularGlossiness.specularGlossinessTexture;
if (specularTexture !== undefined) {
phongMaterial.specularMap = imporTextureFn (specularTexture);
}
let glossiness = khrSpecularGlossiness.glossinessFactor;
if (glossiness !== undefined) {
phongMaterial.shininess = glossiness;
}
return phongMaterial;
} }
ProcessTexture (gltfTexture, texture) ProcessTexture (gltfTexture, texture)
@ -629,7 +634,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
return parseInt (Math.round (OV.LinearToSRGB (component) * 255.0), 10); return parseInt (Math.round (OV.LinearToSRGB (component) * 255.0), 10);
} }
let material = new OV.Material (OV.MaterialType.Physical); let material = new OV.PhysicalMaterial ();
if (gltfMaterial.name !== undefined) { if (gltfMaterial.name !== undefined) {
material.name = gltfMaterial.name; material.name = gltfMaterial.name;
} }
@ -685,9 +690,12 @@ OV.ImporterGltf = class extends OV.ImporterBase
} }
} }
this.gltfExtensions.ProcessMaterial (gltfMaterial, material, (textureRef) => { let newMaterial = this.gltfExtensions.ProcessMaterial (gltfMaterial, material, (textureRef) => {
return this.ImportTexture (gltf, textureRef); return this.ImportTexture (gltf, textureRef);
}); });
if (newMaterial !== null) {
material = newMaterial;
}
this.model.AddMaterial (material); this.model.AddMaterial (material);
} }

View File

@ -207,7 +207,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
let materialIndex = this.materialNameToIndex[materialName]; let materialIndex = this.materialNameToIndex[materialName];
if (materialIndex === undefined) { if (materialIndex === undefined) {
let material = new OV.Material (OV.MaterialType.Phong); let material = new OV.PhongMaterial ();
material.name = materialName; material.name = materialName;
material.color = color; material.color = color;
material.opacity = ifcColor.w; material.opacity = ifcColor.w;

View File

@ -56,7 +56,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
ImportMaterial (materialContent) ImportMaterial (materialContent)
{ {
let material = new OV.Material (OV.MaterialType.Physical); let material = new OV.PhysicalMaterial ();
material.color.Set (255, 255, 255); material.color.Set (255, 255, 255);
if (materialContent.name !== undefined) { if (materialContent.name !== undefined) {
material.name = materialContent.name; material.name = materialContent.name;

View File

@ -220,7 +220,7 @@ OV.ImporterObj = class extends OV.ImporterBase
return true; return true;
} }
let material = new OV.Material (OV.MaterialType.Phong); let material = new OV.PhongMaterial ();
let materialName = OV.NameFromLine (line, keyword.length, '#'); let materialName = OV.NameFromLine (line, keyword.length, '#');
let materialIndex = this.model.AddMaterial (material); let materialIndex = this.model.AddMaterial (material);
material.name = materialName; material.name = materialName;

View File

@ -139,7 +139,7 @@ OV.PlyMaterialHandler = class
let materialIndex = this.colorToMaterial[materialName]; let materialIndex = this.colorToMaterial[materialName];
if (materialIndex === undefined) { if (materialIndex === undefined) {
let material = new OV.Material (OV.MaterialType.Phong); let material = new OV.PhongMaterial ();
material.name = materialName; material.name = materialName;
material.color = new OV.Color (color[0], color[1], color[2]); material.color = new OV.Color (color[0], color[1], color[2]);
material.opacity = color[3] / 255.0; material.opacity = color[3] / 255.0;

View File

@ -258,7 +258,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
} }
} }
let material = new OV.Material (OV.MaterialType.Phong); let material = new OV.PhongMaterial ();
material.name = threeMaterial.name; material.name = threeMaterial.name;
SetColor (material.color, threeMaterial.color); SetColor (material.color, threeMaterial.color);
material.opacity = threeMaterial.opacity; material.opacity = threeMaterial.opacity;

View File

@ -50,6 +50,39 @@ OV.TextureMap = class
} }
return false; return false;
} }
IsEqual (rhs)
{
if (this.name !== rhs.name) {
return false;
}
if (this.name !== rhs.name) {
return false;
}
if (this.url !== rhs.url) {
return false;
}
if (!OV.CoordIsEqual2D (this.offset, rhs.offset)) {
return false;
}
if (!OV.CoordIsEqual2D (this.scale, rhs.scale)) {
return false;
}
if (!OV.IsEqual (this.rotation, rhs.rotation)) {
return false;
}
return true;
}
};
OV.TextureMapIsEqual = function (aTex, bTex)
{
if (aTex === null && bTex === null) {
return true;
} else if (aTex === null || bTex === null) {
return false;
}
return aTex.IsEqual (bTex);
}; };
OV.MaterialType = OV.MaterialType =
@ -58,37 +91,182 @@ OV.MaterialType =
Physical : 2 Physical : 2
}; };
OV.Material = class OV.MaterialBase = class
{ {
constructor (type) constructor (type)
{ {
this.type = type; this.type = type;
this.isDefault = false;
this.name = ''; this.name = '';
this.color = new OV.Color (0, 0, 0); this.color = new OV.Color (0, 0, 0);
}
IsEqual (rhs)
{
if (this.type !== rhs.type) {
return false;
}
if (this.isDefault !== rhs.isDefault) {
return false;
}
if (this.name !== rhs.name) {
return false;
}
if (!OV.ColorIsEqual (this.color, rhs.color)) {
return false;
}
return true;
}
};
OV.FaceMaterial = class extends OV.MaterialBase
{
constructor (type)
{
super (type);
this.ambient = new OV.Color (0, 0, 0);
this.specular = new OV.Color (0, 0, 0);
this.emissive = new OV.Color (0, 0, 0); this.emissive = new OV.Color (0, 0, 0);
this.metalness = 0.0;
this.roughness = 1.0;
this.shininess = 0.0; // 0.0 .. 1.0
this.opacity = 1.0; // 0.0 .. 1.0 this.opacity = 1.0; // 0.0 .. 1.0
this.transparent = false;
this.diffuseMap = null; this.diffuseMap = null;
this.specularMap = null;
this.bumpMap = null; this.bumpMap = null;
this.normalMap = null; this.normalMap = null;
this.emissiveMap = null; this.emissiveMap = null;
this.metalnessMap = null;
this.alphaTest = 0.0; // 0.0 .. 1.0 this.alphaTest = 0.0; // 0.0 .. 1.0
this.transparent = false;
this.multiplyDiffuseMap = false; this.multiplyDiffuseMap = false;
this.multiplyMetallicMap = false; }
this.isDefault = false; IsEqual (rhs)
{
if (!super.IsEqual (rhs)) {
return false;
}
if (!OV.ColorIsEqual (this.emissive, rhs.emissive)) {
return false;
}
if (!OV.IsEqual (this.opacity, rhs.opacity)) {
return false;
}
if (this.transparent !== rhs.transparent) {
return false;
}
if (!OV.TextureMapIsEqual (this.diffuseMap, rhs.diffuseMap)) {
return false;
}
if (!OV.TextureMapIsEqual (this.bumpMap, rhs.bumpMap)) {
return false;
}
if (!OV.TextureMapIsEqual (this.normalMap, rhs.normalMap)) {
return false;
}
if (!OV.TextureMapIsEqual (this.emissiveMap, rhs.emissiveMap)) {
return false;
}
if (!OV.IsEqual (this.alphaTest, rhs.alphaTest)) {
return false;
}
if (this.multiplyDiffuseMap !== rhs.multiplyDiffuseMap) {
return false;
}
return true;
}
EnumerateTextureMaps (enumerator)
{
if (this.diffuseMap !== null) {
enumerator (this.diffuseMap);
}
if (this.bumpMap !== null) {
enumerator (this.bumpMap);
}
if (this.normalMap !== null) {
enumerator (this.normalMap);
}
if (this.emissiveMap !== null) {
enumerator (this.emissiveMap);
}
}
};
OV.PhongMaterial = class extends OV.FaceMaterial
{
constructor ()
{
super (OV.MaterialType.Phong);
this.ambient = new OV.Color (0, 0, 0);
this.specular = new OV.Color (0, 0, 0);
this.shininess = 0.0; // 0.0 .. 1.0
this.specularMap = null;
}
IsEqual (rhs)
{
if (!super.IsEqual (rhs)) {
return false;
}
if (!OV.ColorIsEqual (this.ambient, rhs.ambient)) {
return false;
}
if (!OV.ColorIsEqual (this.specular, rhs.specular)) {
return false;
}
if (!OV.IsEqual (this.shininess, rhs.shininess)) {
return false;
}
if (!OV.TextureMapIsEqual (this.specularMap, rhs.specularMap)) {
return false;
}
return true;
}
EnumerateTextureMaps (enumerator)
{
super.EnumerateTextureMaps (enumerator);
if (this.specularMap !== null) {
enumerator (this.specularMap);
}
}
};
OV.PhysicalMaterial = class extends OV.FaceMaterial
{
constructor ()
{
super (OV.MaterialType.Physical);
this.metalness = 0.0; // 0.0 .. 1.0
this.roughness = 1.0; // 0.0 .. 1.0
this.metalnessMap = null;
}
IsEqual (rhs)
{
if (!super.IsEqual (rhs)) {
return false;
}
if (!OV.IsEqual (this.metalness, rhs.metalness)) {
return false;
}
if (!OV.IsEqual (this.roughness, rhs.roughness)) {
return false;
}
if (!OV.TextureMapIsEqual (this.metalnessMap, rhs.metalnessMap)) {
return false;
}
return true;
}
EnumerateTextureMaps (enumerator)
{
super.EnumerateTextureMaps (enumerator);
if (this.metalnessMap !== null) {
enumerator (this.metalnessMap);
}
} }
}; };
@ -171,103 +349,3 @@ OV.TextureIsEqual = function (a, b)
} }
return true; return true;
}; };
OV.MaterialIsEqual = function (a, b)
{
function TextureIsEqual (aTex, bTex)
{
if (aTex === null && bTex === null) {
return true;
} else if (aTex === null || bTex === null) {
return false;
}
return OV.TextureIsEqual (aTex, bTex);
}
if (a.type !== b.type) {
return false;
}
if (a.name !== b.name) {
return false;
}
if (!OV.ColorIsEqual (a.color, b.color)) {
return false;
}
if (!OV.ColorIsEqual (a.ambient, b.ambient)) {
return false;
}
if (!OV.ColorIsEqual (a.specular, b.specular)) {
return false;
}
if (!OV.ColorIsEqual (a.emissive, b.emissive)) {
return false;
}
if (!OV.IsEqual (a.metalness, b.metalness)) {
return false;
}
if (!OV.IsEqual (a.roughness, b.roughness)) {
return false;
}
if (!OV.IsEqual (a.shininess, b.shininess)) {
return false;
}
if (!OV.IsEqual (a.opacity, b.opacity)) {
return false;
}
if (!TextureIsEqual (a.diffuseMap, b.diffuseMap)) {
return false;
}
if (!TextureIsEqual (a.specularMap, b.specularMap)) {
return false;
}
if (!TextureIsEqual (a.bumpMap, b.bumpMap)) {
return false;
}
if (!TextureIsEqual (a.normalMap, b.normalMap)) {
return false;
}
if (!TextureIsEqual (a.emissiveMap, b.emissiveMap)) {
return false;
}
if (!TextureIsEqual (a.metalnessMap, b.metalnessMap)) {
return false;
}
if (!OV.IsEqual (a.alphaTest, b.alphaTest)) {
return false;
}
if (a.transparent !== b.transparent) {
return false;
}
if (a.multiplyDiffuseMap !== b.multiplyDiffuseMap) {
return false;
}
if (a.multiplyMetallicMap !== b.multiplyMetallicMap) {
return false;
}
if (a.isDefault !== b.isDefault) {
return false;
}
return true;
};
OV.EnumerateMaterialTextureMaps = function (material, enumerator)
{
if (material.diffuseMap !== null) {
enumerator (material.diffuseMap);
}
if (material.specularMap !== null) {
enumerator (material.specularMap);
}
if (material.bumpMap !== null) {
enumerator (material.bumpMap);
}
if (material.normalMap !== null) {
enumerator (material.normalMap);
}
if (material.emissiveMap !== null) {
enumerator (material.emissiveMap);
}
if (material.metalnessMap !== null) {
enumerator (material.metalnessMap);
}
};

View File

@ -4,7 +4,7 @@ function CreateTestModel ()
{ {
let model = new OV.Model (); let model = new OV.Model ();
let material1 = new OV.Material (OV.MaterialType.Phong); let material1 = new OV.PhongMaterial ();
material1.name = 'TestMaterial1'; material1.name = 'TestMaterial1';
material1.ambient = new OV.Color (0, 0, 0); material1.ambient = new OV.Color (0, 0, 0);
material1.color = new OV.Color (255, 0, 0); material1.color = new OV.Color (255, 0, 0);
@ -23,7 +23,7 @@ function CreateTestModel ()
material1.bumpMap.buffer = new ArrayBuffer (3); material1.bumpMap.buffer = new ArrayBuffer (3);
model.AddMaterial (material1); model.AddMaterial (material1);
let material2 = new OV.Material (OV.MaterialType.Phong); let material2 = new OV.PhongMaterial ();
material2.name = 'TestMaterial2'; material2.name = 'TestMaterial2';
material2.ambient = new OV.Color (0, 0, 0); material2.ambient = new OV.Color (0, 0, 0);
material2.color = new OV.Color (0, 255, 0); material2.color = new OV.Color (0, 255, 0);
@ -94,20 +94,20 @@ describe ('Exporter', function () {
[ [
'# exported by https://3dviewer.net', '# exported by https://3dviewer.net',
'newmtl TestMaterial1', 'newmtl TestMaterial1',
'Ka 0 0 0',
'Kd 1 0 0', 'Kd 1 0 0',
'd 1',
'Ka 0 0 0',
'Ks 0.2 0.2 0.2', 'Ks 0.2 0.2 0.2',
'Ns 0', 'Ns 0',
'd 1',
'map_Kd texture1.png', 'map_Kd texture1.png',
'map_Ks texture2.png', 'map_Ks texture2.png',
'bump texture3.png', 'bump texture3.png',
'newmtl TestMaterial2', 'newmtl TestMaterial2',
'Ka 0 0 0',
'Kd 0 1 0', 'Kd 0 1 0',
'd 1',
'Ka 0 0 0',
'Ks 0.2 0.2 0.2', 'Ks 0.2 0.2 0.2',
'Ns 0', 'Ns 0',
'd 1',
'' ''
].join ('\n')); ].join ('\n'));
let objFile = result[1]; let objFile = result[1];
@ -214,7 +214,7 @@ describe ('Exporter', function () {
let importer = new OV.ImporterStl (); let importer = new OV.ImporterStl ();
importer.Import (stlFile.GetName (), 'stl', contentBuffer, { importer.Import (stlFile.GetName (), 'stl', contentBuffer, {
getDefaultMaterial () { getDefaultMaterial () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}, },
onSuccess () { onSuccess () {
let importedModel = importer.GetModel (); let importedModel = importer.GetModel ();
@ -308,7 +308,7 @@ describe ('Exporter', function () {
let importer = new OV.ImporterPly (); let importer = new OV.ImporterPly ();
importer.Import (plyFile.GetName (), 'ply', contentBuffer, { importer.Import (plyFile.GetName (), 'ply', contentBuffer, {
getDefaultMaterial () { getDefaultMaterial () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}, },
onSuccess () { onSuccess () {
let importedModel = importer.GetModel (); let importedModel = importer.GetModel ();
@ -338,7 +338,7 @@ describe ('Exporter', function () {
let importer = new OV.ImporterGltf (); let importer = new OV.ImporterGltf ();
importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, { importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, {
getDefaultMaterial () { getDefaultMaterial () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}, },
getFileBuffer (filePath) { getFileBuffer (filePath) {
if (filePath == 'model.bin') { if (filePath == 'model.bin') {
@ -376,7 +376,7 @@ describe ('Exporter', function () {
let importer = new OV.ImporterGltf (); let importer = new OV.ImporterGltf ();
importer.Import (glbFile.GetName (), 'glb', contentBuffer, { importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
getDefaultMaterial () { getDefaultMaterial () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}, },
getFileBuffer (filePath) { getFileBuffer (filePath) {
return null; return null;

View File

@ -46,7 +46,7 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[0].indices.length, 6); assert.strictEqual (buffer.primitives[0].indices.length, 6);
assert.strictEqual (buffer.primitives[0].vertices.length, 6 * 3); assert.strictEqual (buffer.primitives[0].vertices.length, 6 * 3);
assert.strictEqual (buffer.primitives[0].normals.length, 6 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 6 * 3);
assert.strictEqual (buffer.primitives[0].uvs.length, 0); assert.strictEqual (buffer.primitives[0].uvs.length, 0);
}); });
it ('Mesh To Buffer Different UVs', function () { it ('Mesh To Buffer Different UVs', function () {
@ -66,7 +66,7 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[0].indices.length, 6); assert.strictEqual (buffer.primitives[0].indices.length, 6);
assert.strictEqual (buffer.primitives[0].vertices.length, 6 * 3); assert.strictEqual (buffer.primitives[0].vertices.length, 6 * 3);
assert.strictEqual (buffer.primitives[0].normals.length, 6 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 6 * 3);
assert.strictEqual (buffer.primitives[0].uvs.length, 6 * 2); assert.strictEqual (buffer.primitives[0].uvs.length, 6 * 2);
}); });
it ('Mesh To Buffer Same Normals and UVs', function () { it ('Mesh To Buffer Same Normals and UVs', function () {
@ -85,7 +85,7 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[0].indices.length, 6); assert.strictEqual (buffer.primitives[0].indices.length, 6);
assert.strictEqual (buffer.primitives[0].vertices.length, 4 * 3); assert.strictEqual (buffer.primitives[0].vertices.length, 4 * 3);
assert.strictEqual (buffer.primitives[0].normals.length, 4 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 4 * 3);
assert.strictEqual (buffer.primitives[0].uvs.length, 4 * 2); assert.strictEqual (buffer.primitives[0].uvs.length, 4 * 2);
}); });
it ('Mesh To Buffer Cube', function () { it ('Mesh To Buffer Cube', function () {
@ -123,7 +123,7 @@ describe ('Mesh Buffer', function () {
model.AddMesh (mesh); model.AddMesh (mesh);
OV.FinalizeModel (model, function () { OV.FinalizeModel (model, function () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}); });
assert (OV.CheckModel (model)); assert (OV.CheckModel (model));
@ -132,7 +132,7 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[0].indices.length, 36); assert.strictEqual (buffer.primitives[0].indices.length, 36);
assert.strictEqual (buffer.primitives[0].vertices.length, 24 * 3); assert.strictEqual (buffer.primitives[0].vertices.length, 24 * 3);
assert.strictEqual (buffer.primitives[0].normals.length, 24 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 24 * 3);
assert.strictEqual (buffer.primitives[0].uvs.length, 0); assert.strictEqual (buffer.primitives[0].uvs.length, 0);
}); });
it ('Mesh To Buffer Cube Auto Normals', function () { it ('Mesh To Buffer Cube Auto Normals', function () {
@ -163,7 +163,7 @@ describe ('Mesh Buffer', function () {
model.AddMesh (mesh); model.AddMesh (mesh);
OV.FinalizeModel (model, function () { OV.FinalizeModel (model, function () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}); });
assert (OV.CheckModel (model)); assert (OV.CheckModel (model));
@ -205,7 +205,7 @@ describe ('Mesh Buffer', function () {
model.AddMesh (mesh); model.AddMesh (mesh);
OV.FinalizeModel (model, function () { OV.FinalizeModel (model, function () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}); });
assert (OV.CheckModel (model)); assert (OV.CheckModel (model));
@ -217,12 +217,12 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[0].uvs.length, 0); assert.strictEqual (buffer.primitives[0].uvs.length, 0);
assert.strictEqual (buffer.primitives[0].GetByteLength (2, 4), 36 * 2 + 2 * 8 * 3 * 4); assert.strictEqual (buffer.primitives[0].GetByteLength (2, 4), 36 * 2 + 2 * 8 * 3 * 4);
assert.strictEqual (buffer.GetByteLength (2, 4), 36 * 2 + 2 * 8 * 3 * 4); assert.strictEqual (buffer.GetByteLength (2, 4), 36 * 2 + 2 * 8 * 3 * 4);
}); });
it ('Mesh To Buffer Cube Materials', function () { it ('Mesh To Buffer Cube Materials', function () {
var model = new OV.Model (); var model = new OV.Model ();
model.AddMaterial (new OV.Material (OV.MaterialType.Phong)); model.AddMaterial (new OV.PhongMaterial ());
model.AddMaterial (new OV.Material (OV.MaterialType.Phong)); model.AddMaterial (new OV.PhongMaterial ());
var mesh = new OV.Mesh (); var mesh = new OV.Mesh ();
mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0)); mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0));
@ -249,7 +249,7 @@ describe ('Mesh Buffer', function () {
model.AddMesh (mesh); model.AddMesh (mesh);
OV.FinalizeModel (model, function () { OV.FinalizeModel (model, function () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}); });
assert (OV.CheckModel (model)); assert (OV.CheckModel (model));
@ -266,7 +266,7 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[1].uvs.length, 0); assert.strictEqual (buffer.primitives[1].uvs.length, 0);
assert.strictEqual (buffer.primitives[1].GetByteLength (2, 4), 18 * 2 + 2 * 12 * 3 * 4); assert.strictEqual (buffer.primitives[1].GetByteLength (2, 4), 18 * 2 + 2 * 12 * 3 * 4);
assert.strictEqual (buffer.GetByteLength (2, 4), 36 * 2 + 2 * 24 * 3 * 4); assert.strictEqual (buffer.GetByteLength (2, 4), 36 * 2 + 2 * 24 * 3 * 4);
}); });
it ('Mesh To Buffer Cube One UV', function () { it ('Mesh To Buffer Cube One UV', function () {
var model = new OV.Model (); var model = new OV.Model ();
@ -299,7 +299,7 @@ describe ('Mesh Buffer', function () {
model.AddMesh (mesh); model.AddMesh (mesh);
OV.FinalizeModel (model, function () { OV.FinalizeModel (model, function () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}); });
assert (OV.CheckModel (model)); assert (OV.CheckModel (model));
@ -342,7 +342,7 @@ describe ('Mesh Buffer', function () {
model.AddMesh (mesh); model.AddMesh (mesh);
OV.FinalizeModel (model, function () { OV.FinalizeModel (model, function () {
return new OV.Material (OV.MaterialType.Phong); return new OV.PhongMaterial ();
}); });
assert (OV.CheckModel (model)); assert (OV.CheckModel (model));
@ -352,5 +352,5 @@ describe ('Mesh Buffer', function () {
assert.strictEqual (buffer.primitives[0].vertices.length, 30 * 3); assert.strictEqual (buffer.primitives[0].vertices.length, 30 * 3);
assert.strictEqual (buffer.primitives[0].normals.length, 30 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 30 * 3);
assert.strictEqual (buffer.primitives[0].uvs.length, 30 * 2); assert.strictEqual (buffer.primitives[0].uvs.length, 30 * 2);
}); });
}); });

View File

@ -10,7 +10,7 @@ describe ('Model', function () {
it ('Add Material', function () { it ('Add Material', function () {
var model = new OV.Model (); var model = new OV.Model ();
var material = new OV.Material (OV.MaterialType.Phong); var material = new OV.PhongMaterial ();
material.name = 'example'; material.name = 'example';
var index = model.AddMaterial (material); var index = model.AddMaterial (material);
assert.strictEqual (model.MaterialCount (), 1); assert.strictEqual (model.MaterialCount (), 1);
@ -91,7 +91,7 @@ describe ('Model Finalization', function () {
var model = new OV.Model (); var model = new OV.Model ();
var meshIndex = model.AddMesh (mesh); var meshIndex = model.AddMesh (mesh);
assert.strictEqual (model.MaterialCount (), 0); assert.strictEqual (model.MaterialCount (), 0);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
assert.strictEqual (model.MaterialCount (), 1); assert.strictEqual (model.MaterialCount (), 1);
var theMesh = model.GetMesh (meshIndex); var theMesh = model.GetMesh (meshIndex);
assert.strictEqual (theMesh.NormalCount (), 1); assert.strictEqual (theMesh.NormalCount (), 1);
@ -120,7 +120,7 @@ describe ('Model Finalization', function () {
var model = new OV.Model () var model = new OV.Model ()
var meshIndex = model.AddMesh (mesh); var meshIndex = model.AddMesh (mesh);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
var theMesh = model.GetMesh (meshIndex); var theMesh = model.GetMesh (meshIndex);
assert.strictEqual (theMesh.NormalCount (), 6); assert.strictEqual (theMesh.NormalCount (), 6);
@ -153,7 +153,7 @@ describe ('Model Finalization', function () {
var model = new OV.Model () var model = new OV.Model ()
var meshIndex = model.AddMesh (mesh); var meshIndex = model.AddMesh (mesh);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
var theMesh = model.GetMesh (meshIndex); var theMesh = model.GetMesh (meshIndex);
assert.strictEqual (theMesh.NormalCount (), 9); assert.strictEqual (theMesh.NormalCount (), 9);
@ -192,7 +192,7 @@ describe ('Model Finalization', function () {
node3.AddMeshIndex (meshIndex); node3.AddMeshIndex (meshIndex);
node3.AddMeshIndex (emptyMeshIndex); node3.AddMeshIndex (emptyMeshIndex);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
assert.strictEqual (model.MeshCount (), 1); assert.strictEqual (model.MeshCount (), 1);
let meshInstances = []; let meshInstances = [];
@ -210,7 +210,7 @@ describe ('Model Finalization', function () {
it ('Remove Empty Nodes Recursively', function () { it ('Remove Empty Nodes Recursively', function () {
let model = testUtils.GetHierarchicalModelNoFinalization (); let model = testUtils.GetHierarchicalModelNoFinalization ();
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
assert.strictEqual (model.MeshCount (), 0); assert.strictEqual (model.MeshCount (), 0);
assert.strictEqual (model.MeshInstanceCount (), 0); assert.strictEqual (model.MeshInstanceCount (), 0);
assert (model.GetRootNode ().IsEmpty ()); assert (model.GetRootNode ().IsEmpty ());
@ -395,7 +395,7 @@ describe ('Node Hierarchy', function () {
it ('Instance counters', function () { it ('Instance counters', function () {
let model = testUtils.GetTranslatedRotatedCubesModel (); let model = testUtils.GetTranslatedRotatedCubesModel ();
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
assert.strictEqual (model.MeshCount (), 1); assert.strictEqual (model.MeshCount (), 1);
assert.strictEqual (model.MeshInstanceCount (), 3); assert.strictEqual (model.MeshInstanceCount (), 3);
assert.strictEqual (model.VertexCount (), 8 * 3); assert.strictEqual (model.VertexCount (), 8 * 3);

View File

@ -37,7 +37,7 @@ describe ('Model Utils', function () {
mesh2.AddTriangle (new OV.Triangle (0, 1, 2)); mesh2.AddTriangle (new OV.Triangle (0, 1, 2));
model.AddMeshToRootNode (mesh2); model.AddMeshToRootNode (mesh2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong); }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial (); });
let mesh1Bounds = OV.GetBoundingBox (model.GetMesh (0)); let mesh1Bounds = OV.GetBoundingBox (model.GetMesh (0));
assert (OV.CoordIsEqual3D (mesh1Bounds.min, new OV.Coord3D (0.0, 0.0, 0.0))); assert (OV.CoordIsEqual3D (mesh1Bounds.min, new OV.Coord3D (0.0, 0.0, 0.0)));

View File

@ -54,7 +54,7 @@ module.exports =
}); });
importer.Import (fileName, extension, content, { importer.Import (fileName, extension, content, {
getDefaultMaterial : function () { getDefaultMaterial : function () {
var material = new OV.Material (OV.MaterialType.Phong); var material = new OV.PhongMaterial ();
return material; return material;
}, },
getFileBuffer : function (filePath) { getFileBuffer : function (filePath) {

View File

@ -170,7 +170,7 @@ module.exports =
OV.TransformMesh (cube2, new OV.Transformation (matrix)); OV.TransformMesh (cube2, new OV.Transformation (matrix));
model.AddMeshToRootNode (cube2); model.AddMeshToRootNode (cube2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
return model; return model;
}, },
@ -186,7 +186,7 @@ module.exports =
OV.TransformMesh (cube2, new OV.Transformation (matrix)) OV.TransformMesh (cube2, new OV.Transformation (matrix))
model.AddMeshToRootNode (cube2); model.AddMeshToRootNode (cube2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
return model; return model;
}, },
@ -202,7 +202,7 @@ module.exports =
OV.TransformMesh (cube2, new OV.Transformation (matrix)); OV.TransformMesh (cube2, new OV.Transformation (matrix));
model.AddMeshToRootNode (cube2); model.AddMeshToRootNode (cube2);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
return model; return model;
}, },
@ -251,7 +251,7 @@ module.exports =
{ {
var model = new OV.Model (); var model = new OV.Model ();
model.AddMeshToRootNode (mesh); model.AddMeshToRootNode (mesh);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
return model; return model;
}, },
@ -375,7 +375,7 @@ module.exports =
root.AddChildNode (rotatedNode); root.AddChildNode (rotatedNode);
rotatedNode.AddChildNode (translatedRotatedNode); rotatedNode.AddChildNode (translatedRotatedNode);
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
return model; return model;
} }
} }

View File

@ -116,11 +116,14 @@ OV.DetailsSidebarPanel = class extends OV.SidebarPanel
} }
this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Opacity', material.opacity)); this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Opacity', material.opacity));
AddTextureMap (this, table, 'Diffuse Map', material.diffuseMap); AddTextureMap (this, table, 'Diffuse Map', material.diffuseMap);
AddTextureMap (this, table, 'Specular Map', material.specularMap);
AddTextureMap (this, table, 'Bump Map', material.bumpMap); AddTextureMap (this, table, 'Bump Map', material.bumpMap);
AddTextureMap (this, table, 'Normal Map', material.normalMap); AddTextureMap (this, table, 'Normal Map', material.normalMap);
AddTextureMap (this, table, 'Emissive Map', material.emissiveMap); AddTextureMap (this, table, 'Emissive Map', material.emissiveMap);
AddTextureMap (this, table, 'Metallic Map', material.metalnessMap); if (material.type === OV.MaterialType.Phong) {
AddTextureMap (this, table, 'Specular Map', material.specularMap);
} else if (material.type === OV.MaterialType.Physical) {
AddTextureMap (this, table, 'Metallic Map', material.metalnessMap);
}
this.Resize (); this.Resize ();
} }