Introduce material source parameter to distinguish materials created for lines and faces.
This commit is contained in:
parent
4f0336c268
commit
978b1dfd19
@ -70,12 +70,19 @@ export const MaterialType =
|
|||||||
Physical : 2
|
Physical : 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const MaterialSource =
|
||||||
|
{
|
||||||
|
Model : 1,
|
||||||
|
DefaultFace : 2,
|
||||||
|
DefaultLine : 3
|
||||||
|
};
|
||||||
|
|
||||||
export class MaterialBase
|
export class MaterialBase
|
||||||
{
|
{
|
||||||
constructor (type)
|
constructor (type)
|
||||||
{
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.isDefault = false;
|
this.source = MaterialSource.Model;
|
||||||
|
|
||||||
this.name = '';
|
this.name = '';
|
||||||
this.color = new RGBColor (0, 0, 0);
|
this.color = new RGBColor (0, 0, 0);
|
||||||
@ -88,7 +95,7 @@ export class MaterialBase
|
|||||||
if (this.type !== rhs.type) {
|
if (this.type !== rhs.type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.isDefault !== rhs.isDefault) {
|
if (this.source !== rhs.source) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.name !== rhs.name) {
|
if (this.name !== rhs.name) {
|
||||||
|
|||||||
@ -1,15 +1,9 @@
|
|||||||
import { CopyObjectAttributes } from '../core/core.js';
|
import { CopyObjectAttributes } from '../core/core.js';
|
||||||
import { AddCoord3D, Coord3D, CoordIsEqual3D } from '../geometry/coord3d.js';
|
import { AddCoord3D, Coord3D, CoordIsEqual3D } from '../geometry/coord3d.js';
|
||||||
import { RGBColor } from './color.js';
|
import { RGBColor } from './color.js';
|
||||||
import { PhongMaterial } from './material.js';
|
import { MaterialSource, PhongMaterial } from './material.js';
|
||||||
import { CalculateTriangleNormal, IsEmptyMesh } from './meshutils.js';
|
import { CalculateTriangleNormal, IsEmptyMesh } from './meshutils.js';
|
||||||
|
|
||||||
const MaterialSource =
|
|
||||||
{
|
|
||||||
Line : 1,
|
|
||||||
Face : 2
|
|
||||||
};
|
|
||||||
|
|
||||||
class ModelFinalizer
|
class ModelFinalizer
|
||||||
{
|
{
|
||||||
constructor (params)
|
constructor (params)
|
||||||
@ -148,7 +142,7 @@ class ModelFinalizer
|
|||||||
for (let i = 0; i < mesh.LineCount (); i++) {
|
for (let i = 0; i < mesh.LineCount (); i++) {
|
||||||
let line = mesh.GetLine (i);
|
let line = mesh.GetLine (i);
|
||||||
if (line.mat === null) {
|
if (line.mat === null) {
|
||||||
line.mat = this.GetDefaultMaterialIndex (model, MaterialSource.Line);
|
line.mat = this.GetDefaultMaterialIndex (model, MaterialSource.DefaultLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +150,7 @@ class ModelFinalizer
|
|||||||
let triangle = mesh.GetTriangle (i);
|
let triangle = mesh.GetTriangle (i);
|
||||||
this.FinalizeTriangle (mesh, triangle, meshStatus);
|
this.FinalizeTriangle (mesh, triangle, meshStatus);
|
||||||
if (triangle.mat === null) {
|
if (triangle.mat === null) {
|
||||||
triangle.mat = this.GetDefaultMaterialIndex (model, MaterialSource.Face);
|
triangle.mat = this.GetDefaultMaterialIndex (model, MaterialSource.DefaultFace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,22 +205,22 @@ class ModelFinalizer
|
|||||||
|
|
||||||
GetDefaultMaterialIndex (model, source)
|
GetDefaultMaterialIndex (model, source)
|
||||||
{
|
{
|
||||||
function GetIndex (model, index, color)
|
function GetIndex (model, index, source, color)
|
||||||
{
|
{
|
||||||
if (index !== null) {
|
if (index !== null) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
let defaultMaterial = new PhongMaterial ();
|
let defaultMaterial = new PhongMaterial ();
|
||||||
defaultMaterial.color = color;
|
defaultMaterial.color = color;
|
||||||
defaultMaterial.isDefault = true;
|
defaultMaterial.source = source;
|
||||||
return model.AddMaterial (defaultMaterial);
|
return model.AddMaterial (defaultMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source === MaterialSource.Line) {
|
if (source === MaterialSource.DefaultLine) {
|
||||||
this.defaultLineMaterialIndex = GetIndex (model, this.defaultLineMaterialIndex, this.params.defaultLineMaterialColor);
|
this.defaultLineMaterialIndex = GetIndex (model, this.defaultLineMaterialIndex, MaterialSource.DefaultLine, this.params.defaultLineMaterialColor);
|
||||||
return this.defaultLineMaterialIndex;
|
return this.defaultLineMaterialIndex;
|
||||||
} else if (source === MaterialSource.Face) {
|
} else if (source === MaterialSource.DefaultFace) {
|
||||||
this.defaultMaterialIndex = GetIndex (model, this.defaultMaterialIndex, this.params.defaultMaterialColor);
|
this.defaultMaterialIndex = GetIndex (model, this.defaultMaterialIndex, MaterialSource.DefaultFace, this.params.defaultMaterialColor);
|
||||||
return this.defaultMaterialIndex;
|
return this.defaultMaterialIndex;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { BoundingBoxCalculator3D } from '../geometry/box3d.js';
|
import { BoundingBoxCalculator3D } from '../geometry/box3d.js';
|
||||||
import { Octree } from '../geometry/octree.js';
|
import { Octree } from '../geometry/octree.js';
|
||||||
|
import { MaterialSource } from './material.js';
|
||||||
import { IsEmptyMesh } from './meshutils.js';
|
import { IsEmptyMesh } from './meshutils.js';
|
||||||
import { Model } from './model.js';
|
import { Model } from './model.js';
|
||||||
import { Topology } from './topology.js';
|
import { Topology } from './topology.js';
|
||||||
@ -99,7 +100,7 @@ export function HasDefaultMaterial (model)
|
|||||||
{
|
{
|
||||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||||
let material = model.GetMaterial (i);
|
let material = model.GetMaterial (i);
|
||||||
if (material.isDefault && !material.vertexColors) {
|
if (material.source !== MaterialSource.Model && !material.vertexColors) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ export function ReplaceDefaultMaterialsColor (model, color)
|
|||||||
{
|
{
|
||||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
for (let i = 0; i < model.MaterialCount (); i++) {
|
||||||
let material = model.GetMaterial (i);
|
let material = model.GetMaterial (i);
|
||||||
if (material.isDefault) {
|
if (material.source === MaterialSource.DefaultFace) {
|
||||||
material.color = color;
|
material.color = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RunTasksBatch } from '../core/taskrunner.js';
|
import { RunTasksBatch } from '../core/taskrunner.js';
|
||||||
import { IsEqual } from '../geometry/geometry.js';
|
import { IsEqual } from '../geometry/geometry.js';
|
||||||
import { CreateObjectUrl, CreateObjectUrlWithMimeType } from '../io/bufferutils.js';
|
import { CreateObjectUrl, CreateObjectUrlWithMimeType } from '../io/bufferutils.js';
|
||||||
import { MaterialType } from '../model/material.js';
|
import { MaterialSource, MaterialType } from '../model/material.js';
|
||||||
import { MeshInstance, MeshInstanceId } from '../model/meshinstance.js';
|
import { MeshInstance, MeshInstanceId } from '../model/meshinstance.js';
|
||||||
import { IsEmptyMesh } from '../model/meshutils.js';
|
import { IsEmptyMesh } from '../model/meshutils.js';
|
||||||
import { ConvertColorToThreeColor, GetShadingType, ShadingType } from './threeutils.js';
|
import { ConvertColorToThreeColor, GetShadingType, ShadingType } from './threeutils.js';
|
||||||
@ -204,7 +204,8 @@ export class ThreeMaterialHandler
|
|||||||
threeMaterial.emissiveMap = threeTexture;
|
threeMaterial.emissiveMap = threeTexture;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (material.isDefault) {
|
if (material.source !== MaterialSource.Model) {
|
||||||
|
threeMaterial.userData.source = material.source;
|
||||||
this.conversionOutput.defaultMaterials.push (threeMaterial);
|
this.conversionOutput.defaultMaterials.push (threeMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +226,8 @@ export class ThreeMaterialHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
let threeMaterial = new THREE.LineBasicMaterial (materialParams);
|
let threeMaterial = new THREE.LineBasicMaterial (materialParams);
|
||||||
if (material.isDefault) {
|
if (material.source !== MaterialSource.Model) {
|
||||||
|
threeMaterial.userData.source = material.source;
|
||||||
this.conversionOutput.defaultMaterials.push (threeMaterial);
|
this.conversionOutput.defaultMaterials.push (threeMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Direction } from '../geometry/geometry.js';
|
import { Direction } from '../geometry/geometry.js';
|
||||||
import { Importer } from '../import/importer.js';
|
import { Importer } from '../import/importer.js';
|
||||||
import { RevokeObjectUrl } from '../io/bufferutils.js';
|
import { RevokeObjectUrl } from '../io/bufferutils.js';
|
||||||
|
import { MaterialSource } from '../model/material.js';
|
||||||
import { ConvertModelToThreeObject, ModelToThreeConversionOutput, ModelToThreeConversionParams } from './threeconverter.js';
|
import { ConvertModelToThreeObject, ModelToThreeConversionOutput, ModelToThreeConversionParams } from './threeconverter.js';
|
||||||
import { ConvertColorToThreeColor, HasHighpDriverIssue } from './threeutils.js';
|
import { ConvertColorToThreeColor, HasHighpDriverIssue } from './threeutils.js';
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ export class ThreeModelLoader
|
|||||||
{
|
{
|
||||||
if (this.defaultMaterials !== null) {
|
if (this.defaultMaterials !== null) {
|
||||||
for (let defaultMaterial of this.defaultMaterials) {
|
for (let defaultMaterial of this.defaultMaterials) {
|
||||||
if (!defaultMaterial.vertexColors) {
|
if (!defaultMaterial.vertexColors && defaultMaterial.userData.source === MaterialSource.DefaultFace) {
|
||||||
defaultMaterial.color = ConvertColorToThreeColor (defaultColor);
|
defaultMaterial.color = ConvertColorToThreeColor (defaultColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { AddDiv, AddDomElement, ClearDomElement } from '../engine/viewer/domutil
|
|||||||
import { SidebarPanel } from './sidebarpanel.js';
|
import { SidebarPanel } from './sidebarpanel.js';
|
||||||
import { CreateInlineColorCircle } from './utils.js';
|
import { CreateInlineColorCircle } from './utils.js';
|
||||||
import { GetFileName, IsUrl } from '../engine/io/fileutils.js';
|
import { GetFileName, IsUrl } from '../engine/io/fileutils.js';
|
||||||
import { MaterialType } from '../engine/model/material.js';
|
import { MaterialSource, MaterialType } from '../engine/model/material.js';
|
||||||
import { RGBColorToHexString } from '../engine/model/color.js';
|
import { RGBColorToHexString } from '../engine/model/color.js';
|
||||||
import { Unit } from '../engine/model/unit.js';
|
import { Unit } from '../engine/model/unit.js';
|
||||||
|
|
||||||
@ -104,7 +104,8 @@ export class SidebarDetailsPanel extends SidebarPanel
|
|||||||
} else if (material.type === MaterialType.Physical) {
|
} else if (material.type === MaterialType.Physical) {
|
||||||
typeString = 'Physical';
|
typeString = 'Physical';
|
||||||
}
|
}
|
||||||
this.AddProperty (table, new Property (PropertyType.Text, 'Source', material.isDefault ? 'Default' : 'Model'));
|
let materialSource = (material.source !== MaterialSource.Model) ? 'Default' : 'Model';
|
||||||
|
this.AddProperty (table, new Property (PropertyType.Text, 'Source', materialSource));
|
||||||
this.AddProperty (table, new Property (PropertyType.Text, 'Type', typeString));
|
this.AddProperty (table, new Property (PropertyType.Text, 'Type', typeString));
|
||||||
if (material.vertexColors) {
|
if (material.vertexColors) {
|
||||||
this.AddProperty (table, new Property (PropertyType.Text, 'Color', 'Vertex colors'));
|
this.AddProperty (table, new Property (PropertyType.Text, 'Color', 'Vertex colors'));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user