diff --git a/src/Add-on/DrawRegion.ts b/src/Add-on/DrawRegion.ts index c263fd4df..b8ac5618b 100644 --- a/src/Add-on/DrawRegion.ts +++ b/src/Add-on/DrawRegion.ts @@ -4,6 +4,7 @@ import { Curve } from '../DatabaseServices/Curve'; import { Ellipse } from '../DatabaseServices/Ellipse'; import { Region } from '../DatabaseServices/Region'; import { Command } from '../Editor/CommandMachine'; +import { PromptStatus } from '../Editor/PromptResult'; import { SelectSet } from '../Editor/SelectSet'; import { RegionParse, Route } from '../Geometry/RegionParse'; @@ -11,6 +12,15 @@ export class DrawRegion implements Command { async exec(ss: SelectSet) { + if (ss.SelectEntityList.length === 0) + { + let ssRes = await app.m_Editor.GetSelection(); + if (ssRes.Status !== PromptStatus.OK) + return; + + ss = ssRes.SelectSet; + } + let lines: Curve[] = []; for (let en of ss.SelectEntityList) diff --git a/src/Add-on/TestDrawBoard.ts b/src/Add-on/TestDrawBoard.ts new file mode 100644 index 000000000..0bfc4b054 --- /dev/null +++ b/src/Add-on/TestDrawBoard.ts @@ -0,0 +1,14 @@ +import { Command } from "../Editor/CommandMachine"; +import { Board } from "../DatabaseServices/Board"; +import { app } from "../ApplicationServices/Application"; + + +export class Command_DrawBoard2 implements Command +{ + async exec() + { + let br = new Board(); + br.InitBoard(1.200, 0.600, 0.018); + app.m_Database.ModelSpace.Append(br); + } +} diff --git a/src/DatabaseServices/Arc.ts b/src/DatabaseServices/Arc.ts index 5fd84d5ef..7cb9d0360 100644 --- a/src/DatabaseServices/Arc.ts +++ b/src/DatabaseServices/Arc.ts @@ -29,6 +29,7 @@ export class Arc extends Curve private m_StartAngle: number; private m_EndAngle: number; private m_Normal = new Vector3(0, 0, 1); + private m_Clockwise = true;//顺时针 get Center() { @@ -82,6 +83,11 @@ export class Arc extends Curve this.Update(); } + get IsClockWise() + { + return this.m_Clockwise; + } + get StartAngle() { return this.m_StartAngle; @@ -283,8 +289,15 @@ export class Arc extends Curve this.SetExtendPointAngle(newParam, allAngle); } } + } + Reverse() + { + this.WriteAllObjectRecord(); + this.m_Clockwise = !this.m_Clockwise; + [this.m_StartAngle, this.m_EndAngle] = [this.m_EndAngle, this.m_StartAngle]; } + IntersectWith(curve: Curve, intType: Intersect): Vector3[] { if (curve instanceof Arc) @@ -407,8 +420,9 @@ export class Arc extends Curve if (obj) return obj; let shape = new THREE.Shape(); - shape.absarc(this.m_Center.x, this.m_Center.y, this.m_Radius, this.m_StartAngle, this.m_EndAngle, true); + shape.absarc(this.m_Center.x, this.m_Center.y, this.m_Radius, this.m_StartAngle, this.m_EndAngle, this.m_Clockwise); let geo = new THREE.Geometry().setFromPoints(shape.getPoints(60)); + geo.computeBoundingSphere(); let arc = new THREE.Line(geo, ColorMaterial.GetLineMaterial(this.m_Color)); this.m_DrawEntity.set(renderType, arc); arc.userData = this; @@ -425,6 +439,7 @@ export class Arc extends Curve //圆心x,圆心y,半径,起点角度,端点角度,时针方向 shape.absarc(this.m_Center.x, this.m_Center.y, this.m_Radius, this.m_StartAngle, this.m_EndAngle, true); geo.setFromPoints(shape.getPoints(60)); + geo.computeBoundingSphere(); geo.verticesNeedUpdate = true; } @@ -494,7 +509,7 @@ export class Arc extends Curve this.m_Radius = file.Read(); this.m_StartAngle = file.Read(); this.m_EndAngle = file.Read(); - + this.m_Clockwise = file.Read(); } //对象将自身数据写入到文件. WriteFile(file: CADFile) @@ -506,6 +521,7 @@ export class Arc extends Curve file.Write(this.m_Radius); file.Write(this.m_StartAngle); file.Write(this.m_EndAngle); + file.Write(this.m_Clockwise); } //#endregion } diff --git a/src/DatabaseServices/Board.ts b/src/DatabaseServices/Board.ts new file mode 100644 index 000000000..7df17da41 --- /dev/null +++ b/src/DatabaseServices/Board.ts @@ -0,0 +1,174 @@ +import { ExtrudeGeometry, Matrix4, Mesh, Object3D, Vector3 } from 'three'; + +import { CoordinateSystem } from '../Geometry/CoordinateSystem'; +import { RenderType } from '../GraphicsSystem/Enum'; +import { Factory } from './CADFactory'; +import { CADFile } from './CADFile'; +import { CADObject } from './CADObject'; +import { Entity } from './Entity'; +import { Line } from './Line'; +import { DbPhysicalMaterial } from './PhysicalMaterial'; +import { Region } from './Region'; + + +/** + * 板件实体 + * + * @class Board + * @extends {Entity} + */ +@Factory +export class Board extends Entity +{ + //板件厚度 + private m_Height: number = 18; + private m_Region: Region; + + //自身坐标系 + private m_Matrix: Matrix4 = new Matrix4();//标准的世界坐标系 + constructor(reg?: Region, height?: number) + { + super(); + + this.m_Region = reg; + this.m_Height = height || this.m_Height; + } + + //初始化板件 来自长宽高 + InitBoard(length: number, width: number, height: number) + { + this.m_Height = height; + let px1 = new Vector3(0, 0, 0); + let px3 = new Vector3(length, width, 0); + let px2 = new Vector3(px3.x, px1.y); + let px4 = new Vector3(px1.x, px3.y); + + let l1 = new Line(); + let l2 = new Line(); + let l3 = new Line(); + let l4 = new Line(); + + l1.StartPoint = px1; + l1.EndPoint = px2; + + l2.StartPoint = px2; + l2.EndPoint = px3; + + l3.StartPoint = px3; + l3.EndPoint = px4; + + l4.StartPoint = px1; + l4.EndPoint = px4; + + this.m_Region = new Region([l1, l2, l3, l4]); + + this.Update(); + } + + ApplyMatrix(m: Matrix4) + { + this.WriteAllObjectRecord(); + let coor = new CoordinateSystem(); + coor.copyForm(this.m_Matrix); + coor.applyMatrix4(m); + + this.m_Matrix.copy(coor.getMatrix4()); + + this.Update(); + } + + Draw(renderType: RenderType): Object3D + { + let obj = super.Draw(renderType); + if (obj) return obj; + + if (!this.m_Region) + { + //避免空的板件生成 + this.InitBoard(1e-5, 1e-5, 1e-5); + } + + let extrudeSettings = { + steps: 1, + bevelEnabled: false, + amount: this.m_Height + }; + let extGeo = new ExtrudeGeometry(this.m_Region.Shape, extrudeSettings); + let mesh = new Mesh(extGeo); + mesh.userData = this; + + if (this.m_MaterialId && this.m_MaterialId.Object) + { + let material = this.m_MaterialId.Object as DbPhysicalMaterial; + mesh.material = material.Material; + } + + this.m_DrawEntity.set(renderType, mesh); + + this.Update(); + + return mesh; + } + + Update() + { + super.Update(); + for (let [, obj] of this.m_DrawEntity) + { + let mesh = obj as Mesh; + mesh.geometry.dispose(); + + let extrudeSettings = { + steps: 1, + bevelEnabled: false, + amount: this.m_Height + }; + mesh.geometry = new ExtrudeGeometry(this.m_Region.Shape, extrudeSettings); + mesh.geometry.computeBoundingSphere(); + + if (this.m_MaterialId) + { + let material = this.m_MaterialId.Object as DbPhysicalMaterial; + mesh.material = material.Material; + } + for (let [, obj] of this.m_DrawEntity) + { + let mesh = obj as Mesh; + + let p = new Vector3().setFromMatrixColumn(this.m_Matrix, 3); + obj.position.copy(p); + obj.quaternion.setFromRotationMatrix(this.m_Matrix); + } + } + } + + + //#region -------------------------File------------------------- + //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 + + //对象从文件中读取数据,初始化自身 + ReadFile(file: CADFile) + { + super.ReadFile(file); + let ver = file.Read(); + this.m_Region = file.ReadObject(this._db) as Region; + this.m_Height = file.Read(); + this.m_Matrix.fromArray(file.Read()) + this.Update(); + } + //对象将自身数据写入到文件. + WriteFile(file: CADFile) + { + super.WriteFile(file); + file.Write(1); + file.WriteObject(this.m_Region); + file.Write(this.m_Height); + file.Write(this.m_Matrix.toArray()) + } + //局部撤销 + ApplyPartialUndo(undoData: CADObject) + { + super.ApplyPartialUndo(undoData); + } + //#endregion +} diff --git a/src/DatabaseServices/Curve.ts b/src/DatabaseServices/Curve.ts index 755647f89..73f7b2807 100644 --- a/src/DatabaseServices/Curve.ts +++ b/src/DatabaseServices/Curve.ts @@ -62,6 +62,9 @@ export abstract class Curve extends Entity GetSplitCurves(param: number[] | number): Array { return; } Extend(newParam: number) { } + //翻转曲线.首尾调换. + Reverse() { }; + PtOnCurve(pt: Vector3): boolean { return; } GetOffsetCurves(offsetDist: number): Array { return; } diff --git a/src/DatabaseServices/Database.ts b/src/DatabaseServices/Database.ts index 333d327c5..dd2451b65 100644 --- a/src/DatabaseServices/Database.ts +++ b/src/DatabaseServices/Database.ts @@ -63,11 +63,10 @@ export class Database file.ReadObject(this, this.MaterialDict); file.ReadObject(this, this.TextureTableCol); - //TODO: 在对象关联情况下.更新可能出现 引用的问题. - this.MaterialDict.objectCol.forEach(m => + for (let mat of this.MaterialDict.objectCol) { - m.Update(); - }) + mat.Update(); + } this.hm.ReadFile(file); } @@ -107,4 +106,4 @@ export class Database console.warn("警告:尝试加入已经存在的id!"); this.idMap.set(index, id); } -} \ No newline at end of file +} diff --git a/src/DatabaseServices/Entity.ts b/src/DatabaseServices/Entity.ts index ad29d5f9f..4081bb0f9 100644 --- a/src/DatabaseServices/Entity.ts +++ b/src/DatabaseServices/Entity.ts @@ -1,4 +1,3 @@ -//所有图元的基类 import * as THREE from 'three'; import { Matrix4, Vector3, Mesh, Box3 } from 'three'; @@ -9,6 +8,14 @@ import { CADFile } from './CADFile'; import { CADObject } from './CADObject'; import { ObjectId } from './ObjectId'; + +/** + * Entity 是所有图元的基类,绘制的实体都集成该类. + * + * @export + * @class Entity + * @extends {CADObject} + */ @Factory export class Entity extends CADObject { @@ -17,6 +24,12 @@ export class Entity extends CADObject protected m_MaterialId: ObjectId; protected m_Color: number = 7; + set Material(material: ObjectId) + { + this.m_MaterialId = material; + this.Update(); + } + set ColorIndex(v: number) { this.m_Color = v; @@ -39,8 +52,15 @@ export class Entity extends CADObject return new Box3(); } - - //绘制一个threeJs对象. + /** + * 当实体加入到模型空间时,程序会调用该函数,来绘制实体. + * + * 实体绘制你必须调用`computeBoundingSphere` 来重新计算实体的包围盒,否则实体无法被选中. + * + * @param {RenderType} [renderType=RenderType.Wireframe] + * @returns {THREE.Object3D} + * @memberof Entity + */ Draw(renderType: RenderType = RenderType.Wireframe): THREE.Object3D { if (this.m_DrawEntity && this.m_DrawEntity.has(renderType)) @@ -49,7 +69,13 @@ export class Entity extends CADObject } } - //你必须重载该方法来更新绘制,在撤销重做时会自动调用该方法. + /** + * 当实体数据改变时,绘制的实体必须做出改变,你必须重载该方法,并且调用基类的方法实现实体更新. + * + * 实体更新后你必须调用`computeBoundingSphere` 来重新计算实体的包围盒,否则实体无法被选中. + * + * @memberof Entity + */ Update() { this.UpdateVisible(); @@ -114,6 +140,7 @@ export class Entity extends CADObject let ver = file.Read(); super.ReadFile(file); this.m_Color = file.Read(); + this.m_MaterialId = this.ReadObjectId(file); this.Update(); } //对象将自身数据写入到文件. @@ -122,6 +149,7 @@ export class Entity extends CADObject file.Write(1); super.WriteFile(file); file.Write(this.m_Color); + this.WriteObjectId(file, this.m_MaterialId); } //局部撤销 ApplyPartialUndo(undoData: CADObject) diff --git a/src/DatabaseServices/Line.ts b/src/DatabaseServices/Line.ts index c8fbb4f4a..983164571 100644 --- a/src/DatabaseServices/Line.ts +++ b/src/DatabaseServices/Line.ts @@ -14,13 +14,13 @@ import { Curve } from './Curve'; @Factory export class Line extends Curve { - private startPoint: Vector3; - private endPoint: Vector3; + private m_StartPoint: Vector3; + private m_EndPoint: Vector3; constructor(sp?: Vector3, ep?: Vector3) { super(); - this.startPoint = sp || new Vector3(0, 0, 0); - this.endPoint = ep || new Vector3(0, 0, 0); + this.m_StartPoint = sp || new Vector3(0, 0, 0); + this.m_EndPoint = ep || new Vector3(0, 0, 0); } Draw(renderType: RenderType): Object3D @@ -47,8 +47,8 @@ export class Line extends Curve let geo = lineObj.geometry as THREE.Geometry; - geo.vertices[0].copy(this.startPoint); - geo.vertices[1].copy(this.endPoint); + geo.vertices[0].copy(this.m_StartPoint); + geo.vertices[1].copy(this.m_EndPoint); geo.computeBoundingSphere();//必须调用该函数,使得实体可以被选中. @@ -83,8 +83,8 @@ export class Line extends Curve ApplyMatrix(m: Matrix4) { - this.startPoint.applyMatrix4(m); - this.endPoint.applyMatrix4(m); + this.m_StartPoint.applyMatrix4(m); + this.m_EndPoint.applyMatrix4(m); this.Update(); } @@ -112,7 +112,7 @@ export class Line extends Curve let len = this.Length; if (len == 0) { - if (equal(this.startPoint, pt)) + if (equal(this.m_StartPoint, pt)) return 0; else return NaN; @@ -218,6 +218,12 @@ export class Line extends Curve } } + Reverse() + { + this.WriteAllObjectRecord(); + [this.m_StartPoint, this.m_EndPoint] = [this.m_EndPoint, this.m_StartPoint]; + } + GetOffsetCurves(offsetDist: number): Array { let an = this.GetFistDerivAngle(0) - Math.PI * 0.5; @@ -236,7 +242,7 @@ export class Line extends Curve return 1; } //属性 - get Length(): number { return this.startPoint.distanceTo(this.endPoint); } + get Length(): number { return this.m_StartPoint.distanceTo(this.m_EndPoint); } //#region -----------------------------File----------------------------- //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 @@ -246,16 +252,16 @@ export class Line extends Curve { super.ReadFile(file); let ver = file.Read();//1 - this.startPoint.fromArray(file.Read()); - this.endPoint.fromArray(file.Read()); + this.m_StartPoint.fromArray(file.Read()); + this.m_EndPoint.fromArray(file.Read()); } //对象将自身数据写入到文件. WriteFile(file: CADFile) { super.WriteFile(file); file.Write(1);//ver - file.Write(this.startPoint.toArray()); - file.Write(this.endPoint.toArray()); + file.Write(this.m_StartPoint.toArray()); + file.Write(this.m_EndPoint.toArray()); } //#endregion-----------------------------File End----------------------------- @@ -263,23 +269,23 @@ export class Line extends Curve set StartPoint(v: Vector3) { this.WriteAllObjectRecord(); - this.startPoint.copy(v); + this.m_StartPoint.copy(v); this.Update(); } get StartPoint(): Vector3 { - return this.startPoint.clone(); + return this.m_StartPoint.clone(); } get EndPoint(): Vector3 { - return this.endPoint.clone(); + return this.m_EndPoint.clone(); } set EndPoint(v: Vector3) { this.WriteAllObjectRecord(); - this.endPoint.copy(v); + this.m_EndPoint.copy(v); this.Update(); } diff --git a/src/DatabaseServices/Region.ts b/src/DatabaseServices/Region.ts index 3955290c9..931a9eeca 100644 --- a/src/DatabaseServices/Region.ts +++ b/src/DatabaseServices/Region.ts @@ -1,5 +1,5 @@ -import { Object3D, ShapeGeometry, Vector2, Vector3 } from 'three'; import * as THREE from 'three'; +import { Object3D, Shape, ShapeGeometry, Vector2, Vector3 } from 'three'; import { begin } from 'xaop'; import { CreateBoardUtil } from '../ApplicationServices/mesh/createBoard'; @@ -21,7 +21,7 @@ const fuzz = 1e-8; export class Region extends Entity { private m_CuList: Array = []; - private m_Shape: THREE.Shape; + private m_Shape: Shape; constructor(curveList?: Array) { super(); @@ -29,23 +29,37 @@ export class Region extends Entity if (curveList) this.m_CuList.push(...curveList); } + + get Shape(): Shape + { + if (!this.m_Shape) this.GeneralShape(); + return this.m_Shape; + } + Draw(renderType: RenderType): Object3D { let obj = super.Draw(renderType); if (obj) return obj; - this.m_Shape = new THREE.Shape(); + this.GeneralShape(); - let begin: Vector3; + let geometry = new ShapeGeometry(this.m_Shape, 60); + let mesh = new THREE.Mesh(geometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); + this.m_DrawEntity.set(renderType, mesh); + mesh.userData = this; + return mesh; + } + private GeneralShape() + { + this.m_Shape = new THREE.Shape(); + let begin: Vector3; if (this.m_CuList.length > 1) { let firstL = this.m_CuList[0]; let seconL = this.m_CuList[1]; - if (firstL.StartPoint.distanceTo(seconL.StartPoint) < fuzz - || firstL.StartPoint.distanceTo(seconL.EndPoint) < fuzz - ) + || firstL.StartPoint.distanceTo(seconL.EndPoint) < fuzz) { begin = firstL.EndPoint; } @@ -55,17 +69,14 @@ export class Region extends Entity } this.m_Shape.moveTo(begin.x, begin.y); } - for (let cu of this.m_CuList) { - + if (cu.EndPoint.distanceTo(begin) < fuzz) + cu.Reverse(); + //设置起点 + begin.copy(cu.EndPoint); if (cu instanceof Line) { - if (cu.StartPoint.distanceTo(begin) < fuzz) - begin = cu.EndPoint; - else - begin = cu.StartPoint; - this.m_Shape.lineTo(begin.x, begin.y); } else if (cu instanceof Circle) @@ -78,9 +89,6 @@ export class Region extends Entity } else if (cu instanceof Polyline) { - if (cu.EndPoint.distanceTo(begin) < fuzz) - cu.Reverse(); - let plData = cu.LineData; let pts: Vector2[] = []; let bul: number[] = []; @@ -90,24 +98,12 @@ export class Region extends Entity bul.push(d.bul); } CreateBoardUtil.createPath(pts, bul, this.m_Shape); - - begin = cu.EndPoint; } else if (cu instanceof Arc) { - //起点和终点影响开始角度,结束角度和法向量 - if (begin.distanceTo(cu.StartPoint) < 0.1) - this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, cu.StartAngle, cu.EndAngle, cu.Normal.z < 0); - else - this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, cu.EndAngle, cu.StartAngle, cu.Normal.z > 0); + this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, cu.StartAngle, cu.EndAngle, cu.IsClockWise); } } - - let geometry = new ShapeGeometry(this.m_Shape, 60); - let mesh = new THREE.Mesh(geometry, ColorMaterial.GetLineMaterial(this.ColorIndex)); - this.m_DrawEntity.set(renderType, mesh); - mesh.userData = this; - return mesh; } //在移动时应用矩阵变换 diff --git a/src/Editor/CommandMachine.ts b/src/Editor/CommandMachine.ts index 3ffffb9ef..5db91c9ed 100644 --- a/src/Editor/CommandMachine.ts +++ b/src/Editor/CommandMachine.ts @@ -44,6 +44,7 @@ export class CommandMachine { this.m_CommandIng = false; app.m_Editor.m_CommandStore.isCmdIng = false; + app.m_Editor.ClearSnapEntity(); } get CommandNameList(): Set diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 4103c2786..3679e9202 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -1,10 +1,9 @@ -import { Command_DrawBoard } from '../Add-on/DrawBoard'; -// import { DrawFloor } from '../Add-on/DrawFloor'; import { DrawAxis } from '../Add-on/AddAxis'; import { Command_Copy } from '../Add-on/Copy'; import { CustomUcs } from '../Add-on/CostumUCS'; import { Union } from '../Add-on/CSGUnion'; import { DrawArc } from '../Add-on/DrawArc'; +import { Command_DrawBoard } from '../Add-on/DrawBoard'; import { DrawEllipse } from '../Add-on/DrawEllipse'; import { DrawFloor } from '../Add-on/DrawFloor'; import { DrawGripStretch } from '../Add-on/DrawGripStretch'; @@ -18,6 +17,7 @@ import { DrawCircle0 } from '../Add-on/DrawZeroCircle'; import { Entsel } from '../Add-on/Entsel'; import { Command_Erase } from '../Add-on/Erase'; import { Command_Extend } from '../Add-on/Extends'; +import { CommandFillet } from '../Add-on/Fillet'; import { Fbx } from '../Add-on/loadfbx'; import { LoadImg } from '../Add-on/LoadImg'; import { Command_Move } from '../Add-on/Move'; @@ -25,17 +25,18 @@ import { Open } from '../Add-on/Open'; import { Command_RevPl } from '../Add-on/RevPl'; import { Command_Rotate } from '../Add-on/Rotate'; import { Save } from '../Add-on/Save'; +import { Command_Ssget } from '../Add-on/ssget'; import { Stretch } from '../Add-on/Stretch'; import { Command_SwitchCamera } from '../Add-on/SwitchCamera'; import { Command_SwitchPass } from '../Add-on/SwitchPass'; import { Test } from '../Add-on/test'; +import { Command_DrawBoard2 } from '../Add-on/TestDrawBoard'; import { Command_Trim } from '../Add-on/Trim'; import { Redo, Undo } from '../Add-on/Undo'; import { ViewToFront, ViewToTop } from '../Add-on/ViewChange'; import { commandMachine } from './CommandMachine'; -import { Command_Ssget } from '../Add-on/ssget'; -import { CommandFillet } from '../Add-on/Fillet'; +// import { DrawFloor } from '../Add-on/DrawFloor'; // import { RevTarget, SaveTarget } from '../Add-on/RenderTarget'; export function registerCommand() { @@ -111,6 +112,9 @@ export function registerCommand() commandMachine.RegisterCommand("f", new CommandFillet()); + + commandMachine.RegisterCommand("br2", new Command_DrawBoard2()); + // commandMachine.RegisterCommand("st", new SaveTarget()) // commandMachine.RegisterCommand("rt", new RevTarget()) } diff --git a/src/Editor/SelectControls.ts b/src/Editor/SelectControls.ts index b6f1e3cea..83859425c 100644 --- a/src/Editor/SelectControls.ts +++ b/src/Editor/SelectControls.ts @@ -12,7 +12,6 @@ import { SelectBox } from './SelectBox'; import { SelectPick } from './SelectPick'; import { SelectSet, SelectType } from './SelectSet'; import { TransMode } from './TranstrolControl/TransformServices'; -import { Entity } from '../DatabaseServices/Entity'; export class SelectControls implements EditorService { diff --git a/src/Geometry/CoordinateSystem.ts b/src/Geometry/CoordinateSystem.ts index 65e4cf6d0..8e21a0891 100644 --- a/src/Geometry/CoordinateSystem.ts +++ b/src/Geometry/CoordinateSystem.ts @@ -1,35 +1,44 @@ -import * as THREE from 'three'; +import { Matrix4, Vector3 } from 'three'; + +/** + * 坐标系运算. + * + * @export + * @class CoordinateSystem + */ export class CoordinateSystem { - m_Postion: THREE.Vector3; - m_xAxis: THREE.Vector3; - m_yAxis: THREE.Vector3; - m_zAxis: THREE.Vector3; + m_Postion: Vector3; + m_xAxis: Vector3; + m_yAxis: Vector3; + m_zAxis: Vector3; - constructor(postion?: THREE.Vector3, xAxis?: THREE.Vector3, yAxis?: THREE.Vector3, zAxis?: THREE.Vector3) + constructor(postion?: Vector3, xAxis?: Vector3, yAxis?: Vector3, zAxis?: Vector3) { - this.m_Postion = postion || new THREE.Vector3(0, 0, 0); - this.m_xAxis = xAxis || new THREE.Vector3(1, 0, 0); - this.m_yAxis = yAxis || new THREE.Vector3(0, 1, 0); - this.m_zAxis = zAxis || new THREE.Vector3(0, 0, 1); + this.m_Postion = postion || new Vector3(0, 0, 0); + this.m_xAxis = xAxis || new Vector3(1, 0, 0); + this.m_yAxis = yAxis || new Vector3(0, 1, 0); + this.m_zAxis = zAxis || new Vector3(0, 0, 1); } - applyMatrix4(mat4: THREE.Matrix4) + applyMatrix4(mat4: Matrix4) { - this.m_Postion.applyMatrix4(mat4) - this.m_xAxis.applyMatrix4(mat4) - this.m_yAxis.applyMatrix4(mat4) - this.m_zAxis.applyMatrix4(mat4) + this.m_Postion.applyMatrix4(mat4); + let roMat = new Matrix4(); + mat4.extractRotation(roMat); + this.m_xAxis.applyMatrix4(roMat); + this.m_yAxis.applyMatrix4(roMat); + this.m_zAxis.applyMatrix4(roMat); } - getMatrix4(): THREE.Matrix4 + getMatrix4(): Matrix4 { - let m = new THREE.Matrix4() + let m = new Matrix4() m.makeBasis(this.m_xAxis, this.m_yAxis, this.m_zAxis) m.setPosition(this.m_Postion) return m; } - copyForm(mat4: THREE.Matrix4) + copyForm(mat4: Matrix4) { this.m_Postion.set( mat4.elements[12], @@ -39,7 +48,7 @@ export class CoordinateSystem mat4.extractBasis(this.m_xAxis, this.m_yAxis, this.m_zAxis) } - extractBasis(xAxisA: THREE.Vector3, yAxisA: THREE.Vector3, zAxisA: THREE.Vector3) + extractBasis(xAxisA: Vector3, yAxisA: Vector3, zAxisA: Vector3) { xAxisA.copy(this.m_xAxis); yAxisA.copy(this.m_yAxis); @@ -55,7 +64,11 @@ export class CoordinateSystem } clone() { - let r = new CoordinateSystem() - return r + let r = new CoordinateSystem(); + r.m_Postion = this.m_Postion.clone(); + r.m_xAxis = this.m_xAxis.clone(); + r.m_yAxis = this.m_yAxis.clone(); + r.m_zAxis = this.m_zAxis.clone(); + return r; } -} \ No newline at end of file +} diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index 13e540dd1..36cc7b0e3 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -279,7 +279,7 @@ export class Viewer en.GoodBye(); } }) - xaop.end(db.ModelSpace, db.ModelSpace.ReadFile, () => + xaop.end(db, db.FileRead, () => { renderEntitys(); }) diff --git a/src/UI/Components/Asset.tsx b/src/UI/Components/Asset.tsx index e73bbdddb..07f5d1db9 100644 --- a/src/UI/Components/Asset.tsx +++ b/src/UI/Components/Asset.tsx @@ -133,17 +133,21 @@ export class Asset extends React.Component{ { //得到选择的实体. let mat = this.props.showObject as DbPhysicalMaterial; - for (let o of app.m_Viewer.m_OutlinePass.selectedObjects) + for (let en of app.m_Editor.m_SelectCtrl.SelectSet.SelectEntityList) { - if (o instanceof THREE.Mesh) - { - o.material = mat.Material; - } + en.Material = mat.Id; } + // for (let o of app.m_Viewer.m_OutlinePass.selectedObjects) + // { + // if (o instanceof THREE.Mesh) + // { + // o.material = mat.Material; + // } + // } app.m_Viewer.m_bNeedUpdate = true; } handleDelete = () => { // app.m_Database.m_MaterialDictionary.removeMaterial(this.props.id); } -} \ No newline at end of file +}