diff --git a/packages/chili-core/src/model/entity.ts b/packages/chili-core/src/model/entity.ts index 230e626e..3d680963 100644 --- a/packages/chili-core/src/model/entity.ts +++ b/packages/chili-core/src/model/entity.ts @@ -1,37 +1,30 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { HistoryObservable, IEqualityComparer, Result } from "../foundation"; +import { HistoryObservable } from "../foundation"; import { I18nKeys } from "../i18n"; -import { IShape } from "../shape"; +import { Matrix4 } from "../math"; +import { Serializer } from "../serialize"; export abstract class Entity extends HistoryObservable { - protected shouldRegenerate: boolean = true; abstract display: I18nKeys; - protected _shape: Result = Result.err("Not initialised"); - get shape(): Result { - if (this.shouldRegenerate) { - this._shape = this.generateShape(); - this.shouldRegenerate = false; - } - return this._shape; + protected _matrix: Matrix4 = Matrix4.identity(); + @Serializer.serialze() + get matrix(): Matrix4 { + return this._matrix; } - - protected setPropertyAndUpdate( - property: K, - newValue: this[K], - onPropertyChanged?: (property: K, oldValue: this[K]) => void, - equals?: IEqualityComparer, - ) { - if (this.setProperty(property, newValue, onPropertyChanged, equals)) { - this.shouldRegenerate = true; - this.emitShapeChanged(); - } - } - - protected emitShapeChanged() { - this.emitPropertyChanged("shape", this._shape); + set matrix(value: Matrix4) { + this.setProperty( + "matrix", + value, + (_p, oldMatrix) => { + this.onMatrixChanged(value, oldMatrix); + }, + { + equals: (left, right) => left.equals(right), + }, + ); } - protected abstract generateShape(): Result; + protected onMatrixChanged(newMatrix: Matrix4, oldMatrix: Matrix4): void {} } diff --git a/packages/chili-core/src/model/geometry.ts b/packages/chili-core/src/model/geometryEntity.ts similarity index 68% rename from packages/chili-core/src/model/geometry.ts rename to packages/chili-core/src/model/geometryEntity.ts index 67be2a43..43e2bfe7 100644 --- a/packages/chili-core/src/model/geometry.ts +++ b/packages/chili-core/src/model/geometryEntity.ts @@ -1,12 +1,14 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. import { IDocument } from "../document"; +import { IEqualityComparer, Result } from "../foundation"; import { Matrix4 } from "../math"; import { Property } from "../property"; import { Serializer } from "../serialize"; +import { IShape } from "../shape"; import { Entity } from "./entity"; -export abstract class GeometryObject extends Entity { +export abstract class GeometryEntity extends Entity { private _materialId: string; @Serializer.serialze() @Property.define("common.material", { type: "materialId" }) @@ -17,30 +19,48 @@ export abstract class GeometryObject extends Entity { this.setProperty("materialId", value); } - protected _matrix: Matrix4 = Matrix4.identity(); - @Serializer.serialze() - get matrix(): Matrix4 { - return this._matrix; + protected shouldRegenerate: boolean = true; + + protected _shape: Result = Result.err("Not initialised"); + get shape(): Result { + if (this.shouldRegenerate) { + this._shape = this.generateShape(); + if (this._shape.isOk) { + this._shape.value.matrix = this._matrix; + } + this.shouldRegenerate = false; + } + return this._shape; } - set matrix(value: Matrix4) { - this.setProperty( - "matrix", - value, - () => { - if (this.shape.isOk) { - this.shape.value.matrix = value; - } - }, - { - equals: (left, right) => left.equals(right), - }, - ); + + protected setPropertyAndUpdate( + property: K, + newValue: this[K], + onPropertyChanged?: (property: K, oldValue: this[K]) => void, + equals?: IEqualityComparer, + ) { + if (this.setProperty(property, newValue, onPropertyChanged, equals)) { + this.shouldRegenerate = true; + this.emitShapeChanged(); + } } constructor(document: IDocument, materialId?: string) { super(document); this._materialId = materialId ?? document.materials.at(0)!.id; } + + protected emitShapeChanged() { + this.emitPropertyChanged("shape", this._shape); + } + + override onMatrixChanged(newMatrix: Matrix4, oldMatrix: Matrix4): void { + if (this.shape.isOk) { + this.shape.value.matrix = newMatrix; + } + } + + protected abstract generateShape(): Result; } /* @@ -111,7 +131,7 @@ export abstract class HistoryBody extends Body { } */ -export abstract class FaceableGeometry extends GeometryObject { +export abstract class FaceableGeometry extends GeometryEntity { protected _isFace: boolean = false; @Serializer.serialze() @Property.define("command.faceable.isFace") diff --git a/packages/chili-core/src/model/index.ts b/packages/chili-core/src/model/index.ts index 46698152..562cc64a 100644 --- a/packages/chili-core/src/model/index.ts +++ b/packages/chili-core/src/model/index.ts @@ -2,7 +2,7 @@ export * from "./entity"; export * from "./feature"; -export * from "./geometry"; +export * from "./geometryEntity"; export * from "./model"; export * from "./node"; export * from "./nodeLinkedList"; diff --git a/packages/chili-core/src/model/model.ts b/packages/chili-core/src/model/model.ts index 9048f2d9..8770fb30 100644 --- a/packages/chili-core/src/model/model.ts +++ b/packages/chili-core/src/model/model.ts @@ -3,14 +3,14 @@ import { IDocument } from "../document"; import { Id } from "../foundation"; import { Serializer } from "../serialize"; -import { GeometryObject } from "./geometry"; +import { GeometryEntity } from "./geometryEntity"; import { IModel, IModelGroup, Node } from "./node"; export abstract class Model extends Node implements IModel { @Serializer.serialze() - readonly geometry: GeometryObject; + readonly geometry: GeometryEntity; - constructor(document: IDocument, name: string, body: GeometryObject, id: string = Id.generate()) { + constructor(document: IDocument, name: string, body: GeometryEntity, id: string = Id.generate()) { super(document, name, id); this.geometry = body; } @@ -18,7 +18,7 @@ export abstract class Model extends Node implements IModel { @Serializer.register("GeometryModel", ["document", "name", "geometry", "id"]) export class GeometryModel extends Model { - constructor(document: IDocument, name: string, geometry: GeometryObject, id: string = Id.generate()) { + constructor(document: IDocument, name: string, geometry: GeometryEntity, id: string = Id.generate()) { super(document, name, geometry, id); } diff --git a/packages/chili-core/src/model/node.ts b/packages/chili-core/src/model/node.ts index e53647ea..62f1a38d 100644 --- a/packages/chili-core/src/model/node.ts +++ b/packages/chili-core/src/model/node.ts @@ -4,7 +4,7 @@ import { IDocument } from "../document"; import { HistoryObservable, IDisposable, IPropertyChanged, Id } from "../foundation"; import { Property } from "../property"; import { Serialized, Serializer } from "../serialize"; -import { GeometryObject } from "./geometry"; +import { GeometryEntity } from "./geometryEntity"; export interface INode extends IPropertyChanged, IDisposable { readonly id: string; @@ -30,7 +30,7 @@ export interface INodeLinkedList extends INode { export interface IModel extends INode { readonly document: IDocument; - readonly geometry: GeometryObject; + readonly geometry: GeometryEntity; } export interface IModelGroup extends IModel { diff --git a/packages/chili-core/src/visual/visualShape.ts b/packages/chili-core/src/visual/visualShape.ts index 8d5e66c0..1bed6866 100644 --- a/packages/chili-core/src/visual/visualShape.ts +++ b/packages/chili-core/src/visual/visualShape.ts @@ -1,6 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject } from "../model"; +import { GeometryEntity } from "../model"; import { ShapeType } from "../shape"; import { IVisualObject } from "./visualObject"; @@ -31,7 +31,7 @@ export interface VisualGroup { } export interface IVisualGeometry extends IVisualObject { - get geometry(): GeometryObject; + get geometryEngity(): GeometryEntity; addState(state: VisualState, type: ShapeType, ...indexes: number[]): void; removeState(state: VisualState, type: ShapeType, ...indexes: number[]): void; resetState(): void; diff --git a/packages/chili-occ/src/occMesh.ts b/packages/chili-occ/src/occMesh.ts index 105b16f0..7dc5a0b6 100644 --- a/packages/chili-occ/src/occMesh.ts +++ b/packages/chili-occ/src/occMesh.ts @@ -7,7 +7,6 @@ import { FaceMeshDataBuilder, IShapeMeshData, MeshDataBuilder, - VertexMeshData, } from "chili-core"; import { Handle_Poly_Triangulation, @@ -16,7 +15,6 @@ import { TopAbs_ShapeEnum, TopoDS_Edge, TopoDS_Face, - TopoDS_Shape, gp_Trsf, } from "../occ-wasm/chili_occ"; @@ -25,17 +23,11 @@ import { OccShape } from "./occShape"; export class OccMesh implements IShapeMeshData { private maxDeviation: number = 8; - private _vertexs?: VertexMeshData; private _lines?: EdgeMeshData; private _faces?: FaceMeshData; - private constructor(readonly shape: OccShape) { - this._mesh(shape.shape); - } - - static create(shape: OccShape): IShapeMeshData { + constructor(readonly shape: OccShape) { new occ.BRepMesh_IncrementalMesh_2(shape.shape, 0.1, false, 0.1, false); - return new OccMesh(shape); } updateMeshShape(): void { @@ -43,36 +35,19 @@ export class OccMesh implements IShapeMeshData { this.updateFaceMeshShapes(); } - get vertexs(): VertexMeshData | undefined { - return this._vertexs; - } get edges(): EdgeMeshData | undefined { + if (!this._lines) this._lines = this.edgeMeshs(); return this._lines; } + get faces(): FaceMeshData | undefined { + if (!this._faces) this._faces = this.faceMeshs(); return this._faces; } - private _mesh(shape: TopoDS_Shape) { - let shapeType = shape.ShapeType(); - if (shapeType === occ.TopAbs_ShapeEnum.TopAbs_VERTEX) { - this.pointMesh(shape); - return; - } - if (shapeType !== occ.TopAbs_ShapeEnum.TopAbs_EDGE) { - this.faceMeshs(shape); - } - - this.edgeMeshs(shape); - } - - private pointMesh(shape: TopoDS_Shape) { - console.log("暂不支持"); - } - - private edgeMeshs(shape: TopoDS_Shape) { + private edgeMeshs() { let shapes = OccHelps.findSubShapes( - shape, + this.shape.shape, occ.TopAbs_ShapeEnum.TopAbs_EDGE as TopAbs_ShapeEnum, true, ); @@ -80,9 +55,11 @@ export class OccMesh implements IShapeMeshData { for (const e of shapes) { this.addEdgeMesh(e as TopoDS_Edge, builder); } - this._lines = builder.build(); - let matrix = OccHelps.convertToMatrix(shape.Location_1().Transformation()).invert()!; - this._lines.positions = matrix.ofPoints(this._lines.positions); + let lines = builder.build(); + if (lines.positions.length === 0) return undefined; + let matrix = OccHelps.convertToMatrix(this.shape.shape.Location_1().Transformation()).invert()!; + lines.positions = matrix.ofPoints(lines.positions); + return lines; } private updateEdgeMeshShapes() { @@ -117,9 +94,9 @@ export class OccMesh implements IShapeMeshData { builder.endGroup(OccHelps.wrapShape(edge)); } - private faceMeshs(shape: TopoDS_Shape) { + private faceMeshs() { let shapes = OccHelps.findSubShapes( - shape, + this.shape.shape, occ.TopAbs_ShapeEnum.TopAbs_FACE as TopAbs_ShapeEnum, true, ); @@ -127,10 +104,12 @@ export class OccMesh implements IShapeMeshData { for (const f of shapes) { this.addFaceMesh(f as TopoDS_Face, builder); } - this._faces = builder.build(); - let matrix = OccHelps.convertToMatrix(shape.Location_1().Transformation()).invert()!; - this._faces.positions = matrix.ofPoints(this._faces.positions); - this._faces.normals = matrix.ofVectors(this._faces.normals); + let faces = builder.build(); + if (faces.positions.length === 0) return undefined; + let matrix = OccHelps.convertToMatrix(this.shape.shape.Location_1().Transformation()).invert()!; + faces.positions = matrix.ofPoints(faces.positions); + faces.normals = matrix.ofVectors(faces.normals); + return faces; } private updateFaceMeshShapes() { diff --git a/packages/chili-occ/src/occShape.ts b/packages/chili-occ/src/occShape.ts index c01bb891..e460fa7e 100644 --- a/packages/chili-occ/src/occShape.ts +++ b/packages/chili-occ/src/occShape.ts @@ -56,7 +56,7 @@ export class OccShape implements IShape { private _mesh: IShapeMeshData | undefined; get mesh(): IShapeMeshData { if (this._mesh === undefined) { - this._mesh = OccMesh.create(this); + this._mesh = new OccMesh(this); } return this._mesh; } diff --git a/packages/chili-three/src/threeGeometry.ts b/packages/chili-three/src/threeGeometry.ts index 7fa9e472..c06e308b 100644 --- a/packages/chili-three/src/threeGeometry.ts +++ b/packages/chili-three/src/threeGeometry.ts @@ -3,7 +3,7 @@ import { EdgeMeshData, FaceMeshData, - GeometryObject, + GeometryEntity, IHighlighter, IVisualGeometry, Matrix4, @@ -92,39 +92,54 @@ export class ThreeGeometry extends Object3D implements IVisualGeometry { } constructor( - readonly geometry: GeometryObject, + readonly geometryEngity: GeometryEntity, readonly highlighter: IHighlighter, readonly context: ThreeVisualContext, ) { super(); - let mesh = this.geometry.shape.value?.mesh; - this.transform = geometry.matrix; - this._faceMaterial = context.getMaterial(geometry.materialId); + this.transform = geometryEngity.matrix; + this._faceMaterial = context.getMaterial(geometryEngity.materialId); this.matrixAutoUpdate = false; - if (mesh?.faces?.positions.length) this.add(this.initFaces(mesh.faces)); - if (mesh?.edges?.positions.length) this.add(this.initEdges(mesh.edges)); - geometry.onPropertyChanged(this.handleGeometryPropertyChanged); + this.generateShape(); + geometryEngity.onPropertyChanged(this.handleGeometryPropertyChanged); } - private handleGeometryPropertyChanged = (property: keyof GeometryObject) => { + private handleGeometryPropertyChanged = (property: keyof GeometryEntity) => { if (property === "matrix") { - this.transform = this.geometry.matrix; + this.transform = this.geometryEngity.matrix; } else if (property === "materialId") { - let material = this.context.getMaterial(this.geometry.materialId)!; + let material = this.context.getMaterial(this.geometryEngity.materialId)!; this.setFaceMaterial(material); + } else if (property === "shape") { + this.removeSubShapes(); + this.generateShape(); } }; + private generateShape() { + let mesh = this.geometryEngity.shape.value?.mesh; + if (mesh?.faces?.positions.length) this.add(this.initFaces(mesh.faces)); + if (mesh?.edges?.positions.length) this.add(this.initEdges(mesh.edges)); + } + dispose() { + this.removeSubShapes(); + this.geometryEngity.removePropertyChanged(this.handleGeometryPropertyChanged); + this._edgeMaterial.dispose(); + this.resetState(); + } + + private removeSubShapes() { if (this._edges) { + this.remove(this._edges); this._edges.geometry.dispose(); + this._edges = undefined; } if (this._faces) { + this.remove(this._faces); this._faces.geometry.dispose(); + this._faces = undefined; } - this.geometry.removePropertyChanged(this.handleGeometryPropertyChanged); - this._edgeMaterial.dispose(); - this.resetState(); } private initEdges(data: EdgeMeshData) { @@ -268,7 +283,7 @@ export class ThreeGeometry extends Object3D implements IVisualGeometry { private cloneSubEdge(index: number, material: LineBasicMaterial) { let allPositions = this._edges!.geometry.getAttribute("position") as Float32BufferAttribute; - let group = this.geometry.shape.value!.mesh.edges!.groups[index]; + let group = this.geometryEngity.shape.value!.mesh.edges!.groups[index]; let positions = allPositions.array.slice(group.start * 3, (group.start + group.count) * 3); let buff = new BufferGeometry(); buff.setAttribute("position", new Float32BufferAttribute(positions, 3)); @@ -300,11 +315,11 @@ export class ThreeGeometry extends Object3D implements IVisualGeometry { } private cloneSubFace(index: number, material: MeshLambertMaterial) { - let group = this.geometry.shape.value?.mesh.faces!.groups[index]; + let group = this.geometryEngity.shape.value?.mesh.faces!.groups[index]; if (!group) return undefined; let allPositions = this._faces!.geometry.getAttribute("position") as Float32BufferAttribute; let allNormals = this._faces!.geometry.getAttribute("normal") as Float32BufferAttribute; - let allIndices = this.geometry.shape.value!.mesh.faces!.indices; + let allIndices = this.geometryEngity.shape.value!.mesh.faces!.indices; let indices = allIndices.slice(group.start, group.start + group.count); let indiceStart = Math.min(...indices); let indiceEnd = Math.max(...indices) + 1; diff --git a/packages/chili-three/src/threeView.ts b/packages/chili-three/src/threeView.ts index 4da9ad2a..55a514d1 100644 --- a/packages/chili-three/src/threeView.ts +++ b/packages/chili-three/src/threeView.ts @@ -49,7 +49,7 @@ export class ThreeView extends Observable implements IView { private _needsUpdate: boolean = false; private readonly _gizmo: ViewGizmo; readonly cameraController: CameraController; - readonly dynamicLight = new DirectionalLight(0xffffff, 1.5); + readonly dynamicLight = new DirectionalLight(0xffffff, 2); private _name: string; get name(): string { @@ -274,9 +274,9 @@ export class ThreeView extends Observable implements IView { ) { if (!(shape.parent instanceof ThreeGeometry) || !shape.parent.visible) return; if (shapeType === ShapeType.Shape && shape instanceof LineSegments) { - if (shapeFilter && !shapeFilter.allow(shape.parent.geometry.shape.value!)) return; + if (shapeFilter && !shapeFilter.allow(shape.parent.geometryEngity.shape.value!)) return; detecteds.push({ - shape: shape.parent.geometry.shape.value!, + shape: shape.parent.geometryEngity.shape.value!, owner: shape.parent, indexes: [], }); @@ -296,13 +296,13 @@ export class ThreeView extends Observable implements IView { const parent = element.object.parent; if ( !(parent instanceof ThreeGeometry) || - (shapeFilter && !shapeFilter.allow(parent.geometry.shape.value!)) + (shapeFilter && !shapeFilter.allow(parent.geometryEngity.shape.value!)) ) { continue; } result.push({ owner: parent, - shape: parent.geometry.shape.value!, + shape: parent.geometryEngity.shape.value!, indexes: [], }); } @@ -351,7 +351,7 @@ export class ThreeView extends Observable implements IView { } private getWireAndIndexes(shape: IShape, groups: ShapeMeshGroup[], parent: ThreeGeometry) { - let wire = shape.findAncestor(ShapeType.Wire, parent.geometry.shape.value!).at(0); + let wire = shape.findAncestor(ShapeType.Wire, parent.geometryEngity.shape.value!).at(0); let indexes: number[] = []; if (wire) { let edges = wire.findSubShapes(ShapeType.Edge, true); @@ -371,13 +371,13 @@ export class ThreeView extends Observable implements IView { let index: number | undefined = undefined; let groups: ShapeMeshGroup[] | undefined = undefined; if (element.faceIndex !== null) { - groups = parent.geometry.shape.value?.mesh.faces?.groups; + groups = parent.geometryEngity.shape.value?.mesh.faces?.groups; if (groups) { index = ThreeHelper.findGroupIndex(groups, element.faceIndex! * 3)!; shape = groups[index].shape; } } else if (element.index !== null) { - groups = parent.geometry.shape.value?.mesh.edges?.groups; + groups = parent.geometryEngity.shape.value?.mesh.edges?.groups; if (groups) { index = ThreeHelper.findGroupIndex(groups, element.index!)!; shape = groups[index].shape; diff --git a/packages/chili-three/src/threeVisual.ts b/packages/chili-three/src/threeVisual.ts index e15fd679..da186aa2 100644 --- a/packages/chili-three/src/threeVisual.ts +++ b/packages/chili-three/src/threeVisual.ts @@ -53,10 +53,9 @@ export class ThreeVisual implements IVisual { initScene() { let scene = new Scene(); scene.background = new Color(0x888888); - const light = new DirectionalLight(0xffffff, 0.5); - let envLight = new AmbientLight(0x888888, 4); + let envLight = new AmbientLight(0x888888, 5); let axisHelper = new AxesHelper(250); - scene.add(light, envLight, axisHelper); + scene.add(envLight, axisHelper); return scene; } diff --git a/packages/chili-three/src/threeVisualContext.ts b/packages/chili-three/src/threeVisualContext.ts index 0cb1b8e6..5e70e312 100644 --- a/packages/chili-three/src/threeVisualContext.ts +++ b/packages/chili-three/src/threeVisualContext.ts @@ -64,11 +64,7 @@ export class ThreeVisualContext implements IVisualContext { transparent: true, name: item.name, }); - if (item.texture) { - material.map = new TextureLoader().load(item.texture); - material.map.wrapS = RepeatWrapping; - material.map.wrapT = RepeatWrapping; - } + material.map = this.loadTexture(item); item.onPropertyChanged(this.onMaterialPropertyChanged); this.materialMap.set(item.id, material); }); @@ -82,6 +78,19 @@ export class ThreeVisualContext implements IVisualContext { } }; + private loadTexture(item: Material) { + if (!item.texture) { + return null; + } + + let map = new TextureLoader().load(item.texture); + map.wrapS = RepeatWrapping; + map.wrapT = RepeatWrapping; + map.repeat.set(item.repeatU, item.repeatV); + map.rotation = MathUtils.degToRad(item.angle); + return map; + } + getMaterial(id: string): ThreeMaterial { let material = this.materialMap.get(id); if (!material) { @@ -96,7 +105,7 @@ export class ThreeVisualContext implements IVisualContext { if (prop === "color") { material.color.set(source.color); } else if (prop === "texture") { - material.map = source.texture ? new TextureLoader().load(source.texture) : null; + material.map = this.loadTexture(source); } else if (prop === "opacity") { material.opacity = source.opacity; } else if (prop === "name") { diff --git a/packages/chili-three/test/testEdge.ts b/packages/chili-three/test/testEdge.ts index cae1dc14..2c18eb44 100644 --- a/packages/chili-three/test/testEdge.ts +++ b/packages/chili-three/test/testEdge.ts @@ -1,5 +1,5 @@ import { - GeometryObject, + GeometryEntity, I18nKeys, ICurve, IDocument, @@ -80,7 +80,7 @@ export class TestEdge implements IEdge { } } -export class TestBody extends GeometryObject { +export class TestBody extends GeometryEntity { display: I18nKeys = "body.line"; constructor( document: IDocument, diff --git a/packages/chili-three/test/three.test.ts b/packages/chili-three/test/three.test.ts index f81d5e45..3e105171 100644 --- a/packages/chili-three/test/three.test.ts +++ b/packages/chili-three/test/three.test.ts @@ -36,7 +36,7 @@ describe("three test", () => { expect(shapes[0].shape.shapeType).toBe(ShapeType.Edge); let shape = context.getShape(model); - expect(shapes.at(0)?.shape).toEqual(shape?.geometry.shape.value); + expect(shapes.at(0)?.shape).toEqual(shape?.geometryEngity.shape.value); expect(context.getModel(shape!)).toEqual(model); context.removeModel([model]); diff --git a/packages/chili-ui/src/property/materialProperty.ts b/packages/chili-ui/src/property/materialProperty.ts index 516fea29..cd485d1b 100644 --- a/packages/chili-ui/src/property/materialProperty.ts +++ b/packages/chili-ui/src/property/materialProperty.ts @@ -1,6 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, IDocument, Material, Property, PubSub, Transaction } from "chili-core"; +import { GeometryEntity, IDocument, Material, Property, PubSub, Transaction } from "chili-core"; import { button, div, localize, span } from "../controls"; import style from "./materialProperty.module.css"; import { PropertyBase } from "./propertyBase"; @@ -8,7 +8,7 @@ import { PropertyBase } from "./propertyBase"; export class MaterialProperty extends PropertyBase { constructor( readonly document: IDocument, - objects: GeometryObject[], + objects: GeometryEntity[], readonly property: Property, ) { super(objects); diff --git a/packages/chili-ui/src/property/propertyView.ts b/packages/chili-ui/src/property/propertyView.ts index 9c00f1a2..167b19fc 100644 --- a/packages/chili-ui/src/property/propertyView.ts +++ b/packages/chili-ui/src/property/propertyView.ts @@ -1,8 +1,8 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. import { + GeometryEntity, GeometryModel, - GeometryObject, I18nKeys, IConverter, IDocument, @@ -69,25 +69,44 @@ export class PropertyView extends HTMLElement { private addGeometry(nodes: INode[], document: IDocument) { let geometries = nodes.filter((x) => INode.isModelNode(x)).map((x) => (x as GeometryModel).geometry); if (geometries.length === 0 || !this.isAllElementsOfTypeFirstElement(geometries)) return; - this.addCommon(document, geometries); + this.addGeneral(document, geometries); + this.addTransform(document, geometries); this.addParameters(geometries, document); } - private addCommon(document: IDocument, geometries: GeometryObject[]) { + private addGeneral(document: IDocument, geometries: GeometryEntity[]) { let common = new Expander("common.general"); this.panel.append(common); common.classList.add(style.expander); - Property.getOwnProperties(GeometryObject.prototype).forEach((x) => { + Property.getOwnProperties(GeometryEntity.prototype).forEach((x) => { appendProperty(common.contenxtPanel, document, geometries, x); }); - this.addTransform(common, document, geometries); } - private addParameters(geometries: GeometryObject[], document: IDocument) { + private addTransform(document: IDocument, geometries: GeometryEntity[]) { + let matrix = new Expander("common.matrix"); + this.panel.append(matrix); + matrix.classList.add(style.expander); + + const addMatrix = (display: I18nKeys, converter: IConverter) => { + appendProperty(matrix, document, geometries, { + name: "matrix", + display: display, + converter, + }); + }; + // 这部分代码有问题,待完善 + let converters = MatrixConverter.init(); + addMatrix("transform.translation", converters.translation); + addMatrix("transform.scale", converters.scale); + addMatrix("transform.rotation", converters.rotate); + } + + private addParameters(geometries: GeometryEntity[], document: IDocument) { let parameters = new Expander(geometries[0].display); this.panel.append(parameters); parameters.classList.add(style.expander); - Property.getProperties(Object.getPrototypeOf(geometries[0]), GeometryObject.prototype).forEach( + Property.getProperties(Object.getPrototypeOf(geometries[0]), GeometryEntity.prototype).forEach( (x) => { appendProperty(parameters.contenxtPanel, document, geometries, x); }, @@ -106,21 +125,6 @@ export class PropertyView extends HTMLElement { } return true; } - - private addTransform(dom: HTMLElement, document: IDocument, geometries: GeometryObject[]) { - const addMatrix = (display: I18nKeys, converter: IConverter) => { - appendProperty(dom, document, geometries, { - name: "matrix", - display: display, - converter, - }); - }; - // 这部分代码有问题,待完善 - let converters = MatrixConverter.init(); - addMatrix("transform.translation", converters.translation); - addMatrix("transform.scale", converters.scale); - addMatrix("transform.rotation", converters.rotate); - } } customElements.define("chili-property-view", PropertyView); diff --git a/packages/chili/src/bodys/arcBody.ts b/packages/chili/src/bodys/arcBody.ts index 3afb4ddd..91e07c83 100644 --- a/packages/chili/src/bodys/arcBody.ts +++ b/packages/chili/src/bodys/arcBody.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IShape, Property, Result, Serializer, XYZ } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IShape, Property, Result, Serializer, XYZ } from "chili-core"; @Serializer.register("ArcBody", ["document", "normal", "center", "start", "angle"]) -export class ArcBody extends GeometryObject { +export class ArcBody extends GeometryEntity { readonly display: I18nKeys = "body.arc"; private _center: XYZ; diff --git a/packages/chili/src/bodys/boolean.ts b/packages/chili/src/bodys/boolean.ts index 3afa8f22..0741dcab 100644 --- a/packages/chili/src/bodys/boolean.ts +++ b/packages/chili/src/bodys/boolean.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IShape, Result, Serializer } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IShape, Result, Serializer } from "chili-core"; @Serializer.register("BooleanBody", ["document", "booleanShape"]) -export class BooleanBody extends GeometryObject { +export class BooleanBody extends GeometryEntity { override display: I18nKeys = "body.bolean"; private _booleanShape: IShape; diff --git a/packages/chili/src/bodys/box.ts b/packages/chili/src/bodys/box.ts index 8aac1cbc..8222f444 100644 --- a/packages/chili/src/bodys/box.ts +++ b/packages/chili/src/bodys/box.ts @@ -1,7 +1,7 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. import { - GeometryObject, + GeometryEntity, I18nKeys, IDocument, IShape, @@ -12,7 +12,7 @@ import { } from "chili-core"; @Serializer.register("BoxBody", ["document", "plane", "dx", "dy", "dz"]) -export class BoxBody extends GeometryObject { +export class BoxBody extends GeometryEntity { readonly display: I18nKeys = "body.box"; private _dx: number; diff --git a/packages/chili/src/bodys/face.ts b/packages/chili/src/bodys/face.ts index 3e253af4..998679e7 100644 --- a/packages/chili/src/bodys/face.ts +++ b/packages/chili/src/bodys/face.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IEdge, IShape, IWire, Result, Serializer } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IEdge, IShape, IWire, Result, Serializer } from "chili-core"; @Serializer.register("FaceBody", ["document", "shapes"]) -export class FaceBody extends GeometryObject { +export class FaceBody extends GeometryEntity { override display: I18nKeys = "body.face"; private _shapes: IEdge[] | IWire; diff --git a/packages/chili/src/bodys/fuse.ts b/packages/chili/src/bodys/fuse.ts index 2a530354..c06120fd 100644 --- a/packages/chili/src/bodys/fuse.ts +++ b/packages/chili/src/bodys/fuse.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IShape, Result, Serializer } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IShape, Result, Serializer } from "chili-core"; @Serializer.register("FuseBody", ["document", "bottom", "top"]) -export class FuseBody extends GeometryObject { +export class FuseBody extends GeometryEntity { override display: I18nKeys = "body.fuse"; private _bottom: IShape; diff --git a/packages/chili/src/bodys/importer.ts b/packages/chili/src/bodys/importer.ts index 5699aab1..acee740c 100644 --- a/packages/chili/src/bodys/importer.ts +++ b/packages/chili/src/bodys/importer.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IShape, Result, Serializer } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IShape, Result, Serializer } from "chili-core"; @Serializer.register("ImportedBody", ["document", "importedShape"]) -export class ImportedBody extends GeometryObject { +export class ImportedBody extends GeometryEntity { override display: I18nKeys = "body.imported"; private _importedShape: IShape; diff --git a/packages/chili/src/bodys/line.ts b/packages/chili/src/bodys/line.ts index 48fd0e5a..eaceef3d 100644 --- a/packages/chili/src/bodys/line.ts +++ b/packages/chili/src/bodys/line.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IShape, Property, Result, Serializer, XYZ } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IShape, Property, Result, Serializer, XYZ } from "chili-core"; @Serializer.register("LineBody", ["document", "start", "end"]) -export class LineBody extends GeometryObject { +export class LineBody extends GeometryEntity { readonly display: I18nKeys = "body.line"; private _start: XYZ; diff --git a/packages/chili/src/bodys/prism.ts b/packages/chili/src/bodys/prism.ts index 92d85518..0ed5813b 100644 --- a/packages/chili/src/bodys/prism.ts +++ b/packages/chili/src/bodys/prism.ts @@ -1,7 +1,7 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. import { - GeometryObject, + GeometryEntity, I18nKeys, IDocument, IFace, @@ -12,7 +12,7 @@ import { } from "chili-core"; @Serializer.register("PrismBody", ["document", "face", "length"]) -export class PrismBody extends GeometryObject { +export class PrismBody extends GeometryEntity { override display: I18nKeys = "body.prism"; private _face: IFace; diff --git a/packages/chili/src/bodys/revolve.ts b/packages/chili/src/bodys/revolve.ts index 36c8468f..b3dd7a12 100644 --- a/packages/chili/src/bodys/revolve.ts +++ b/packages/chili/src/bodys/revolve.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IShape, Ray, Result, Serializer } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IShape, Ray, Result, Serializer } from "chili-core"; @Serializer.register("RevolveBody", ["document", "profile", "axis", "angle"]) -export class RevolveBody extends GeometryObject { +export class RevolveBody extends GeometryEntity { override display: I18nKeys = "body.revol"; private _profile: IShape; diff --git a/packages/chili/src/bodys/sweep.ts b/packages/chili/src/bodys/sweep.ts index f12bdbb9..e378ee41 100644 --- a/packages/chili/src/bodys/sweep.ts +++ b/packages/chili/src/bodys/sweep.ts @@ -1,7 +1,7 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. import { - GeometryObject, + GeometryEntity, I18nKeys, IDocument, IEdge, @@ -13,7 +13,7 @@ import { } from "chili-core"; @Serializer.register("SweepBody", ["document", "profile", "path"]) -export class SweepBody extends GeometryObject { +export class SweepBody extends GeometryEntity { override display: I18nKeys = "body.sweep"; private _profile: IShape; diff --git a/packages/chili/src/bodys/wire.ts b/packages/chili/src/bodys/wire.ts index 5ac3acfc..3c7684d3 100644 --- a/packages/chili/src/bodys/wire.ts +++ b/packages/chili/src/bodys/wire.ts @@ -1,9 +1,9 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { GeometryObject, I18nKeys, IDocument, IEdge, IShape, Result, Serializer } from "chili-core"; +import { GeometryEntity, I18nKeys, IDocument, IEdge, IShape, Result, Serializer } from "chili-core"; @Serializer.register("WireBody", ["document", "edges"]) -export class WireBody extends GeometryObject { +export class WireBody extends GeometryEntity { override display: I18nKeys = "body.wire"; private _edges: IEdge[];