使所有的定位方式都支持相对定位

pull/450/MERGE
ChenX 5 years ago
parent e2adafb335
commit e08b2a6824

@ -103,7 +103,8 @@ export class TemplateParam
if (this.expr === "") return this.value as number;
if (evaled.has(this)) return this.value as number;
evaled.add(this);
if (update)
evaled.add(this);
let value = parseFloat(this.expr as string);
if (isNaN(value))
@ -113,7 +114,7 @@ export class TemplateParam
for (let key of keywords)
{
if (key !== this.name && paramMap.has(key))
paramMap.get(key).EvalUpdate(vardefines, paramMap, evaled, update);
vardefines[key] = paramMap.get(key).EvalUpdate(vardefines, paramMap, evaled, update);
}
try
@ -126,7 +127,7 @@ export class TemplateParam
return this.value as number;
}
}
else
else if (update)
this.expr = "";
vardefines[this.name] = value;

@ -252,7 +252,14 @@ export class TemplateRecord extends SymbolTableRecord
for (let br of brs)
br.ApplyMatrix(br.SpaceOCSInv);
//#region 1.定位(坐标系和大小)
/**
* LWH.
* - ,LWH.
* - ,,,
* ,.
*/
if (this.positioning)
{
@ -263,11 +270,7 @@ export class TemplateRecord extends SymbolTableRecord
this._CacheSpaceCS = this.positioning.SpaceCS;
this._CacheSpaceSize = this.positioning.SpaceSize;
this._CacheSpaceCS = this.RotateSpaceCS(this._CacheParamVars, paramMap, evaled, this._CacheSpaceCS, this._CacheSpaceSize);
this._CacheParamVars["L"] = this._CacheSpaceSize.x;
this._CacheParamVars["W"] = this._CacheSpaceSize.y;
this._CacheParamVars["H"] = this._CacheSpaceSize.z;
this.RotateSpaceCS(paramMap, evaled);
if (this.LParam.expr)
this._CacheSpaceSize.x = this.LParam.EvalUpdate(this._CacheParamVars, paramMap, evaled, false);
@ -276,35 +279,17 @@ export class TemplateRecord extends SymbolTableRecord
if (this.HParam.expr)
this._CacheSpaceSize.z = this.HParam.EvalUpdate(this._CacheParamVars, paramMap, evaled, false);
//更新LWH(通过定位空间)
this.LParam.UpdateParam(this._CacheSpaceSize.x);
this.WParam.UpdateParam(this._CacheSpaceSize.y);
this.HParam.UpdateParam(this._CacheSpaceSize.z);
if (this.positioning instanceof PositioningTemporary)
this.positioning = undefined;
}
else
{
this.LParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.WParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.HParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.PXParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.PYParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.PZParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
let l = this.LParam.value as number;
let w = this.WParam.value as number;
let h = this.HParam.value as number;
let l = this.LParam.EvalUpdate(this._CacheParamVars, paramMap, evaled, false);
let w = this.WParam.EvalUpdate(this._CacheParamVars, paramMap, evaled, false);
let h = this.HParam.EvalUpdate(this._CacheParamVars, paramMap, evaled, false);
this._CacheSpaceSize = new Vector3(l, w, h);
//相对定位. use PX PY pZ
let baseP = new Vector3(this.PXParam.value as number, this.PYParam.value as number, this.PZParam.value as number);
baseP.applyMatrix4(this._CacheSpaceCS);
this._CacheSpaceCS.setPosition(baseP);
this._CacheSpaceCS = this.RotateSpaceCS(this._CacheParamVars, paramMap, evaled, this._CacheSpaceCS, this._CacheSpaceSize);
this.RotateSpaceCS(paramMap, evaled);
if (!this.Parent)
{
@ -324,16 +309,19 @@ export class TemplateRecord extends SymbolTableRecord
this.RYParam.expr = "";
this.RZParam.expr = "";
}
//更新LWH(通过定位空间)
this.LParam.UpdateParam(this._CacheSpaceSize.x);
this.WParam.UpdateParam(this._CacheSpaceSize.y);
this.HParam.UpdateParam(this._CacheSpaceSize.z);
}
this._CacheParamVars["L"] = this._CacheSpaceSize.x;
this._CacheParamVars["W"] = this._CacheSpaceSize.y;
this._CacheParamVars["H"] = this._CacheSpaceSize.z;
//相对定位. use PX PY PZ
this.UpdatePosition(paramMap, evaled);
//更新LWH(通过定位空间)
this.LParam.UpdateParam(this._CacheSpaceSize.x);
this.WParam.UpdateParam(this._CacheSpaceSize.y);
this.HParam.UpdateParam(this._CacheSpaceSize.z);
evaled.add(this.LParam);
evaled.add(this.WParam);
evaled.add(this.HParam);
//#endregion
@ -371,14 +359,31 @@ export class TemplateRecord extends SymbolTableRecord
}
}
/**
* 使PXPYPZ
*/
private UpdatePosition(paramMap: Map<string, TemplateParam>, evaled: Set<TemplateParam>)
{
this.PXParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.PYParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.PZParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
if (this.PXParam.value !== 0 || this.PYParam.value !== 0 || this.PZParam.value !== 0)
{
let baseP = new Vector3(this.PXParam.value as number, this.PYParam.value as number, this.PZParam.value as number);
baseP.applyMatrix4(this._CacheSpaceCS);
this._CacheSpaceCS.setPosition(baseP);
}
}
/**
* ,,SpaceSizeSpaceCS
*/
private RotateSpaceCS(vardefines: any, paramMap: Map<string, TemplateParam>, evaled: Set<TemplateParam>, spaceCS: Matrix4, spaceSize: Vector3)
private RotateSpaceCS(paramMap: Map<string, TemplateParam>, evaled: Set<TemplateParam>)
{
this.RXParam.EvalUpdate(vardefines, paramMap, evaled);
this.RYParam.EvalUpdate(vardefines, paramMap, evaled);
this.RZParam.EvalUpdate(vardefines, paramMap, evaled);
this.RXParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.RYParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
this.RZParam.EvalUpdate(this._CacheParamVars, paramMap, evaled);
//use RX RY RZ
let rx = Math.degToRad(this.RXParam.value as number);
let ry = Math.degToRad(this.RYParam.value as number);
@ -389,21 +394,23 @@ export class TemplateRecord extends SymbolTableRecord
let mry = new Matrix4().makeRotationY(ry);
let mrz = new Matrix4().makeRotationZ(rz);
let mro = mrz.multiply(mry.multiply(mrx));
let roSpace = mro.multiply(spaceCS);
let roSpace = mro.multiply(this._CacheSpaceCS);
let roSpaceInv = mrx.getInverse(roSpace); //变量复用
let transfromToRoSpace = roSpaceInv.multiply(spaceCS);
let box = new Box3(new Vector3(), spaceSize.clone());
let transfromToRoSpace = roSpaceInv.multiply(this._CacheSpaceCS);
let box = new Box3(new Vector3(), this._CacheSpaceSize.clone());
box.applyMatrix4(transfromToRoSpace);
box.getSize(spaceSize);
box.getSize(this._CacheSpaceSize);
let baseP = box.min.clone().applyMatrix4(roSpace);
roSpace.setPosition(baseP);
//更新LWH(通过定位空间)
this.LParam.UpdateParam(spaceSize.x);
this.WParam.UpdateParam(spaceSize.y);
this.HParam.UpdateParam(spaceSize.z);
spaceCS = roSpace;
this.LParam.UpdateParam(this._CacheSpaceSize.x);
this.WParam.UpdateParam(this._CacheSpaceSize.y);
this.HParam.UpdateParam(this._CacheSpaceSize.z);
this._CacheSpaceCS = roSpace;
}
return spaceCS;
this._CacheParamVars["L"] = this._CacheSpaceSize.x;
this._CacheParamVars["W"] = this._CacheSpaceSize.y;
this._CacheParamVars["H"] = this._CacheSpaceSize.z;
}
/** 以广度搜索优先更新节点树 */

Loading…
Cancel
Save