加入材质字典.

pull/7/head
ChenX 7 years ago
parent c11d993b3f
commit cf06aed9ba

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`changev 1`] = `"[1,[\\"BlockTableRecord\\",1,0,1,[\\"Line\\",1,1,1,[2,3,4],[0,0,0]]]]"`;
exports[`changev 1`] = `"[1,[\\"BlockTableRecord\\",1,0,1,[\\"Line\\",1,2,1,[2,3,4],[0,0,0]]],[\\"MaerialTableRecord\\",1,1,0]]"`;
exports[`测试创建 1`] = `"[1,-1,1,[]]"`;

@ -1,10 +1,14 @@
import { Vector3 } from 'three';
import * as THREE from 'three';
import
{
AllObjectData,
BlockTableRecord,
CADFactory,
CADFile,
CADObject,
ColorMaterial,
CommandHistoryRecord,
CreateObjectData,
Database,
@ -12,7 +16,6 @@ import
Line,
ObjectAllDataHistoryRecord,
RemoveObjectData,
CADObject,
} from '../../src/DatabaseServices/FileSystem';
function CadObjectToString(obj: CADObject)
@ -158,3 +161,22 @@ test('xxx', () =>
expect(f3.ToString()).toBe(f.ToString());//对象序列化反序列化后 数据应该一样
});
test('create material', () =>
{
let materialRed = new ColorMaterial();
materialRed.Color = new THREE.Color(321321);
materialRed.ClassName /*?*/
let f = new CADFile();
f.WriteObject(materialRed);
let materialCopy = f.ReadObject(undefined);
f.ToString()/*?*/
CadObjectToString(materialRed) /*?*/
});

@ -912,6 +912,7 @@ export class Database
//模型空间
ModelSpace: BlockTableRecord;
//材质字典...
MaterialDict: MaerialTableRecord;
private idCout = -1;
private idMap = new Map<number, ObjectId>();
@ -920,6 +921,9 @@ export class Database
{
this.ModelSpace = new BlockTableRecord();
this.ModelSpace.InitObjectId(this);
this.MaterialDict = new MaerialTableRecord();
this.MaterialDict.InitObjectId(this);
this.hm = new HistoricManage();
this.hm.SetDefaultDb(this);
}
@ -929,12 +933,14 @@ export class Database
let file = new CADFile();
file.Write(1);//ver;
file.WriteObject(this.ModelSpace);
file.WriteObject(this.MaterialDict);
return file;
}
FileRead(file: CADFile)
{
let ver = file.Read();
file.ReadObject(this, this.ModelSpace);
file.ReadObject(this, this.MaterialDict);
}
//创建一个id,自动递增它的索引号,并且会自动加入到db的id列表中.
@ -976,35 +982,16 @@ export class Database
@Factory
export class BlockTableRecord extends ObjectCollection<Entity>
{
constructor()
{
super();
}
//#region -----------------------------File-----------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFile)
{
super.ReadFile(file);
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)
{
super.WriteFile(file);
}
//局部撤销
ApplyPartialUndo(undoData: CADObject)
{
super.ApplyPartialUndo(undoData);
}
//#endregion-----------------------------File End-----------------------------
}
//所有图元的基类
@Factory
export class Entity extends CADObject
{
protected m_DrawEntity = new Map<RenderType, Object3D>();
//材质id
protected m_MaterialId: ObjectId;
//绘制一个threeJs对象.
Draw(renderType: RenderType = RenderType.Wireframe): Object3D
{
@ -1088,3 +1075,70 @@ export class Line extends Entity
//#endregion
}
@Factory
export class MaerialTableRecord extends ObjectCollection<Material>
{
}
@Factory
export class Material extends CADObject
{
}
//颜色材质,对于二维图像来说可能有用,应该不对三维对象使用该材质
@Factory
export class ColorMaterial extends Material
{
private m_Color: THREE.Color;
constructor()
{
super();
this.m_Color = new THREE.Color();
}
get Color(): THREE.Color
{
return this.m_Color;
}
set Color(v: THREE.Color)
{
this.m_Color.copy(v);
}
private m_Material: THREE.LineBasicMaterial;
get LineMaterial(): THREE.LineBasicMaterial
{
if (!this.m_Material)
{
this.m_Material = new THREE.LineBasicMaterial({ color: this.m_Color });
}
return this.m_Material;
}
//#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFile)
{
let ver = file.Read();
let hex = file.Read();
this.m_Color.setHex(hex);
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)
{
file.Write(1);
file.Write(this.m_Color.getHex());
}
//局部撤销
ApplyPartialUndo(undoData: CADObject)
{
}
//#endregion
}

Loading…
Cancel
Save