Replace default material without reloading the model.
This commit is contained in:
parent
f6f5a4c00d
commit
d32dc8485a
18
source/external/threeconverter.js
vendored
18
source/external/threeconverter.js
vendored
@ -6,9 +6,17 @@ OV.ModelToThreeConversionParams = class
|
||||
}
|
||||
};
|
||||
|
||||
OV.ConvertModelToThreeMeshes = function (model, params, callbacks)
|
||||
OV.ModelToThreeConversionResult = class
|
||||
{
|
||||
function CreateThreeMaterial (model, materialIndex)
|
||||
constructor ()
|
||||
{
|
||||
this.defaultMaterial = null;
|
||||
}
|
||||
};
|
||||
|
||||
OV.ConvertModelToThreeMeshes = function (model, params, result, callbacks)
|
||||
{
|
||||
function CreateThreeMaterial (model, materialIndex, params, result)
|
||||
{
|
||||
function SetTextureParameters (texture, threeTexture)
|
||||
{
|
||||
@ -82,6 +90,10 @@ OV.ConvertModelToThreeMeshes = function (model, params, callbacks)
|
||||
callbacks.onTextureLoaded ();
|
||||
});
|
||||
|
||||
if (material.isDefault) {
|
||||
result.defaultMaterial = threeMaterial;
|
||||
}
|
||||
|
||||
return threeMaterial;
|
||||
}
|
||||
|
||||
@ -183,7 +195,7 @@ OV.ConvertModelToThreeMeshes = function (model, params, callbacks)
|
||||
|
||||
let modelThreeMaterials = [];
|
||||
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
|
||||
let threeMaterial = CreateThreeMaterial (model, materialIndex);
|
||||
let threeMaterial = CreateThreeMaterial (model, materialIndex, params, result);
|
||||
modelThreeMaterials.push (threeMaterial);
|
||||
}
|
||||
|
||||
|
||||
5
source/external/threemodelloader.js
vendored
5
source/external/threemodelloader.js
vendored
@ -7,6 +7,7 @@ OV.ThreeModelLoader = class
|
||||
this.importer.AddImporter (new OV.ImporterIfc ());
|
||||
this.callbacks = null;
|
||||
this.inProgress = false;
|
||||
this.defaultMaterial = null;
|
||||
this.hasHighpDriverIssue = OV.HasHighpDriverIssue ();
|
||||
}
|
||||
|
||||
@ -77,11 +78,13 @@ OV.ThreeModelLoader = class
|
||||
this.callbacks.onVisualizationStart ();
|
||||
let params = new OV.ModelToThreeConversionParams ();
|
||||
params.forceMediumpForMaterials = this.hasHighpDriverIssue;
|
||||
OV.ConvertModelToThreeMeshes (importResult.model, params, {
|
||||
let result = new OV.ModelToThreeConversionResult ();
|
||||
OV.ConvertModelToThreeMeshes (importResult.model, params, result, {
|
||||
onTextureLoaded : function () {
|
||||
obj.callbacks.onTextureLoaded ();
|
||||
},
|
||||
onModelLoaded : function (meshes) {
|
||||
obj.defaultMaterial = result.defaultMaterial;
|
||||
obj.callbacks.onModelFinished (importResult, meshes);
|
||||
obj.inProgress = false;
|
||||
}
|
||||
|
||||
@ -87,6 +87,8 @@ OV.Material = class
|
||||
this.alphaTest = 0.0; // 0.0 .. 1.0
|
||||
this.transparent = false;
|
||||
this.multiplyDiffuseMap = false;
|
||||
|
||||
this.isDefault = false;
|
||||
}
|
||||
|
||||
EnumerateTextureMaps (enumerator)
|
||||
|
||||
@ -109,7 +109,9 @@ OV.FinalizeModel = function (model, getDefaultMaterial)
|
||||
let defaultMaterialIndex = null;
|
||||
let getDefaultMaterialIndex = function () {
|
||||
if (defaultMaterialIndex === null) {
|
||||
defaultMaterialIndex = model.AddMaterial (getDefaultMaterial ());
|
||||
let defaultMaterial = getDefaultMaterial ();
|
||||
defaultMaterial.isDefault = true;
|
||||
defaultMaterialIndex = model.AddMaterial (defaultMaterial);
|
||||
}
|
||||
return defaultMaterialIndex;
|
||||
};
|
||||
|
||||
@ -253,3 +253,13 @@ OV.IsSolid = function (element)
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
OV.ReplaceDefaultMaterialColor = function (model, color)
|
||||
{
|
||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||
let material = model.GetMaterial (i);
|
||||
if (material.isDefault) {
|
||||
material.diffuse = color;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -62,6 +62,7 @@ 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.Percent, 'Opacity', material.opacity));
|
||||
AddTextureMap (this, table, 'Diffuse Map', material.diffuseMap);
|
||||
|
||||
@ -462,7 +462,11 @@ OV.Website = class
|
||||
onChange : function (newVal) {
|
||||
obj.importSettings.defaultColor = newVal;
|
||||
obj.cookieHandler.SetColorVal ('ov_default_color', newVal);
|
||||
obj.ReloadFiles ();
|
||||
if (obj.modelLoader.defaultMaterial !== null) {
|
||||
OV.ReplaceDefaultMaterialColor (obj.model, newVal);
|
||||
obj.modelLoader.defaultMaterial.color = new THREE.Color (newVal.r / 255.0, newVal.g / 255.0, newVal.b / 255.0);
|
||||
}
|
||||
obj.viewer.Render ();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user