同步源码

This commit is contained in:
ChenX
2023-02-22 09:27:57 +08:00
parent 8f005232a8
commit ba2be9949d
37 changed files with 212 additions and 64 deletions

View File

@@ -709,7 +709,7 @@ class CADFiler {
Read() {
return this._datas[this.readIndex++];
}
ReadBool(v) {
ReadBool() {
return Boolean(this.Read());
}
ReadArray(count) {
@@ -791,11 +791,11 @@ exports.AllObjectData = __decorate([
exports.EraseEntityData = class EraseEntityData {
ReadFile(file) {
this.isErase = file.Read();
this.isErase = file.ReadBool();
return this;
}
WriteFile(file) {
file.Write(this.isErase);
file.WriteBool(this.isErase);
return this;
}
constructor(isErase = true) {
@@ -892,7 +892,7 @@ class CADObject {
this.objectId = id;
id.Object = this;
}
this._isErase = file.Read();
this._isErase = file.ReadBool();
if (ver > 1)
this._Owner = file.ReadObjectId();
}
@@ -900,7 +900,7 @@ class CADObject {
WriteFile(file) {
file.Write(2);
file.WriteObjectId(this.objectId);
file.Write(this._isErase);
file.WriteBool(this._isErase);
file.WriteObjectId(this._Owner);
}
//局部撤销
@@ -1508,6 +1508,7 @@ exports.Entity = Entity_1 = class Entity extends CADObject {
//模块空间的标系
this._SpaceOCS = new three.Matrix4();
this._Visible = true;
this._VisibleInRender = true; //在渲染器中显示
this._Freeze = false; //冻结(无法被选中)
//加工组
this.ProcessingGroupList = [];
@@ -1540,6 +1541,13 @@ exports.Entity = Entity_1 = class Entity extends CADObject {
this.WriteAllObjectRecord();
this._Freeze = f;
}
get VisibleInRender() { return this._VisibleInRender; }
set VisibleInRender(v) {
if (this._VisibleInRender !== v) {
this.WriteAllObjectRecord();
this._VisibleInRender = v;
}
}
set Material(materialId) {
if (materialId === this._MaterialId)
return;
@@ -2001,6 +2009,8 @@ exports.Entity = Entity_1 = class Entity extends CADObject {
super.ReadFile(file);
this._Color = file.Read();
this._MaterialId = file.ReadHardObjectId();
if (!this._MaterialId)
this._MaterialId = file.database?.DefaultMaterial?.Id;
this._Matrix.fromArray(file.Read());
if (ver === 2)
this.Owner = file.ReadObjectId();
@@ -2009,7 +2019,7 @@ exports.Entity = Entity_1 = class Entity extends CADObject {
if (ver > 4)
this.GroupId = file.ReadHardObjectId();
if (ver > 5)
this._Visible = file.Read();
this._Visible = file.ReadBool();
if (ver > 6)
this._SpaceOCS.fromArray(file.Read());
if (ver > 7) {
@@ -2022,25 +2032,30 @@ exports.Entity = Entity_1 = class Entity extends CADObject {
}
}
if (ver > 8)
this._Freeze = file.Read();
this._Freeze = file.ReadBool();
else
this._Freeze = false;
if (ver > 9)
this._VisibleInRender = file.ReadBool();
else
this._VisibleInRender = true;
}
//对象将自身数据写入到文件.
WriteFile(file) {
file.Write(9);
file.Write(10);
super.WriteFile(file);
file.Write(this._Color);
file.WriteHardObjectId(this._MaterialId);
file.Write(this._Matrix.toArray());
file.WriteObjectId(this.Template);
file.WriteHardObjectId(this.GroupId);
file.Write(this._Visible);
file.WriteBool(this._Visible);
file.Write(this._SpaceOCS.toArray());
file.Write(this.ProcessingGroupList.length);
for (let id of this.ProcessingGroupList)
file.WriteHardObjectId(id);
file.WriteBool(this._Freeze);
file.WriteBool(this._VisibleInRender);
}
//局部撤销
ApplyPartialUndo(undoData) {
@@ -9381,7 +9396,7 @@ exports.Arc = Arc_1 = class Arc extends exports.Curve {
this._Radius = file.Read();
this._StartAngle = file.Read();
this._EndAngle = file.Read();
this._Clockwise = file.Read();
this._Clockwise = file.ReadBool();
}
//对象将自身数据写入到文件.
WriteFile(file) {
@@ -9390,7 +9405,7 @@ exports.Arc = Arc_1 = class Arc extends exports.Curve {
file.Write(this._Radius);
file.Write(this._StartAngle);
file.Write(this._EndAngle);
file.Write(this._Clockwise);
file.WriteBool(this._Clockwise);
}
};
exports.Arc._X = new three.Vector3;
@@ -21070,6 +21085,8 @@ exports.Board = Board_1 = class Board extends exports.ExtrudeSolid {
}
}
HandleBoardMaterial(renderType, obj) {
if (!obj)
return;
if (!this.IsChaiDan) {
if (renderType === exports.RenderType.Conceptual || renderType === exports.RenderType.Physical2) {
obj.children.length = 1;
@@ -23558,8 +23575,20 @@ exports.Text = class Text extends exports.Entity {
return this.BoundingBoxInOCS.applyMatrix4((this.OCSNoClone));
}
get BoundingBoxInOCS() {
let w = Math.max(Math.abs(this.Width / 2), 1);
let h = Math.max(Math.abs(this.Height / 2), 1);
let width = this.Width;
let height = this.Height;
let obj = this._CacheDrawObject.get(exports.RenderType.Wireframe);
if (obj && obj.children.length === 1) {
let geo = obj.children[0].geometry;
if (geo) {
if (!geo.boundingBox)
geo.computeBoundingBox();
width = geo.boundingBox.max.x - geo.boundingBox.min.x;
height = geo.boundingBox.max.y - geo.boundingBox.min.y;
}
}
let w = Math.max(Math.abs(width / 2), 1);
let h = Math.max(Math.abs(height / 2), 1);
let box = new Box3Ext(new three.Vector3(-w, -h, 0), new three.Vector3(w, h, 0));
let offset = new three.Vector3;
if (this.TextAligen & exports.TextAligen.LeftMid)
@@ -23650,6 +23679,19 @@ exports.Text = class Text extends exports.Entity {
this.Height = this.Height + v.y;
}
}
//捕捉点
GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) {
if (snapMode === ObjectSnapMode.End) {
let box = this.BoundingBoxInOCS;
let p2 = new three.Vector3(box.min.x, box.max.y);
let p3 = new three.Vector3(box.max.x, box.min.y);
let pts = [box.min, p2, p3, box.max];
for (let p of pts)
p.applyMatrix4(this.OCSNoClone);
return pts;
}
return [];
}
GetStretchPoints() {
return [this.Position];
}
@@ -26621,7 +26663,7 @@ exports.SymbolTable = class SymbolTable extends CADObject {
}
WriteFile(file) {
super.WriteFile(file);
file.Write(3);
file.Write(4);
file.Write(this.Symbols.size);
for (let [key, record] of this.Symbols) {
file.WriteObject(record);
@@ -27036,6 +27078,10 @@ exports.BlockTableRecord = class BlockTableRecord extends SymbolTableRecord {
if (!entity.Material)
entity.Material = this._db.MaterialTable.CurFloorMtl;
}
else if (entity instanceof exports.Board) {
if (!entity.Material)
entity.Material = this._db.MaterialTable.CurBoardMtl;
}
}
this.EntityCol.Append(entity, isCheckObjectCleanly);
entity.Owner = this.objectId;
@@ -28172,6 +28218,7 @@ exports.HemisphereLight = __decorate([
class MaterialTable extends exports.SymbolTable {
get CurFloorMtl() { return this._CurFloorMtl; }
get CurWallMtl() { return this._CurWallMtl; }
get CurBoardMtl() { return this._CurDrawMtl; }
set CurFloorMtl(id) {
if (id === this._CurFloorMtl)
return;
@@ -28188,6 +28235,14 @@ class MaterialTable extends exports.SymbolTable {
if (this._db && this._db.IsDefaultDatabase)
HostApplicationServices.DefaultWallMaterial = id.Object.Material;
}
set CurBoardMtl(id) {
if (id === this._CurDrawMtl)
return;
this.WriteAllObjectRecord();
this._CurDrawMtl = id;
if (this._db && this._db.IsDefaultDatabase)
HostApplicationServices.DefaultMeshMaterial = id.Object.Material;
}
get Materials() {
return this.Symbols;
}
@@ -28203,6 +28258,12 @@ class MaterialTable extends exports.SymbolTable {
AllocateName(name = "材质") {
return super.AllocateName(name);
}
Destroy() {
super.Destroy();
this._CurDrawMtl = undefined;
this._CurFloorMtl = undefined;
this._CurWallMtl = undefined;
}
//#region -------------------------File-------------------------
//对象从文件中读取数据,初始化自身
ReadFile(file) {
@@ -28211,12 +28272,15 @@ class MaterialTable extends exports.SymbolTable {
this._CurFloorMtl = file.ReadObjectId();
this._CurWallMtl = file.ReadObjectId();
}
if (this._FileVer > 3)
this._CurDrawMtl = file.ReadHardObjectId();
}
//对象将自身数据写入到文件.
WriteFile(file) {
super.WriteFile(file);
file.WriteObjectId(this._CurFloorMtl);
file.WriteObjectId(this._CurWallMtl);
file.WriteObjectId(this._CurDrawMtl);
}
}
@@ -28433,6 +28497,7 @@ exports.Database = class Database {
this.DefaultMaterial.roughnessMap = texture.Id;
this.DefaultMaterial.bumpMap = texture.Id;
this.MaterialTable.Add(this.DefaultMaterial);
this.MaterialTable.CurBoardMtl = this.DefaultMaterial.Id;
texture.Update();
}
InitLight() {
@@ -28452,7 +28517,9 @@ exports.Database = class Database {
return;
this.DefaultMaterial = this.GetObjectId(71)?.Object ?? this.DefaultMaterial;
this.DefaultMaterial.Update();
HostApplicationServices.DefaultMeshMaterial = this.DefaultMaterial.Material;
HostApplicationServices.DefaultMeshMaterial = this.MaterialTable.CurBoardMtl?.Object?.Material ?? this.DefaultMaterial.Material;
HostApplicationServices.DefaultWallMaterial = this.MaterialTable.CurWallMtl?.Object?.Material ?? this.DefaultMaterial.Material;
HostApplicationServices.DefaultFloorMaterial = this.MaterialTable.CurFloorMtl?.Object?.Material ?? this.DefaultMaterial.Material;
HostApplicationServices.CurrentDimStyle = this.DimStyleTable.Current;
}
Destroy() {