Use Physically Based Rendering when possible #99
This commit is contained in:
parent
779e9f4d5b
commit
46644d47c3
@ -76,7 +76,7 @@ OV.Exporter3dm = class extends OV.ExporterBase
|
||||
let rhinoMaterial = new this.rhino.Material ();
|
||||
rhinoMaterial.name = this.GetExportedMaterialName (material.name);
|
||||
rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient);
|
||||
rhinoMaterial.diffuseColor = ColorToRhinoColor (material.diffuse);
|
||||
rhinoMaterial.diffuseColor = ColorToRhinoColor (material.color);
|
||||
rhinoMaterial.specularColor = ColorToRhinoColor (material.specular);
|
||||
rhinoMaterial.transparency = 1.0 - material.opacity;
|
||||
|
||||
|
||||
@ -403,9 +403,9 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
let jsonMaterial = {
|
||||
name : obj.GetExportedMaterialName (material.name),
|
||||
pbrMetallicRoughness : {
|
||||
baseColorFactor : ColorToRGBA (material.diffuse, material.opacity),
|
||||
metallicFactor : 0.0,
|
||||
roughnessFactor : 1.0
|
||||
baseColorFactor : ColorToRGBA (material.color, material.opacity),
|
||||
metallicFactor : material.metallic,
|
||||
roughnessFactor : material.roughness
|
||||
},
|
||||
emissiveFactor : ColorToRGB (material.emissive),
|
||||
doubleSided : true,
|
||||
@ -424,6 +424,10 @@ OV.ExporterGltf = class extends OV.ExporterBase
|
||||
}
|
||||
jsonMaterial.pbrMetallicRoughness.baseColorTexture = baseColorTexture;
|
||||
}
|
||||
let metallicTexture = GetTextureParams (mainJson, material.metallicMap, addTexture);
|
||||
if (metallicTexture !== null) {
|
||||
jsonMaterial.pbrMetallicRoughness.metallicRoughnessTexture = metallicTexture;
|
||||
}
|
||||
let normalTexture = GetTextureParams (mainJson, material.normalMap, addTexture);
|
||||
if (normalTexture !== null) {
|
||||
jsonMaterial.normalTexture = normalTexture;
|
||||
|
||||
@ -42,7 +42,7 @@ OV.ExporterObj = class extends OV.ExporterBase
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
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.diffuse.r / 255.0, material.diffuse.g / 255.0, material.diffuse.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]);
|
||||
|
||||
@ -320,8 +320,8 @@ OV.Importer = class
|
||||
|
||||
importer.Import (mainFile.file.content, mainFile.file.extension, {
|
||||
getDefaultMaterial : () => {
|
||||
let material = new OV.Material ();
|
||||
material.diffuse = settings.defaultColor;
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
material.color = settings.defaultColor;
|
||||
return material;
|
||||
},
|
||||
getFileBuffer : (filePath) => {
|
||||
@ -404,7 +404,7 @@ OV.Importer = class
|
||||
}
|
||||
for (let i = 0; i < this.model.MaterialCount (); i++) {
|
||||
let material = this.model.GetMaterial (i);
|
||||
material.EnumerateTextureMaps ((texture) => {
|
||||
OV.EnumerateMaterialTextureMaps (material, (texture) => {
|
||||
if (texture.url !== null) {
|
||||
OV.RevokeObjectUrl (texture.url);
|
||||
}
|
||||
|
||||
@ -293,22 +293,22 @@ OV.Importer3dm = class extends OV.ImporterBase
|
||||
return rhinoColor.r === 255 && rhinoColor.g === 255 && rhinoColor.b === 255;
|
||||
}
|
||||
|
||||
let material = new OV.Material ();
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
if (rhinoMaterial === null) {
|
||||
material.diffuse.Set (255, 255, 255);
|
||||
material.color.Set (255, 255, 255);
|
||||
} else {
|
||||
material.name = rhinoMaterial.name;
|
||||
SetColor (material.ambient, rhinoMaterial.ambientColor);
|
||||
SetColor (material.diffuse, rhinoMaterial.diffuseColor);
|
||||
SetColor (material.color, rhinoMaterial.diffuseColor);
|
||||
SetColor (material.specular, rhinoMaterial.specularColor);
|
||||
material.opacity = 1.0 - rhinoMaterial.transparency;
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
// material.shininess = rhinoMaterial.shine / 255.0;
|
||||
if (IsBlack (material.diffuse) && !IsWhite (rhinoMaterial.reflectionColor)) {
|
||||
SetColor (material.diffuse, rhinoMaterial.reflectionColor);
|
||||
if (IsBlack (material.color) && !IsWhite (rhinoMaterial.reflectionColor)) {
|
||||
SetColor (material.color, rhinoMaterial.reflectionColor);
|
||||
}
|
||||
if (IsBlack (material.diffuse) && !IsWhite (rhinoMaterial.transparentColor)) {
|
||||
SetColor (material.diffuse, rhinoMaterial.transparentColor);
|
||||
if (IsBlack (material.color) && !IsWhite (rhinoMaterial.transparentColor)) {
|
||||
SetColor (material.color, rhinoMaterial.transparentColor);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||
@ -319,7 +319,7 @@ OV.Importer3dm = class extends OV.ImporterBase
|
||||
if (!OV.ColorIsEqual (current.ambient, material.ambient)) {
|
||||
continue;
|
||||
}
|
||||
if (!OV.ColorIsEqual (current.diffuse, material.diffuse)) {
|
||||
if (!OV.ColorIsEqual (current.color, material.color)) {
|
||||
continue;
|
||||
}
|
||||
if (!OV.ColorIsEqual (current.specular, material.specular)) {
|
||||
|
||||
@ -135,7 +135,7 @@ OV.Importer3ds = class extends OV.ImporterBase
|
||||
|
||||
ReadMaterialChunk (reader, length)
|
||||
{
|
||||
let material = new OV.Material ();
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
let endByte = this.GetChunkEnd (reader, length);
|
||||
let shininess = null;
|
||||
let shininessStrength = null;
|
||||
@ -145,7 +145,7 @@ OV.Importer3ds = class extends OV.ImporterBase
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_AMBIENT) {
|
||||
material.ambient = this.ReadColorChunk (reader, chunkLength);
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_DIFFUSE) {
|
||||
material.diffuse = this.ReadColorChunk (reader, chunkLength);
|
||||
material.color = this.ReadColorChunk (reader, chunkLength);
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_SPECULAR) {
|
||||
material.specular = this.ReadColorChunk (reader, chunkLength);
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_SHININESS) {
|
||||
|
||||
@ -314,9 +314,10 @@ OV.GltfExtensions = class
|
||||
}
|
||||
let khrSpecularGlossiness = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness;
|
||||
if (khrSpecularGlossiness !== undefined) {
|
||||
material.type = OV.MaterialType.Phong;
|
||||
let diffuseColor = khrSpecularGlossiness.diffuseFactor;
|
||||
if (diffuseColor !== undefined) {
|
||||
material.diffuse = new OV.Color (
|
||||
material.color = new OV.Color (
|
||||
GetMaterialComponent (diffuseColor[0]),
|
||||
GetMaterialComponent (diffuseColor[1]),
|
||||
GetMaterialComponent (diffuseColor[2])
|
||||
@ -714,12 +715,12 @@ OV.ImporterGltf = class extends OV.ImporterBase
|
||||
}
|
||||
|
||||
let gltfMaterial = gltf.materials[materialIndex];
|
||||
let material = new OV.Material ();
|
||||
let material = new OV.Material (OV.MaterialType.Physical);
|
||||
if (gltfMaterial.name !== undefined) {
|
||||
material.name = gltfMaterial.name;
|
||||
}
|
||||
|
||||
material.diffuse = new OV.Color (
|
||||
material.color = new OV.Color (
|
||||
GetMaterialComponent (1.0),
|
||||
GetMaterialComponent (1.0),
|
||||
GetMaterialComponent (1.0)
|
||||
@ -727,13 +728,21 @@ OV.ImporterGltf = class extends OV.ImporterBase
|
||||
if (gltfMaterial.pbrMetallicRoughness !== undefined) {
|
||||
let baseColor = gltfMaterial.pbrMetallicRoughness.baseColorFactor;
|
||||
if (baseColor !== undefined) {
|
||||
material.diffuse = new OV.Color (
|
||||
material.color = new OV.Color (
|
||||
GetMaterialComponent (baseColor[0]),
|
||||
GetMaterialComponent (baseColor[1]),
|
||||
GetMaterialComponent (baseColor[2])
|
||||
);
|
||||
material.opacity = baseColor[3];
|
||||
}
|
||||
let metallicFactor = gltfMaterial.pbrMetallicRoughness.metallicFactor;
|
||||
if (metallicFactor !== undefined) {
|
||||
material.metallic = metallicFactor;
|
||||
}
|
||||
let roughnessFactor = gltfMaterial.pbrMetallicRoughness.roughnessFactor;
|
||||
if (roughnessFactor !== undefined) {
|
||||
material.roughness = roughnessFactor;
|
||||
}
|
||||
let emissiveColor = gltfMaterial.emissiveFactor;
|
||||
if (emissiveColor !== undefined) {
|
||||
material.emissive = new OV.Color (
|
||||
@ -744,6 +753,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
|
||||
}
|
||||
|
||||
material.diffuseMap = this.ImportTexture (gltf, gltfMaterial.pbrMetallicRoughness.baseColorTexture);
|
||||
material.metallicMap = this.ImportTexture (gltf, gltfMaterial.pbrMetallicRoughness.metallicRoughnessTexture);
|
||||
material.normalMap = this.ImportTexture (gltf, gltfMaterial.normalTexture);
|
||||
material.emissiveMap = this.ImportTexture (gltf, gltfMaterial.emissiveTexture);
|
||||
if (material.diffuseMap !== null) {
|
||||
|
||||
@ -206,9 +206,9 @@ OV.ImporterIfc = class extends OV.ImporterBase
|
||||
|
||||
let materialIndex = this.materialNameToIndex[materialName];
|
||||
if (materialIndex === undefined) {
|
||||
let material = new OV.Material ();
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
material.name = materialName;
|
||||
material.diffuse = color;
|
||||
material.color = color;
|
||||
material.opacity = ifcColor.w;
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
materialIndex = this.model.AddMaterial (material);
|
||||
|
||||
@ -52,13 +52,13 @@ OV.ImporterO3dv = class extends OV.ImporterBase
|
||||
|
||||
ImportMaterial (materialContent)
|
||||
{
|
||||
let material = new OV.Material ();
|
||||
material.diffuse.Set (255, 255, 255);
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
material.color.Set (255, 255, 255);
|
||||
if (materialContent.name !== undefined) {
|
||||
material.name = materialContent.name;
|
||||
}
|
||||
if (materialContent.diffuse !== undefined) {
|
||||
material.diffuse = OV.ArrayToColor (materialContent.diffuse);
|
||||
if (materialContent.color !== undefined) {
|
||||
material.color = OV.ArrayToColor (materialContent.color);
|
||||
}
|
||||
this.model.AddMaterial (material);
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ OV.ImporterObj = class extends OV.ImporterBase
|
||||
return true;
|
||||
}
|
||||
|
||||
let material = new OV.Material ();
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
let materialName = OV.NameFromLine (line, keyword.length, '#');
|
||||
let materialIndex = this.model.AddMaterial (material);
|
||||
material.name = materialName;
|
||||
@ -248,7 +248,7 @@ OV.ImporterObj = class extends OV.ImporterBase
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.diffuse = CreateColor (parameters);
|
||||
this.currentMaterial.color = CreateColor (parameters);
|
||||
return true;
|
||||
} else if (keyword === 'ks') {
|
||||
if (this.currentMaterial === null || parameters.length < 3) {
|
||||
|
||||
@ -279,9 +279,9 @@ OV.ImporterPly = class extends OV.ImporterBase
|
||||
OV.IntegerToHexString (color[3]);
|
||||
let materialIndex = colorToMaterial[materialName];
|
||||
if (materialIndex === undefined) {
|
||||
let material = new OV.Material ();
|
||||
let material = new OV.Material (OV.MaterialType.Phong);
|
||||
material.name = materialName;
|
||||
material.diffuse = 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;
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
materialIndex = obj.model.AddMaterial (material);
|
||||
|
||||
@ -64,17 +64,27 @@ OV.TextureMap = class
|
||||
}
|
||||
};
|
||||
|
||||
OV.MaterialType =
|
||||
{
|
||||
Phong : 1,
|
||||
Physical : 2
|
||||
};
|
||||
|
||||
OV.Material = class
|
||||
{
|
||||
constructor ()
|
||||
constructor (type)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = '';
|
||||
this.color = new OV.Color (0, 0, 0);
|
||||
|
||||
this.ambient = new OV.Color (0, 0, 0);
|
||||
this.diffuse = new OV.Color (0, 0, 0);
|
||||
this.specular = new OV.Color (0, 0, 0);
|
||||
this.emissive = new OV.Color (0, 0, 0);
|
||||
|
||||
this.metallic = 0.0;
|
||||
this.roughness = 1.0;
|
||||
|
||||
this.shininess = 0.0; // 0.0 .. 1.0
|
||||
this.opacity = 1.0; // 0.0 .. 1.0
|
||||
|
||||
@ -83,6 +93,7 @@ OV.Material = class
|
||||
this.bumpMap = null;
|
||||
this.normalMap = null;
|
||||
this.emissiveMap = null;
|
||||
this.metallicMap = null;
|
||||
|
||||
this.alphaTest = 0.0; // 0.0 .. 1.0
|
||||
this.transparent = false;
|
||||
@ -91,36 +102,20 @@ OV.Material = class
|
||||
this.isDefault = false;
|
||||
}
|
||||
|
||||
EnumerateTextureMaps (enumerator)
|
||||
{
|
||||
if (this.diffuseMap !== null) {
|
||||
enumerator (this.diffuseMap);
|
||||
}
|
||||
if (this.specularMap !== null) {
|
||||
enumerator (this.specularMap);
|
||||
}
|
||||
if (this.bumpMap !== null) {
|
||||
enumerator (this.bumpMap);
|
||||
}
|
||||
if (this.normalMap !== null) {
|
||||
enumerator (this.normalMap);
|
||||
}
|
||||
if (this.emissiveMap !== null) {
|
||||
enumerator (this.emissiveMap);
|
||||
}
|
||||
}
|
||||
|
||||
Clone ()
|
||||
{
|
||||
let cloned = new OV.Material ();
|
||||
let cloned = new OV.Material (this.type);
|
||||
|
||||
cloned.name = this.name;
|
||||
cloned.color = this.color.Clone ();
|
||||
|
||||
cloned.ambient = this.ambient.Clone ();
|
||||
cloned.diffuse = this.diffuse.Clone ();
|
||||
cloned.specular = this.specular.Clone ();
|
||||
cloned.emissive = this.emissive.Clone ();
|
||||
|
||||
cloned.metallic = this.metallic;
|
||||
cloned.roughness = this.roughness;
|
||||
|
||||
cloned.shininess = this.shininess;
|
||||
cloned.opacity = this.opacity;
|
||||
|
||||
@ -129,6 +124,7 @@ OV.Material = class
|
||||
cloned.bumpMap = this.CloneTextureMap (this.bumpMap);
|
||||
cloned.normalMap = this.CloneTextureMap (this.normalMap);
|
||||
cloned.emissiveMap = this.CloneTextureMap (this.emissiveMap);
|
||||
cloned.metallicMap = this.CloneTextureMap (this.metallicMap);
|
||||
|
||||
cloned.alphaTest = this.alphaTest;
|
||||
cloned.transparent = this.transparent;
|
||||
@ -202,3 +198,25 @@ OV.ArrayToColor = function (arr)
|
||||
{
|
||||
return new OV.Color (arr[0], arr[1], arr[2]);
|
||||
};
|
||||
|
||||
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.metallicMap !== null) {
|
||||
enumerator (material.metallicMap);
|
||||
}
|
||||
};
|
||||
|
||||
@ -259,7 +259,7 @@ OV.ReplaceDefaultMaterialColor = function (model, color)
|
||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||
let material = model.GetMaterial (i);
|
||||
if (material.isDefault) {
|
||||
material.diffuse = color;
|
||||
material.color = color;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -44,28 +44,45 @@ OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
||||
}
|
||||
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
let diffuseColor = new THREE.Color (material.diffuse.r / 255.0, material.diffuse.g / 255.0, material.diffuse.b / 255.0);
|
||||
let specularColor = new THREE.Color (material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0);
|
||||
let diffuseColor = new THREE.Color (material.color.r / 255.0, material.color.g / 255.0, material.color.b / 255.0);
|
||||
let emissiveColor = new THREE.Color (material.emissive.r / 255.0, material.emissive.g / 255.0, material.emissive.b / 255.0);
|
||||
if (OV.IsEqual (material.shininess, 0.0)) {
|
||||
specularColor.setRGB (0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
let materialParams = {
|
||||
color : diffuseColor,
|
||||
specular : specularColor,
|
||||
emissive : emissiveColor,
|
||||
shininess : material.shininess * 100.0,
|
||||
opacity : material.opacity,
|
||||
transparent : material.transparent,
|
||||
alphaTest : material.alphaTest,
|
||||
side : THREE.DoubleSide
|
||||
};
|
||||
|
||||
if (params.forceMediumpForMaterials) {
|
||||
materialParams.precision = 'mediump';
|
||||
}
|
||||
|
||||
let threeMaterial = new THREE.MeshPhongMaterial (materialParams);
|
||||
let threeMaterial = null;
|
||||
if (material.type === OV.MaterialType.Phong) {
|
||||
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);
|
||||
if (OV.IsEqual (material.shininess, 0.0)) {
|
||||
specularColor.setRGB (0.0, 0.0, 0.0);
|
||||
}
|
||||
threeMaterial.specular = specularColor;
|
||||
threeMaterial.shininess = material.shininess * 100.0,
|
||||
LoadTexture (threeMaterial, material.specularMap, (threeTexture) => {
|
||||
threeMaterial.specularMap = threeTexture;
|
||||
callbacks.onTextureLoaded ();
|
||||
});
|
||||
} else if (material.type === OV.MaterialType.Physical) {
|
||||
threeMaterial = new THREE.MeshStandardMaterial (materialParams);
|
||||
threeMaterial.metalness = material.metalness;
|
||||
threeMaterial.roughness = material.roughness;
|
||||
LoadTexture (threeMaterial, material.metallicMap, (threeTexture) => {
|
||||
threeMaterial.metalnessMap = threeTexture;
|
||||
threeMaterial.roughnessMap = threeTexture;
|
||||
callbacks.onTextureLoaded ();
|
||||
});
|
||||
}
|
||||
LoadTexture (threeMaterial, material.diffuseMap, (threeTexture) => {
|
||||
if (!material.multiplyDiffuseMap) {
|
||||
threeMaterial.color.setRGB (1.0, 1.0, 1.0);
|
||||
@ -73,10 +90,6 @@ OV.ConvertModelToThreeMeshes = function (model, params, output, callbacks)
|
||||
threeMaterial.map = threeTexture;
|
||||
callbacks.onTextureLoaded ();
|
||||
});
|
||||
LoadTexture (threeMaterial, material.specularMap, (threeTexture) => {
|
||||
threeMaterial.specularMap = threeTexture;
|
||||
callbacks.onTextureLoaded ();
|
||||
});
|
||||
LoadTexture (threeMaterial, material.bumpMap, (threeTexture) => {
|
||||
threeMaterial.bumpMap = threeTexture;
|
||||
callbacks.onTextureLoaded ();
|
||||
|
||||
@ -2,19 +2,19 @@
|
||||
"materials" : [
|
||||
{
|
||||
"name" : "Material 1",
|
||||
"diffuse" : [200, 0, 0]
|
||||
"color" : [200, 0, 0]
|
||||
},
|
||||
{
|
||||
"name" : "Material 2",
|
||||
"diffuse" : [0, 200, 0]
|
||||
"color" : [0, 200, 0]
|
||||
},
|
||||
{
|
||||
"name" : "Material 3",
|
||||
"diffuse" : [0, 0, 200]
|
||||
"color" : [0, 0, 200]
|
||||
},
|
||||
{
|
||||
"name" : "Material 4",
|
||||
"diffuse" : [200, 200, 0]
|
||||
"color" : [200, 200, 0]
|
||||
}
|
||||
],
|
||||
"meshes" : [
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"materials" : [
|
||||
{
|
||||
"name" : "Material",
|
||||
"diffuse" : [200, 0, 0]
|
||||
"color" : [200, 0, 0]
|
||||
}
|
||||
],
|
||||
"meshes" : [
|
||||
|
||||
@ -4,10 +4,10 @@ function CreateTestModel ()
|
||||
{
|
||||
let model = new OV.Model ();
|
||||
|
||||
let material1 = new OV.Material ();
|
||||
let material1 = new OV.Material (OV.MaterialType.Phong);
|
||||
material1.name = 'TestMaterial1';
|
||||
material1.ambient = new OV.Color (0, 0, 0);
|
||||
material1.diffuse = new OV.Color (255, 0, 0);
|
||||
material1.color = new OV.Color (255, 0, 0);
|
||||
material1.specular = new OV.Color (51, 51, 51);
|
||||
material1.diffuseMap = new OV.TextureMap ();
|
||||
material1.diffuseMap.name = 'textures/texture1.png';
|
||||
@ -23,10 +23,10 @@ function CreateTestModel ()
|
||||
material1.bumpMap.buffer = new ArrayBuffer (3);
|
||||
model.AddMaterial (material1);
|
||||
|
||||
let material2 = new OV.Material ();
|
||||
let material2 = new OV.Material (OV.MaterialType.Phong);
|
||||
material2.name = 'TestMaterial2';
|
||||
material2.ambient = new OV.Color (0, 0, 0);
|
||||
material2.diffuse = new OV.Color (0, 255, 0);
|
||||
material2.color = new OV.Color (0, 255, 0);
|
||||
material2.specular = new OV.Color (51, 51, 51);
|
||||
model.AddMaterial (material2);
|
||||
|
||||
@ -214,7 +214,7 @@ describe ('Exporter', function () {
|
||||
let importer = new OV.ImporterStl ();
|
||||
importer.Import (contentBuffer, 'stl', {
|
||||
getDefaultMaterial () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
},
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
@ -308,7 +308,7 @@ describe ('Exporter', function () {
|
||||
let importer = new OV.ImporterPly ();
|
||||
importer.Import (contentBuffer, 'ply', {
|
||||
getDefaultMaterial () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
},
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
@ -338,7 +338,7 @@ describe ('Exporter', function () {
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (contentBuffer, 'gltf', {
|
||||
getDefaultMaterial () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
},
|
||||
getFileBuffer (filePath) {
|
||||
if (filePath == 'model.bin') {
|
||||
@ -376,7 +376,7 @@ describe ('Exporter', function () {
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (contentBuffer, 'glb', {
|
||||
getDefaultMaterial () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
},
|
||||
getFileBuffer (filePath) {
|
||||
return null;
|
||||
|
||||
@ -260,7 +260,7 @@ describe ('Importer Test', function () {
|
||||
assert.deepStrictEqual (importResult.usedFiles, ['single_triangle.stl']);
|
||||
assert.deepStrictEqual (importResult.missingFiles, []);
|
||||
let material = importResult.model.GetMaterial (0);
|
||||
assert.deepStrictEqual (material.diffuse, new OV.Color (200, 0, 0));
|
||||
assert.deepStrictEqual (material.color, new OV.Color (200, 0, 0));
|
||||
done ();
|
||||
},
|
||||
onError : function (importError) {
|
||||
|
||||
@ -123,7 +123,7 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
});
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
@ -163,7 +163,7 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
});
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
@ -205,7 +205,7 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
});
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
@ -221,8 +221,8 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
it ('Mesh To Buffer Cube Materials', function () {
|
||||
var model = new OV.Model ();
|
||||
model.AddMaterial (new OV.Material ());
|
||||
model.AddMaterial (new OV.Material ());
|
||||
model.AddMaterial (new OV.Material (OV.MaterialType.Phong));
|
||||
model.AddMaterial (new OV.Material (OV.MaterialType.Phong));
|
||||
var mesh = new OV.Mesh ();
|
||||
|
||||
mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0));
|
||||
@ -249,7 +249,7 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
});
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
@ -299,7 +299,7 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
});
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
@ -342,7 +342,7 @@ describe ('Mesh Buffer', function () {
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.Material ();
|
||||
return new OV.Material (OV.MaterialType.Phong);
|
||||
});
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ describe ('Model', function() {
|
||||
|
||||
it ('Add Material', function () {
|
||||
var model = new OV.Model ();
|
||||
var material = new OV.Material ();
|
||||
var material = new OV.Material (OV.MaterialType.Phong);
|
||||
material.name = 'example';
|
||||
var index = model.AddMaterial (material);
|
||||
assert.strictEqual (model.MaterialCount (), 1);
|
||||
@ -110,7 +110,7 @@ describe ('Model Finalization', function() {
|
||||
var model = new OV.Model ();
|
||||
var meshIndex = model.AddMesh (mesh);
|
||||
assert.strictEqual (model.MaterialCount (), 0);
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
assert.strictEqual (model.MaterialCount (), 1);
|
||||
var theMesh = model.GetMesh (meshIndex);
|
||||
assert.strictEqual (theMesh.NormalCount (), 1);
|
||||
@ -139,7 +139,7 @@ describe ('Model Finalization', function() {
|
||||
var model = new OV.Model ()
|
||||
var meshIndex = model.AddMesh (mesh);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
|
||||
var theMesh = model.GetMesh (meshIndex);
|
||||
assert.strictEqual (theMesh.NormalCount (), 6);
|
||||
@ -172,7 +172,7 @@ describe ('Model Finalization', function() {
|
||||
var model = new OV.Model ()
|
||||
var meshIndex = model.AddMesh (mesh);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
|
||||
var theMesh = model.GetMesh (meshIndex);
|
||||
assert.strictEqual (theMesh.NormalCount (), 9);
|
||||
|
||||
@ -19,7 +19,7 @@ describe ('Model Utils', function () {
|
||||
mesh2.AddTriangle (new OV.Triangle (0, 1, 2));
|
||||
model.AddMesh (mesh2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (); });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong); });
|
||||
assert.deepStrictEqual (testUtils.ModelToObject (model), {
|
||||
name : '',
|
||||
materials : [
|
||||
@ -103,7 +103,7 @@ describe ('Model Utils', function () {
|
||||
mesh2.AddTriangle (new OV.Triangle (0, 1, 2));
|
||||
model.AddMesh (mesh2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (); });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong); });
|
||||
|
||||
let mesh1Bounds = OV.GetBoundingBox (model.GetMesh (0));
|
||||
assert (OV.CoordIsEqual3D (mesh1Bounds.min, new OV.Coord3D (0.0, 0.0, 0.0)));
|
||||
|
||||
@ -75,7 +75,7 @@ module.exports =
|
||||
});
|
||||
importer.Import (content, extension, {
|
||||
getDefaultMaterial : function () {
|
||||
var material = new OV.Material ();
|
||||
var material = new OV.Material (OV.MaterialType.Phong);
|
||||
return material;
|
||||
},
|
||||
getFileBuffer : function (filePath) {
|
||||
|
||||
@ -148,7 +148,7 @@ module.exports =
|
||||
let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0);
|
||||
model.AddMesh (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -163,7 +163,7 @@ module.exports =
|
||||
let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0);
|
||||
model.AddMesh (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -178,7 +178,7 @@ module.exports =
|
||||
let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0);
|
||||
model.AddMesh (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -227,7 +227,7 @@ module.exports =
|
||||
{
|
||||
var model = new OV.Model ();
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () { return new OV.Material () });
|
||||
OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 164 KiB |
@ -63,13 +63,14 @@ OV.DetailsSidebarPanel = class extends OV.SidebarPanel
|
||||
this.Clear ();
|
||||
let table = $('<div>').addClass ('ov_property_table').appendTo (this.contentDiv);
|
||||
this.AddProperty (table, new OV.Property (OV.PropertyType.Text, 'Source', material.isDefault ? 'Default' : 'Model'));
|
||||
this.AddProperty (table, new OV.Property (OV.PropertyType.Color, 'Color', material.diffuse));
|
||||
this.AddProperty (table, new OV.Property (OV.PropertyType.Color, 'Color', material.color));
|
||||
this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Opacity', material.opacity));
|
||||
AddTextureMap (this, table, 'Diffuse Map', material.diffuseMap);
|
||||
AddTextureMap (this, table, 'Specular Map', material.specularMap);
|
||||
AddTextureMap (this, table, 'Bump Map', material.bumpMap);
|
||||
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.metallicMap);
|
||||
this.Resize ();
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ OV.NavigatorInfoPanel = class
|
||||
let usedMaterial = usedMaterials[i];
|
||||
materialItems.push ({
|
||||
name : OV.GetMaterialName (usedMaterial.name),
|
||||
color : usedMaterial.diffuse
|
||||
color : usedMaterial.color
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -509,7 +509,7 @@ OV.Website = class
|
||||
return {
|
||||
index : materialIndex,
|
||||
name : material.name,
|
||||
diffuse : material.diffuse.Clone ()
|
||||
color : material.color.Clone ()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user