WblockClone 材质球

pull/252/MERGE
ChenX 6 years ago
parent c86057936d
commit 62573bea7a

@ -78,7 +78,7 @@ export class CADFiler
} }
} }
CloneObjects(objects: ISerialize[], clonedObjects: ISerialize[] = []) CloneObjects(objects: CADObject[], clonedObjects: CADObject[] = [])
{ {
for (let o of objects) for (let o of objects)
this.WriteObject(o); this.WriteObject(o);
@ -121,6 +121,10 @@ export class CADFiler
if (this.database) if (this.database)
return this.database.GetObjectId(index, true); return this.database.GetObjectId(index, true);
} }
ReadHardId()
{
return this.ReadObjectId();
}
ToString() ToString()
{ {

@ -14,6 +14,10 @@ export abstract class CADObject
{ {
this.m_Owner = owner; this.m_Owner = owner;
} }
get Owner()
{
return this.m_Owner;
}
//对象被彻底遗弃 //对象被彻底遗弃
GoodBye(): any GoodBye(): any

@ -11,6 +11,9 @@ import { IdMaping } from './IdMaping';
import { MaterialTable } from './MaterialTable'; import { MaterialTable } from './MaterialTable';
import { ObjectId } from './ObjectId'; import { ObjectId } from './ObjectId';
import { TextureTable } from './TextureTable'; import { TextureTable } from './TextureTable';
import { SymbolTable } from './SymbolTable';
import { SymbolTableRecord } from './SymbolTableRecord';
import { WblockCloneFiler } from './WblockCloneFiler';
@Factory @Factory
export class Database export class Database
@ -114,6 +117,16 @@ export class Database
ent.SetDefaultDb(this); ent.SetDefaultDb(this);
owner.Append(ent, false); owner.Append(ent, false);
} }
else if (owner instanceof SymbolTable)
{
let record = objectId.Object as SymbolTableRecord;
if (owner.Has(record.Name))
{
console.log("重复的记录名称!");
continue;
}
owner.Add(record, false);
}
} }
} }
} }
@ -121,7 +134,7 @@ export class Database
/** /**
* . * .
* @param objects * @param objects
* @param owner * @param owner
* @param idMap id * @param idMap id
* @param cloning DuplicateRecordCloning * @param cloning DuplicateRecordCloning
* @param deferXlation ID * @param deferXlation ID
@ -134,7 +147,32 @@ export class Database
deferXlation = false deferXlation = false
) )
{ {
let f = new WblockCloneFiler();
let clonedObjects: CADObject[] = [];
f.CloneObjects(objects, clonedObjects);
this.CheapClone(f, idMap, owner);
let oldDb = objects[0].Db;
for (let [n, id] of f.hardMaping)
{
clonedObjects = [];
let oldId = oldDb.GetObjectId(n);
f.CloneObjects([oldId.Object], clonedObjects);
//使用旧的OwnerId得到新的OwnerId,假设所有者都是数据库默认存在的.
//TODO: 当OwnerId>100时,表示这个所有者不是数据库里面默认存在的,那么应该将Owner拷贝过来.
let newOwnerId = owner.Db.GetObjectId(oldId.Object.Owner.Index);
let newOwner = newOwnerId.Object as SymbolTable;
newOwner.Add(clonedObjects[0] as SymbolTableRecord, false);
id.Index = this.idIndex++;
this.idMap.set(id.Index, id);
idMap.set(oldId, id);
}
return clonedObjects;
} }
Insert() Insert()

@ -10,14 +10,8 @@ ObjectId必须使用 Database分配(db里面会存id的列表,以便同时更新
*/ */
export class ObjectId export class ObjectId
{ {
private id: number; constructor(private index = 0, private obj?: CADObject)
private obj: CADObject;
//对外隐藏构造函数,如果需要构造一个id,请使用 Create 静态方法.
constructor(index: number = 0, obj?: CADObject)
{ {
this.id = index;
this.obj = obj;
} }
get IsErase(): boolean get IsErase(): boolean
@ -34,11 +28,11 @@ export class ObjectId
} }
get Index(): number get Index(): number
{ {
return this.id; return this.index;
} }
set Index(index: number) set Index(index: number)
{ {
this.id = index; this.index = index;
} }
} }

@ -61,10 +61,10 @@ export class PhysicalMaterialRecord extends MaterialTableRecord
this.matalness = file.Read(); this.matalness = file.Read();
this.opacity = file.Read(); this.opacity = file.Read();
this.depthTest = file.Read(); this.depthTest = file.Read();
this.map = file.ReadObjectId(); this.map = file.ReadHardId();
this.bumpMap = file.ReadObjectId(); this.bumpMap = file.ReadHardId();
this.bumpScale = file.Read(); this.bumpScale = file.Read();
this.roughnessMap = file.ReadObjectId(); this.roughnessMap = file.ReadHardId();
this.roughness = file.Read(); this.roughness = file.Read();
this.useMap = file.Read(); this.useMap = file.Read();
this.useBumpMap = file.Read(); this.useBumpMap = file.Read();

@ -13,12 +13,12 @@ export class SymbolTable extends CADObject
*/ */
@observable Symbols = new Map<string, any>(); @observable Symbols = new Map<string, any>();
Add(record: SymbolTableRecord): Status Add(record: SymbolTableRecord, isCheckObjectCleanly = true): Status
{ {
if (this.Symbols.has(record.Name)) if (this.Symbols.has(record.Name))
return Status.DuplicateRecordName; return Status.DuplicateRecordName;
if (this._db && !record.Id) if (this._db && (!isCheckObjectCleanly || !record.Id))
record.SetOwnerDatabase(this._db); record.SetOwnerDatabase(this._db);
record.Owner = this.objectId; record.Owner = this.objectId;

@ -0,0 +1,23 @@
import { DeepCloneFiler } from "./DeepCloneFiler";
import { ObjectId } from "./ObjectId";
export class WblockCloneFiler extends DeepCloneFiler
{
hardMaping = new Map<number, ObjectId>();
ReadHardId()
{
let index = this.Read();
if (index <= 0) return;
let id = this.idMaping.get(index);
if (id) return id;
id = new ObjectId();
this.idMaping.set(index, id);
if (index > 100)
this.hardMaping.set(index, id);
return id;
}
}
Loading…
Cancel
Save