!2981 优化:直线和圆弧墙提取公共函数GetMtlLockedStatus和MeshMaterials

pull/2953/MERGE
zc 2 months ago committed by ChenX
parent 8b2748b353
commit f9921ed7d9

@ -1,4 +1,4 @@
import { BufferGeometry, Face3, Geometry, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, Material, MathUtils, Matrix3, Mesh, Object3D, ShapeUtils, Line as TLine, Vector2, Vector3 } from "three";
import { BufferGeometry, Face3, Geometry, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, MathUtils, Matrix3, Mesh, Object3D, ShapeUtils, Line as TLine, Vector2, Vector3 } from "three";
import { Line2 } from "three/examples/jsm/lines/Line2";
import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
import { HostApplicationServices } from "../../../../ApplicationServices/HostApplicationServices";
@ -834,36 +834,6 @@ export class RoomWallArc extends RoomWallBase
OverWriteMaterial = new Map<number, ObjectId<PhysicalMaterialRecord>>();//section index -> materialId
GetMtlLockedStatus()
{
let partMtlLocked = false;
let allMtlLocked = true;
for (const [, v] of this.OverWriteMaterial)
{
if (v?.Object?.IsMaterialLock)
{
partMtlLocked = true;
continue;
}
allMtlLocked = false;
}
const meshSize = this.MeshMaterials.length;
if (this.OverWriteMaterial.size !== meshSize)
{
if (super.Material?.Object?.IsMaterialLock)
partMtlLocked = true;
else
allMtlLocked = false;
}
return {
partMtlLocked,
allMtlLocked,
};
}
UpdateDrawObjectMaterial(renderType: RenderType, obj: Object3D)
{
if (renderType === RenderType.Physical)
@ -873,48 +843,6 @@ export class RoomWallArc extends RoomWallBase
}
}
get MeshMaterials(): Material[]
{
let defaultMtl = super.MeshMaterial;
let materials: Material[] = [];
let materialIndex = 0;
const addMaterial = (curves: (Arc | Line)[]) =>
{
if (curves)
for (let c of curves)
{
if (c[CURVE_FACE_TYPE_KEY] === WallFaceType.Outside)
continue;
materials.push(this.OverWriteMaterial.get(materialIndex)?.Object.Material ?? defaultMtl);
materialIndex++;
//这里不使用1
if (materialIndex === 1)
{
materials.push(defaultMtl);
materialIndex++;
}
}
};
addMaterial(this.LeftCurves);
addMaterial(this.RightCurves);
addMaterial(this.LidCurves);
if (this.Region)
{
materials.push(this.OverWriteMaterial.get(materialIndex)?.Object.Material ?? defaultMtl);
materialIndex++;
if (HostApplicationServices.DrawWallBottomFace)
materials.push(this.OverWriteMaterial.get(materialIndex + 1)?.Object.Material ?? defaultMtl);
}
return materials;
}
GetPrintObject3D()
{
let geometry = new LineGeometry();

@ -1,4 +1,4 @@
import { Mesh, MeshStandardMaterial, Object3D, Line as TLine } from "three";
import { Material, Mesh, MeshStandardMaterial, Object3D, Line as TLine } from "three";
import { HostApplicationServices } from "../../../../ApplicationServices/HostApplicationServices";
import { ColorMaterial } from "../../../../Common/ColorPalette";
import { UpdateDraw } from "../../../../Common/Status";
@ -158,6 +158,36 @@ export abstract class RoomWallBase extends RoomBase
this.Update(UpdateDraw.Material);
}
GetMtlLockedStatus()
{
let partMtlLocked = false;
let allMtlLocked = true;
for (const [, v] of this.OverWriteMaterial)
{
if (v?.Object?.IsMaterialLock)
{
partMtlLocked = true;
continue;
}
allMtlLocked = false;
}
const meshSize = this.MeshMaterials.length;
if (this.OverWriteMaterial.size !== meshSize)
{
if (super.Material?.Object?.IsMaterialLock)
partMtlLocked = true;
else
allMtlLocked = false;
}
return {
partMtlLocked,
allMtlLocked,
};
}
protected get MeshMaterial()
{
if (this._MaterialId && this._MaterialId.Object)
@ -165,6 +195,46 @@ export abstract class RoomWallBase extends RoomBase
return HostApplicationServices.DefaultWallMaterial ?? HostApplicationServices.DefaultMeshMaterial;
}
get MeshMaterials(): Material[]
{
let defaultMtl = this.MeshMaterial;
let materials: Material[] = [];
let materialIndex = 0;
const addMaterial = (curves: (Arc | Line)[]) =>
{
if (curves)
for (let c of curves)
{
if (c[CURVE_FACE_TYPE_KEY] === WallFaceType.Outside)
continue;
materials.push(this.OverWriteMaterial.get(materialIndex)?.Object.Material ?? defaultMtl);
materialIndex++;
//这里不使用1
if (materialIndex === 1)
{
materials.push(defaultMtl);
materialIndex++;
}
}
};
addMaterial(this.LeftCurves);
addMaterial(this.RightCurves);
addMaterial(this.LidCurves);
if (this.Region)
{
materials.push(this.OverWriteMaterial.get(materialIndex)?.Object.Material ?? defaultMtl);
if (HostApplicationServices.DrawWallBottomFace)
materials.push(this.OverWriteMaterial.get(materialIndex + 1)?.Object.Material ?? defaultMtl);
}
return materials;
}
//标记算法 求出分裂或合并墙时材质状态
ResetSign(oldSign: Map<number, number>, newSign: Map<number, number>, allChange?: boolean, isLid?: boolean)
{

@ -1,4 +1,4 @@
import { Box3, BufferGeometry, Color, Face3, Geometry, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, Material, MathUtils, Matrix3, Mesh, Object3D, ShapeUtils, Line as TLine, Vector2, Vector3 } from "three";
import { Box3, BufferGeometry, Color, Face3, Geometry, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, MathUtils, Matrix3, Mesh, Object3D, ShapeUtils, Line as TLine, Vector2, Vector3 } from "three";
import { Line2 } from "three/examples/jsm/lines/Line2";
import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
import { HostApplicationServices } from "../../../../ApplicationServices/HostApplicationServices";
@ -13,7 +13,6 @@ import { MoveMatrix, ZAxis, ZeroVec, equaln, equalv3, midPoint } from "../../../
import { RenderType } from "../../../../GraphicsSystem/RenderType";
import { Factory } from "../../../CADFactory";
import { CADFiler } from "../../../CADFiler";
import { Arc } from "../../../Entity/Arc";
import { Curve } from "../../../Entity/Curve";
import { Line } from "../../../Entity/Line";
import { ObjectId } from "../../../ObjectId";
@ -730,76 +729,6 @@ export class RoomWallLine extends RoomWallBase
return [line, mesh];
}
get MeshMaterials(): Material[]
{
let defaultMtl = super.MeshMaterial;
let materials: Material[] = [];
let materialIndex = 0;
const addMaterial = (curves: (Arc | Line)[]) =>
{
if (curves)
for (let c of curves)
{
if (c[CURVE_FACE_TYPE_KEY] === WallFaceType.Outside)
continue;
materials.push(this.OverWriteMaterial.get(materialIndex)?.Object.Material ?? defaultMtl);
materialIndex++;
//这里不使用1
if (materialIndex === 1)
{
materials.push(defaultMtl);
materialIndex++;
}
}
};
addMaterial(this.LeftCurves);
addMaterial(this.RightCurves);
addMaterial(this.LidCurves);
if (this.Region)
{
materials.push(this.OverWriteMaterial.get(materialIndex)?.Object.Material ?? defaultMtl);
if (HostApplicationServices.DrawWallBottomFace)
materials.push(this.OverWriteMaterial.get(materialIndex + 1)?.Object.Material ?? defaultMtl);
}
return materials;
}
GetMtlLockedStatus()
{
let partMtlLocked = false;
let allMtlLocked = true;
for (const [, v] of this.OverWriteMaterial)
{
if (v?.Object?.IsMaterialLock)
{
partMtlLocked = true;
continue;
}
allMtlLocked = false;
}
const meshSize = this.MeshMaterials.length;
if (this.OverWriteMaterial.size !== meshSize)
{
if (super.Material?.Object?.IsMaterialLock)
partMtlLocked = true;
else
allMtlLocked = false;
}
return {
partMtlLocked,
allMtlLocked,
};
}
InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
{
if (renderType === RenderType.Physical)

Loading…
Cancel
Save