同步源码

This commit is contained in:
ChenX
2023-02-23 10:36:06 +08:00
parent ba2be9949d
commit 72af70545a
13 changed files with 123 additions and 75 deletions

View File

@@ -2250,6 +2250,7 @@ function AsVector3(p) {
function isIntersect(amin, amax, bmin, bmax, eps = 0) {
return Math.max(amin, bmin) < Math.min(amax, bmax) + eps;
}
//范围交集 [a1,a2] 与 [b1,b2] 的交集
function isIntersect2(a1, a2, b1, b2, eps = 0) {
if (a1 > a2)
[a1, a2] = [a2, a1];
@@ -19158,41 +19159,56 @@ var Production;
}
}
/**分析常规排钻 */
function ParseCylHoles(d, br, offsetTanslation, data, outline) {
let processData = br.BoardProcessOption;
function ParseCylHoles(cyHole, br, offsetTanslation, data, outline) {
let brInv = br.OCSInv;
let brNormal = br.Normal;
let roMat = new three.Matrix4().extractRotation(br.OCSInv);
let position = d.Position.applyMatrix4(br.OCSInv);
let roMat = new three.Matrix4().extractRotation(brInv);
let position = cyHole.Position.applyMatrix4(brInv);
let holes = data.frontBackHoles;
let face;
let face; //孔面方向
let isPush = false;
let endPt;
let depth = d.Height;
let diffMat = br.OCSInv.multiply(d.OCS);
let depth = cyHole.Height;
let diffMat = brInv.clone().multiply(cyHole.OCSNoClone);
let x = new three.Vector3().setFromMatrixColumn(diffMat, 0);
let angle = angleTo(XAxis, x);
let nor = d.Normal.applyMatrix4(roMat);
let pos2 = position.clone().add(nor.multiplyScalar(depth));
if (d.Type === exports.GangDrillType.Pxl || d.Type === exports.GangDrillType.WoodPXL) {
if (isParallelTo(d.Normal, brNormal, CanDrawHoleFuzz)) {
if (!IsBetweenA2B(position.x, -d.Radius, br.Width + d.Radius, 1e-6)
|| !IsBetweenA2B(position.y, -d.Radius, br.Height + d.Radius, 1e-6)
|| !isIntersect2(0, br.Thickness, position.z, pos2.z, -CanDrawHoleFuzz)
|| !HoleInBoard(position.clone().setZ(0), d.Radius, outline))
let cyNormal = cyHole.Normal.applyMatrix4(roMat);
let pos2 = position.clone().add(cyNormal.multiplyScalar(depth));
if (cyHole.Type === exports.GangDrillType.Pxl || cyHole.Type === exports.GangDrillType.WoodPXL) {
if (isParallelTo(cyHole.Normal, brNormal, CanDrawHoleFuzz)) {
if (!IsBetweenA2B(position.x, -cyHole.Radius, br.Width + cyHole.Radius, 1e-6)
|| !IsBetweenA2B(position.y, -cyHole.Radius, br.Height + cyHole.Radius, 1e-6)
|| !HoleInBoard(position.clone().setZ(0), cyHole.Radius, outline))
return;
position.sub(offsetTanslation);
face = processData[EBoardKeyList.BigHole];
//#region 求得真实的求交范围
let z0 = position.z;
let z1 = pos2.z;
if (z0 > z1)
[z0, z1] = [z1, z0];
let i1 = Math.max(z0, 0);
let i2 = Math.min(z1, br.Thickness);
if (i2 - i1 < CanDrawHoleFuzz)
return; //相交范围小于0.1
if (equaln$1(i1, 0, CanDrawHoleFuzz))
face = FaceDirection.Back;
else if (equaln$1(i2, br.Thickness, CanDrawHoleFuzz))
face = FaceDirection.Front;
else
return; //不在正面 也不在反面
depth = i2 - i1; //真实的相交范围
//#endregion
isPush = true;
}
}
else if (d.Type === exports.GangDrillType.Ljg || d.Type === exports.GangDrillType.Wood) {
if (isPerpendicularityTo(d.Normal, brNormal, CanDrawHoleFuzz)) //侧孔
else if (cyHole.Type === exports.GangDrillType.Ljg || cyHole.Type === exports.GangDrillType.Wood) {
if (isPerpendicularityTo(cyHole.Normal, brNormal, CanDrawHoleFuzz)) //侧孔
{
let z = position.z;
if (!IsBetweenA2B(z, -d.Radius, br.Thickness + d.Radius, 1e-6))
if (!IsBetweenA2B(z, -cyHole.Radius, br.Thickness + cyHole.Radius, 1e-6))
return;
let sp = position.clone().add(d.Normal.multiplyScalar(-CanDrawHoleFuzz).applyMatrix4(roMat)).setZ(0); //加长线(以便加大容差)
let ep = position.clone().add(d.Normal.multiplyScalar(d.Height + CanDrawHoleFuzz).applyMatrix4(roMat)).setZ(0); //加长线
let sp = position.clone().add(cyHole.Normal.multiplyScalar(-CanDrawHoleFuzz).applyMatrix4(roMat)).setZ(0); //加长线(以便加大容差)
let ep = position.clone().add(cyHole.Normal.multiplyScalar(cyHole.Height + CanDrawHoleFuzz).applyMatrix4(roMat)).setZ(0); //加长线
let line = new exports.Line(sp, ep);
let pt = outline.IntersectWith(line, 0)[0];
if (!pt) {
@@ -19218,20 +19234,20 @@ var Production;
InvertPosition(position, br.Thickness);
InvertPosition(endPt, br.Thickness);
}
else if (d.Type === exports.GangDrillType.Wood) {
else if (cyHole.Type === exports.GangDrillType.Wood) {
if (!outline.PtInCurve(position.clone().setZ(0)))
return;
face = position.z > 0 ? FaceDirection.Front : FaceDirection.Back;
holes = data.frontBackHoles;
if (position.z > 0) {
let z1 = position.z - d.Height;
let z1 = position.z - cyHole.Height;
if (z1 > 0 && z1 < br.Thickness) {
depth = br.Thickness - z1;
isPush = true;
}
}
else {
let z1 = position.z + d.Height;
let z1 = position.z + cyHole.Height;
if (z1 > 0 && z1 < br.Thickness) {
depth = z1;
isPush = true;
@@ -19241,22 +19257,22 @@ var Production;
}
}
else {
if (isParallelTo(d.Normal, brNormal, CanDrawHoleFuzz)) {
if (!IsBetweenA2B(position.x, -d.Radius, br.Width + d.Radius, CanDrawHoleFuzz)
|| !IsBetweenA2B(position.y, -d.Radius, br.Height + d.Radius, CanDrawHoleFuzz)
if (isParallelTo(cyHole.Normal, brNormal, CanDrawHoleFuzz)) {
if (!IsBetweenA2B(position.x, -cyHole.Radius, br.Width + cyHole.Radius, CanDrawHoleFuzz)
|| !IsBetweenA2B(position.y, -cyHole.Radius, br.Height + cyHole.Radius, CanDrawHoleFuzz)
|| !isIntersect2(0, br.Thickness, position.z, pos2.z, -CanDrawHoleFuzz)
|| !HoleInBoard(position.clone().setZ(0), d.Radius, outline, true))
|| !HoleInBoard(position.clone().setZ(0), cyHole.Radius, outline, true))
return;
position.sub(offsetTanslation);
holes = data.frontBackHoles;
face = !equalv3(d.Normal, brNormal, CanDrawHoleFuzz) ? FaceDirection.Front : FaceDirection.Back;
face = !equalv3(cyHole.Normal, brNormal, CanDrawHoleFuzz) ? FaceDirection.Front : FaceDirection.Back;
isPush = true;
}
}
isPush && holes.push({
type: d.Type,
type: cyHole.Type,
position,
radius: d.Radius,
radius: cyHole.Radius,
depth,
face,
endPt,
@@ -28453,6 +28469,7 @@ exports.Database = class Database {
this.IsDefaultDatabase = IsDefaultDatabase;
//相机快照记录
this.CameraSnapshoots = [];
this.ExtendedData = null;
this.idIndex = 1;
this.idMap = new Map();
this.ModelSpace = new exports.BlockTableRecord().SetOwnerDatabase(this);
@@ -28523,6 +28540,7 @@ exports.Database = class Database {
HostApplicationServices.CurrentDimStyle = this.DimStyleTable.Current;
}
Destroy() {
this.ExtendedData = null;
this.idMap.clear();
this.ModelSpace.Destroy();
this.LayoutSpace.Destroy();
@@ -28551,7 +28569,7 @@ exports.Database = class Database {
}
//#region Serialize
FileWrite(file = new CADFiler) {
file.Write(10); //ver;
file.Write(11); //ver;
file.Write(this.idIndex);
this.ModelSpace.WriteFile(file);
this.TextureTable.WriteFile(file);
@@ -28566,6 +28584,7 @@ exports.Database = class Database {
for (let r of this.CameraSnapshoots)
r.WriteFile(file);
this.DimStyleTable.WriteFile(file);
file.Write(this.ExtendedData);
return file;
}
FileRead(file) {
@@ -28623,6 +28642,8 @@ exports.Database = class Database {
for (let e of this.LayoutSpace.EntityCol.Objects)
e.Owner = this.LayoutSpace.objectId;
}
if (ver > 10)
this.ExtendedData = file.Read();
this.SettingDefaultStyleAndMaterial();
this.hm.doing = false;
exports.Entity.__ReadFileIng__ = false;
@@ -33857,6 +33878,8 @@ exports.ViewportEntity = ViewportEntity_1 = class ViewportEntity extends exports
this._width = file.Read();
this._height = file.Read();
this._renderType = file.Read();
if (ver === 2 && this._renderType === exports.RenderType.Jig)
this._renderType = exports.RenderType.Wireframe;
let count = file.Read();
this._HideObjectIds.clear();
for (let i = 0; i < count; i++) {
@@ -33878,7 +33901,7 @@ exports.ViewportEntity = ViewportEntity_1 = class ViewportEntity extends exports
}
WriteFile(file) {
super.WriteFile(file);
file.Write(2);
file.Write(3);
this.camera.WriteFile(file);
file.Write(this._width);
file.Write(this._height);