!2776 开发:优化获取概念透明材质代码

Merge pull request !2776 from 林三/op_code
pull/2835/head
林三 3 months ago
parent e812b195e7
commit d57d3d84f4

@ -321,9 +321,8 @@ export class ColorMaterial
} }
private static _ConceptualMaterial: Map<string, ShaderMaterial> = new Map(); private static _ConceptualMaterial: Map<string, ShaderMaterial> = new Map();
static GetConceptualMaterial(color: number, side: Side = FrontSide, enableTransparent = false, freeze = false, opacity?: number) static GetConceptualMaterial(color: number, side: Side = FrontSide, enableTransparent = false)
{ {
if (freeze) color = 257;
let key = `${color},${side},${enableTransparent ? 1 : 0}`; let key = `${color},${side},${enableTransparent ? 1 : 0}`;
if (this._ConceptualMaterial.has(key)) if (this._ConceptualMaterial.has(key))
return this._ConceptualMaterial.get(key); return this._ConceptualMaterial.get(key);
@ -336,15 +335,7 @@ export class ColorMaterial
get: () => mtl.uniforms.opacity.value !== 1 get: () => mtl.uniforms.opacity.value !== 1
}); });
Object.defineProperty(mtl.uniforms.opacity, "value", { Object.defineProperty(mtl.uniforms.opacity, "value", {
get: () => get: () => HostApplicationServices.ConceptualOpacity
{
let conceptualOpacity = HostApplicationServices.ConceptualOpacity;
if (freeze)
conceptualOpacity = 0.5;
else if (opacity)
conceptualOpacity = opacity;
return conceptualOpacity;
}
}); });
} }
this._ConceptualMaterial.set(key, mtl); this._ConceptualMaterial.set(key, mtl);

@ -2199,7 +2199,7 @@ export class Board extends ExtrudeSolid
//del_exp2_end //del_exp2_end
//绘制排版面时使用的颜色 //绘制排版面时使用的颜色
private get PlaceColor() { return this._Color === 8 ? 9 : this._Color; } private get PlaceColor() { return this._Color === 8 ? 9 : this.DrawColorIndex; }
//排版面网格 //排版面网格
private GetPlaceFace(): Mesh private GetPlaceFace(): Mesh
{ {

@ -1,6 +1,6 @@
import { Geom3 } from '@jscad/modeling/src/geometries/types'; import { Geom3 } from '@jscad/modeling/src/geometries/types';
import Flatbush from 'flatbush'; import Flatbush from 'flatbush';
import { Box3, BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, Float32BufferAttribute, FrontSide, Frustum, Geometry, Group, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Line as TLine, UVGenerator, Vector3 } from "three"; import { Box3, BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, Float32BufferAttribute, FrontSide, Frustum, Geometry, Group, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, Material, Matrix3, Matrix4, Mesh, Object3D, Line as TLine, UVGenerator, Vector3 } from "three";
import { Line2 } from "three/examples/jsm/lines/Line2"; import { Line2 } from "three/examples/jsm/lines/Line2";
import { LineGeometry } from "three/examples/jsm/lines/LineGeometry"; import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
import { arrayClone, arrayLast, arrayPushArray, arrayRemoveIf, arrayRemoveOnce, arraySortByNumber, arraySum } from "../../Common/ArrayExt"; import { arrayClone, arrayLast, arrayPushArray, arrayRemoveIf, arrayRemoveOnce, arraySortByNumber, arraySum } from "../../Common/ArrayExt";
@ -1692,7 +1692,7 @@ export class ExtrudeSolid extends Entity
else if (renderType === RenderType.Conceptual) else if (renderType === RenderType.Conceptual)
{ {
return new Object3D().add( return new Object3D().add(
new Mesh(this.MeshGeometry, ColorMaterial.GetConceptualMaterial(this.DrawColorIndex, FrontSide, true, this.Freeze)), new Mesh(this.MeshGeometry, this.GetConceptualMaterial()),
new LineSegments(this.EdgeGeometry, ColorMaterial.GetConceptualEdgeMaterial()) new LineSegments(this.EdgeGeometry, ColorMaterial.GetConceptualEdgeMaterial())
); );
} }
@ -2130,7 +2130,7 @@ export class ExtrudeSolid extends Entity
else if (renderType === RenderType.Conceptual) else if (renderType === RenderType.Conceptual)
{ {
return obj.add( return obj.add(
new Mesh(this.MeshGeometry, ColorMaterial.GetConceptualMaterial(this.DrawColorIndex, FrontSide, true, this.Freeze)), new Mesh(this.MeshGeometry, this.GetConceptualMaterial()),
new LineSegments(this.EdgeGeometry, ColorMaterial.GetConceptualEdgeMaterial()) new LineSegments(this.EdgeGeometry, ColorMaterial.GetConceptualEdgeMaterial())
); );
} }
@ -2185,7 +2185,7 @@ export class ExtrudeSolid extends Entity
else if (renderType === RenderType.Conceptual) else if (renderType === RenderType.Conceptual)
{ {
let mesh = obj.children[0] as Mesh; let mesh = obj.children[0] as Mesh;
mesh.material = ColorMaterial.GetConceptualMaterial(this.DrawColorIndex, FrontSide, true, this.Freeze); mesh.material = this.GetConceptualMaterial();
} }
else if (renderType === RenderType.Physical2) else if (renderType === RenderType.Physical2)
{ {
@ -2198,6 +2198,18 @@ export class ExtrudeSolid extends Entity
mesh.material = this.MeshMaterial; mesh.material = this.MeshMaterial;
} }
} }
//获取概念视图材质 冻结状态使用257色号 半透明
private GetConceptualMaterial()
{
let mtl: Material;
if (this.Freeze)
mtl = ColorMaterial.GetBasicMaterialTransparent2(257, 0.5);
else
mtl = ColorMaterial.GetConceptualMaterial(this.DrawColorIndex, FrontSide, true);
return mtl;
}
private GetModelGroove() private GetModelGroove()
{ {
const grooves: ExtrudeSolid[] = []; const grooves: ExtrudeSolid[] = [];
@ -2218,7 +2230,7 @@ export class ExtrudeSolid extends Entity
const meshGeo = grooveClone.MeshGeometry; const meshGeo = grooveClone.MeshGeometry;
meshGeo.applyMatrix4(mtx); meshGeo.applyMatrix4(mtx);
const mesh = new Mesh(meshGeo, ColorMaterial.GetConceptualMaterial(1, FrontSide, true, this.Freeze, 0.6)); const mesh = new Mesh(meshGeo, ColorMaterial.GetConceptualMaterial(1, 0.6));
group.add(mesh, line); group.add(mesh, line);
} }
return group; return group;

Loading…
Cancel
Save