修正板厚变化时造型保持

pull/539/MERGE
ChenX 5 years ago
parent 7dbbe6bdf7
commit d72510534a

@ -165,3 +165,10 @@ export function arrayPushArray<T>(arr1: T[], arr2: T[]): T[]
return arr1;
}
export function arraySum(arr: number[])
{
let sum = 0;
for (let n of arr) sum += n;
return sum;
}

@ -379,19 +379,6 @@ export class Board extends ExtrudeSolid
}
return roMat;
}
get Thickness()
{
return this.thickness;
}
set Thickness(v: number)
{
if (!equaln(v, this.thickness, 1e-2))
{
this.WriteAllObjectRecord();
this.thickness = v;
this.Update();
}
}
get Height()
{
return this.height;

@ -1,5 +1,5 @@
import { Box3, BoxGeometry, BufferGeometry, ExtrudeGeometry, ExtrudeGeometryOptions, Geometry, Line, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Vector3 } from "three";
import { arrayClone, arrayLast, arrayRemoveIf, arraySortByNumber } from "../../Common/ArrayExt";
import { arrayClone, arrayLast, arrayRemoveIf, arraySortByNumber, arraySum } from "../../Common/ArrayExt";
import { ColorMaterial } from "../../Common/ColorPalette";
import { equalCurve } from "../../Common/CurveUtils";
import { DisposeThreeObj } from "../../Common/Dispose";
@ -194,7 +194,30 @@ export class ExtrudeSolid extends Entity
}
set Thickness(thickness: number)
{
this.thickness = thickness;
if (!equaln(thickness, this.thickness, 1e-3))
{
this.WriteAllObjectRecord();
if (this.grooves.length > 0)
{
let inv = this.OCSInv;
let v = this.Normal.multiplyScalar(thickness - this.thickness);
let m = new Matrix4().setPosition(v);
for (let g of this.grooves)
{
let p = g.Position.applyMatrix4(inv);
if (equaln(g.thickness, this.thickness))
g.Thickness = thickness;
else if (!equaln(p.z, 0))
g.ApplyMatrix(m);
}
}
this.thickness = thickness;
this.Update(UpdateDraw.Geometry);
}
}
get Grooves()
@ -479,6 +502,12 @@ export class ExtrudeSolid extends Entity
{
this.WriteAllObjectRecord();
if (dragType === DragPointType.Stretch && indexList.length === arraySum(this.GetStrectchPointCountList(dragType)))
{
this.Position = this.Position.add(vec);
return;
}
arraySortByNumber(indexList);
if (this.grooves.length === 0)
@ -967,6 +996,8 @@ export class ExtrudeSolid extends Entity
*/
g.grooves.length = 0;
}
else
arrayRemoveIf(g.grooves, subg => !equaln(g.thickness, subg.thickness));
}
//合并

@ -1,8 +1,8 @@
import { Factory } from "../../CADFactory";
import { Board } from "../../Entity/Board";
import { TemplateAction } from "./TemplateAction";
import { CADFiler } from "../../CADFiler";
import { Board } from "../../Entity/Board";
import { ObjectId } from "../../ObjectId";
import { TemplateAction } from "./TemplateAction";
export enum ThicknessDirection
{
@ -27,7 +27,6 @@ export interface ThicknessActionData
@Factory
export class TempateThicknessAction extends TemplateAction
{
//正 true 反 false
EntityDirectionMap: Map<ObjectId, ThicknessActionData> = new Map();
protected _Update(paramDiff: number, newValue: number)
{

@ -424,6 +424,10 @@ export async function InitTempateBoardThicknessActions(template: TemplateRecord,
for (let br of brs)
{
//板件中心
let boardCenter = new Vector3(br.Width, br.Height, br.Thickness).multiplyScalar(.5);
boardCenter.applyMatrix4(br.OCS);
let p: Vector3;
if (!autoCalculate)
{
@ -431,10 +435,6 @@ export async function InitTempateBoardThicknessActions(template: TemplateRecord,
app.Viewer.OutlinePass.selectedObjects = [br.DrawObject];
app.Editor.UpdateScreen();
//板件中心
let boardCenter = new Vector3(br.Width, br.Height, br.Thickness).multiplyScalar(.5);
boardCenter.applyMatrix4(br.OCS);
//设置UCS
app.Editor.UCSMatrix = br.OCS;
@ -453,8 +453,9 @@ export async function InitTempateBoardThicknessActions(template: TemplateRecord,
else
p = center.clone();
let v = p.sub(boardCenter).applyMatrix4(br.OCSInv.setPosition(ZeroVec));
//构建板厚动作
GeneralBoardThicknessAction(br, p, scsInv, brs, directionMap);
GeneralBoardThicknessAction(br, v, scsInv, brs, directionMap);
}
let action = new TempateThicknessAction();
action.EntityDirectionMap = directionMap;
@ -469,15 +470,13 @@ export async function InitTempateBoardThicknessActions(template: TemplateRecord,
/**
*
* @param br
* @param p wcs,
* @param v wcs,
* @param scsInv
* @param brs
* @param directionMap
*/
function GeneralBoardThicknessAction(br: Board, p: Vector3, scsInv: Matrix4, brs: Board[], directionMap: Map<ObjectId, ThicknessActionData>)
function GeneralBoardThicknessAction(br: Board, v: Vector3, scsInv: Matrix4, brs: Board[], directionMap: Map<ObjectId, ThicknessActionData>)
{
p.applyMatrix4(br.OCSInv);
let direction: ThicknessDirection;
let actions: TemplateAction[] = [];
@ -524,7 +523,7 @@ function GeneralBoardThicknessAction(br: Board, p: Vector3, scsInv: Matrix4, brs
}
//判断拉伸方向
if (equaln(p.z, 0))//居中
if (equaln(v.z, 0))//居中
{
direction = ThicknessDirection.Center;
@ -540,7 +539,7 @@ function GeneralBoardThicknessAction(br: Board, p: Vector3, scsInv: Matrix4, brs
}
else
{
if (p.z > 0)
if (v.z > 0)
{
direction = ThicknessDirection.Front;
let frontAction = new TemplateStretchGripAction(frontVec);
@ -626,9 +625,9 @@ export async function UpdateTempateBoardThicknessAction(template: TemplateRecord
return;
}
let p = ptRes.Point;
let v = ptRes.Point.sub(boardCenter).applyMatrix4(br.OCSInv.setPosition(ZeroVec));
//构建板厚动作
GeneralBoardThicknessAction(br, p, scsInv, brs, thicknessAction.EntityDirectionMap);
GeneralBoardThicknessAction(br, v, scsInv, brs, thicknessAction.EntityDirectionMap);
}
//还原

Loading…
Cancel
Save