优化:仅复制五金后,如果和板不在相交(容差10),那么不再作为关联五金 fix #I7CMSL

pull/2240/MERGE
ChenX 1 year ago
parent e312df83ed
commit 1c1347d462

@ -128,7 +128,7 @@
"react-virtualized-auto-sizer": "^1.0.6",
"react-window": "^1.8.7",
"stats.js": "^0.17.0",
"three": "npm:three-cf@0.122.4",
"three": "npm:three-cf@0.122.5",
"xaop": "^2.0.0"
},
"resolutions": {

@ -1,4 +1,5 @@
import { Intent } from '@blueprintjs/core';
import { OBB } from 'three/examples/jsm/math/OBB';
import { app } from '../ApplicationServices/Application';
import { Log, LogType } from '../Common/Log';
import { DuplicateRecordCloning } from '../Common/Status';
@ -300,31 +301,39 @@ export class Command_Copy implements Command
}
else if (e instanceof HardwareCompositeEntity)//五金
{
//如果仅仅复制了五金,但是没有复制五金关联的板(复合板),我们对它进行重新关联
let oldId = GetOldObjectId(e.Id);
let oldE = oldId.Object as HardwareCompositeEntity;
let newEObb: OBB;
for (let id of oldE.RelevanceBoards)
{
if (!id || id.IsErase) continue;
let ent = id.Object;
if (ent instanceof Board)//只复制了五金 却没复制板
{
if (!olds.has(ent))
let ent = id.Object as Entity;
if (olds.has(ent)) continue;//复制了五金 也复制了板
//我们求obb 如果不相交,我们不再关联它
newEObb = newEObb || e.OBB;
let entObb = ent.OBB;
entObb.halfSize.addScalar(10);
if (!entObb.intersectsOBB(newEObb))
continue;
//只复制了五金 却没复制板(或复合板)
if (ent instanceof Board)
{
e.RelevanceBoards.push(ent.Id);
ent.RelativeHardware.push(e.Id);
}
}
else if (ent instanceof HardwareCompositeEntity) //复合板
{
if (!olds.has(ent))
{
e.RelevanceBoards.push(ent.Id);
ent.RelevanceHardware.push(e.Id);
}
}
}
}
else if (e instanceof HardwareTopline)//顶线不需要
{
}

@ -11,7 +11,7 @@ import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { Region } from "../../DatabaseServices/Entity/Region";
import { TemplateRecord } from "../../DatabaseServices/Template/TemplateRecord";
import { AsVector2, equaln, equalnn, isParallelTo, isPerpendicularityTo, midPoint, ZAxis } from "../../Geometry/GeUtils";
import { OBB } from "../../Geometry/OBB/obb";
import { GetObbFromOcsSize } from "../../Geometry/OBB/obb";
import { BoolOpeartionType } from "../../GraphicsSystem/BoolOperateUtils";
import { TestDraw } from "../test/TestUtil";
@ -246,7 +246,7 @@ export class DimBoards
let ocs = new Matrix4().makeBasis(_x, _y, _z).setPosition(c.StartPoint.setZ(-5000))
.premultiply(spaceFrontCS);
let cuObb = new OBB(ocs, new Vector3(c.Length, 20, 10000));
let cuObb = GetObbFromOcsSize(ocs, new Vector3(c.Length, 20, 10000));
for (let br of brs)
{

@ -1,5 +1,8 @@
import { Geom3 } from "@jscad/modeling/src/geometries/types";
import { Box3, Material, Mesh } from "three";
import { OBB } from "three/examples/jsm/math/OBB";
import { FuzzyFactory } from "../csg/core/FuzzyFactory";
import { CSG2Geometry2, Geometry2CSG2 } from "../csg/core/Geometry2CSG";
import { ExtrudeHole } from "../DatabaseServices/3DSolid/ExtrudeHole";
import { SweepSolid } from "../DatabaseServices/3DSolid/SweepSolid";
import { Board } from "../DatabaseServices/Entity/Board";
@ -11,11 +14,8 @@ import { ProcessingGroupRecord } from "../DatabaseServices/ProcessingGroup/Proce
import { TemplateLatticeRecord } from "../DatabaseServices/Template/ProgramTempate/TemplateLatticeRecord";
import { TemplateWineRackRecord } from "../DatabaseServices/Template/ProgramTempate/TemplateWineRackRecord";
import { BoxIsSolid } from "../Geometry/Box";
import { OBB } from "../Geometry/OBB/obb";
import { FuzzyFactory } from "../csg/core/FuzzyFactory";
import { CSG2Geometry2, Geometry2CSG2 } from "../csg/core/Geometry2CSG";
import { CSGIntersect } from "./CSGIntersect";
import { ColorMaterial } from "./ColorPalette";
import { CSGIntersect } from "./CSGIntersect";
import { Log, LogType } from "./Log";
import { Sleep } from "./Sleep";

@ -22,7 +22,6 @@ import { GenUVForWorld } from "../Entity/GenUVForWorld";
import { Polyline } from "../Entity/Polyline";
import { PhysicalMaterialRecord } from "../PhysicalMaterialRecord";
import { Shape } from "../Shape";
import { OBB } from './../../Geometry/OBB/obb';
import { Hole } from "./Hole";
@Factory
@ -451,11 +450,6 @@ export class ExtrudeHole extends Hole
mesh.material = ColorMaterial.GetConceptualMaterial(this.ColorIndex);
}
}
get OBB(): OBB
{
let size = this.ContourCurve.BoundingBox.getSize(new Vector3).setZ(this.Height);
return new OBB(this.OCS, size.multiplyScalar(0.5));
}
ReadFile(file: CADFiler)
{
super.ReadFile(file);

@ -19,7 +19,6 @@ import { Polyline } from '../Entity/Polyline';
import { IsPointInPolyLine } from '../PointInPolyline';
import { Spline } from "../Spline";
import { FixIndex } from './../../Common/Utils';
import { OBB } from './../../Geometry/OBB/obb';
import { PlaneExt } from './../../Geometry/Plane';
@Factory
@ -295,12 +294,6 @@ export class SweepSolid extends Entity
return geom.boundingBox.clone().applyMatrix4(this._Matrix);
}
get OBB(): OBB
{
let box = this.BoundingBox;
let size = box.getSize(new Vector3);
return new OBB(MoveMatrix(box.min), size.multiplyScalar(0.5));
}
GetObjectSnapPoints(
snapMode: ObjectSnapMode,
pickPoint: Vector3,

@ -1,4 +1,5 @@
import { Material, Matrix3, Matrix4, MeshStandardMaterial, Object3D, Vector3 } from 'three';
import { OBB } from 'three/examples/jsm/math/OBB';
import { iaop } from 'xaop';
import { HostApplicationServices } from '../../ApplicationServices/HostApplicationServices';
import { DisposeThreeObj, Object3DRemoveAll } from '../../Common/Dispose';
@ -152,6 +153,16 @@ export class Entity extends CADObject
*/
Explode(): Entity[] { return []; }
get OBB(): OBB
{
let ocs = this.OCSNoClone;
let box = this.BoundingBoxInOCS;
let center = box.getCenter(new Vector3);
center.applyMatrix4(ocs);
let size = box.getSize(new Vector3).multiplyScalar(0.5);
return new OBB(center, size, new Matrix3().setFromMatrix4(ocs));
}
/**
* .
*/

@ -21,7 +21,6 @@ import { FastExtrudeEdgeGeometry, FastExtrudeEdgeGeometryOfShape, FastWireframe
import { EdgesGeometry } from "../../Geometry/EdgeGeometry";
import { ExtrudeGeometryBuilder } from "../../Geometry/ExtrudeMeshGeomBuilder/ExtrudeEdgeGeometry2";
import { AsVector2, equaln, equalv2, equalv3, IdentityMtx4, isIntersect, isParallelTo, isPerpendicularityTo, MoveMatrix, XAxis, YAxis, ZAxis, ZeroVec } from "../../Geometry/GeUtils";
import { OBB } from "../../Geometry/OBB/obb";
import { ScaleUV, ScaleUV2 } from "../../Geometry/UVUtils";
import { RenderType } from "../../GraphicsSystem/RenderType";
import { BlockTableRecord } from "../BlockTableRecord";
@ -157,11 +156,6 @@ export class ExtrudeSolid extends Entity
return new Box3Ext().setFromPoints([new Vector3, new Vector3(this.width, this.height, this.thickness)]);
}
get OBB(): OBB
{
return new OBB(this.OCS, new Vector3(this.width, this.height, this.thickness).multiplyScalar(0.5));
}
get GroovesAddLength()
{
return this.groovesAddLength;

@ -1,249 +1,15 @@
import { Vector3, Matrix4 } from 'three';
// Quote from:
// https://github.com/Mugen87/yume/blob/master/src/javascript/engine/etc/OBB.js
// 即obb.js(本项目中已存在)
import { Matrix3, Matrix4, Vector3 } from 'three';
import { OBB } from "three/examples/jsm/math/OBB";
// Reference material:
//https://stackoverflow.com/questions/28499800/oriented-box-intersection-in-threejs
//http://www.cnblogs.com/iamzhanglei/archive/2012/06/07/2539751.html
//https://github.com/Mugen87/yume/blob/master/src/javascript/engine/etc/OBB.js
export class OBB
{
_EPSILON = 1e-3;
public center: Vector3;
constructor(public ocs: Matrix4, public halfSizes: Vector3)
{
this.center = halfSizes.clone().applyMatrix4(ocs);
}
intersectsOBB(obb: OBB, is2D?: boolean, ucsInv?: Matrix4): boolean
{
let newCenter: Vector3;
let newObbCenter: Vector3;
let cs: Matrix4;
let obbcs: Matrix4;
if (is2D)
{
let mtx1 = new Matrix4().multiplyMatrices(ucsInv, this.ocs);
let mtx2 = new Matrix4().multiplyMatrices(ucsInv, obb.ocs);
cs = mtx1;
obbcs = mtx2;
cs.elements[14] = 0;
obbcs.elements[14] = 0;
newCenter = this.halfSizes.clone().applyMatrix4(cs);
newObbCenter = obb.halfSizes.clone().applyMatrix4(obbcs);
}
let xAxisA = new Vector3();
let yAxisA = new Vector3();
let zAxisA = new Vector3();
let xAxisB = new Vector3();
let yAxisB = new Vector3();
let zAxisB = new Vector3();
let translation = new Vector3();
let vector = new Vector3();
let axisA: Vector3[] = [];
let axisB: Vector3[] = [];
let rotationMatrix = [[], [], []];
let rotationMatrixAbs = [[], [], []];
let halfSizeA: number, halfSizeB: number;
let t: number, i: number;
// extract each axis
(cs ?? this.ocs).extractBasis(xAxisA, yAxisA, zAxisA);
(obbcs ?? obb.ocs).extractBasis(xAxisB, yAxisB, zAxisB);
// push basis vectors into arrays, so you can access them via indices
axisA.push(xAxisA, yAxisA, zAxisA);
axisB.push(xAxisB, yAxisB, zAxisB);
// get displacement vector
vector.subVectors(newObbCenter ?? obb.center, newCenter ?? this.center);
// express the translation vector in the coordinate frame of the current
// OBB (this)
for (i = 0; i < 3; i++)
{
translation.setComponent(i, vector.dot(axisA[i]));
}
// generate a rotation matrix that transforms from world space to the
// OBB's coordinate space
for (i = 0; i < 3; i++)
{
for (let j = 0; j < 3; j++)
{
rotationMatrix[i][j] = axisA[i].dot(axisB[j]);
rotationMatrixAbs[i][j] = Math.abs(rotationMatrix[i][j]) + this._EPSILON;
}
}
// test the three major axes of this OBB
for (i = 0; i < 3; i++)
{
vector.set(rotationMatrixAbs[i][0], rotationMatrixAbs[i][1], rotationMatrixAbs[i][2]);
halfSizeA = this.halfSizes.getComponent(i);
halfSizeB = obb.halfSizes.dot(vector);
if (Math.abs(translation.getComponent(i)) > halfSizeA + halfSizeB)
{
return false;
}
}
// test the three major axes of other OBB
for (i = 0; i < 3; i++)
{
vector.set(rotationMatrixAbs[0][i], rotationMatrixAbs[1][i], rotationMatrixAbs[2][i]);
halfSizeA = this.halfSizes.dot(vector);
halfSizeB = obb.halfSizes.getComponent(i);
vector.set(rotationMatrix[0][i], rotationMatrix[1][i], rotationMatrix[2][i]);
t = translation.dot(vector);
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
}
// test the 9 different cross-axes
// A.x <cross> B.x
halfSizeA = this.halfSizes.y * rotationMatrixAbs[2][0] + this.halfSizes.z * rotationMatrixAbs[1][0];
halfSizeB = obb.halfSizes.y * rotationMatrixAbs[0][2] + obb.halfSizes.z * rotationMatrixAbs[0][1];
t = translation.z * rotationMatrix[1][0] - translation.y * rotationMatrix[2][0];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.x < cross> B.y
halfSizeA = this.halfSizes.y * rotationMatrixAbs[2][1] + this.halfSizes.z * rotationMatrixAbs[1][1];
halfSizeB = obb.halfSizes.x * rotationMatrixAbs[0][2] + obb.halfSizes.z * rotationMatrixAbs[0][0];
t = translation.z * rotationMatrix[1][1] - translation.y * rotationMatrix[2][1];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.x <cross> B.z
halfSizeA = this.halfSizes.y * rotationMatrixAbs[2][2] + this.halfSizes.z * rotationMatrixAbs[1][2];
halfSizeB = obb.halfSizes.x * rotationMatrixAbs[0][1] + obb.halfSizes.y * rotationMatrixAbs[0][0];
t = translation.z * rotationMatrix[1][2] - translation.y * rotationMatrix[2][2];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.y <cross> B.x
halfSizeA = this.halfSizes.x * rotationMatrixAbs[2][0] + this.halfSizes.z * rotationMatrixAbs[0][0];
halfSizeB = obb.halfSizes.y * rotationMatrixAbs[1][2] + obb.halfSizes.z * rotationMatrixAbs[1][1];
t = translation.x * rotationMatrix[2][0] - translation.z * rotationMatrix[0][0];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.y <cross> B.y
halfSizeA = this.halfSizes.x * rotationMatrixAbs[2][1] + this.halfSizes.z * rotationMatrixAbs[0][1];
halfSizeB = obb.halfSizes.x * rotationMatrixAbs[1][2] + obb.halfSizes.z * rotationMatrixAbs[1][0];
t = translation.x * rotationMatrix[2][1] - translation.z * rotationMatrix[0][1];
if (Math.abs(t) > halfSizeA + halfSizeB)
/**
* @param ocs
* @param size
* @returns OBB
*/
export function GetObbFromOcsSize(ocs: Matrix4, size: Vector3): OBB
{
return false;
}
// A.y <cross> B.z
halfSizeA = this.halfSizes.x * rotationMatrixAbs[2][2] + this.halfSizes.z * rotationMatrixAbs[0][2];
halfSizeB = obb.halfSizes.x * rotationMatrixAbs[1][1] + obb.halfSizes.y * rotationMatrixAbs[1][0];
t = translation.x * rotationMatrix[2][2] - translation.z * rotationMatrix[0][2];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.z <cross> B.x
halfSizeA = this.halfSizes.x * rotationMatrixAbs[1][0] + this.halfSizes.y * rotationMatrixAbs[0][0];
halfSizeB = obb.halfSizes.y * rotationMatrixAbs[2][2] + obb.halfSizes.z * rotationMatrixAbs[2][1];
t = translation.y * rotationMatrix[0][0] - translation.x * rotationMatrix[1][0];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.z <cross> B.y
halfSizeA = this.halfSizes.x * rotationMatrixAbs[1][1] + this.halfSizes.y * rotationMatrixAbs[0][1];
halfSizeB = obb.halfSizes.x * rotationMatrixAbs[2][2] + obb.halfSizes.z * rotationMatrixAbs[2][0];
t = translation.y * rotationMatrix[0][1] - translation.x * rotationMatrix[1][1];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// A.z <cross> B.z
halfSizeA = this.halfSizes.x * rotationMatrixAbs[1][2] + this.halfSizes.y * rotationMatrixAbs[0][2];
halfSizeB = obb.halfSizes.x * rotationMatrixAbs[2][1] + obb.halfSizes.y * rotationMatrixAbs[2][0];
t = translation.y * rotationMatrix[0][2] - translation.x * rotationMatrix[1][2];
if (Math.abs(t) > halfSizeA + halfSizeB)
{
return false;
}
// no separating axis exists, so the two OBB don't intersect
return true;
}
// setFromObject(obj: THREE.Mesh): OBB;
// setFromAABB(aabb: THREE.Box3): OBB;
// setFromSphere(sphere: THREE.Shape): OBB;
// closestPoint(point: THREE.Vector3): THREE.Vector3
// isPointContained(point: THREE.Vector3): boolean
// isAABBContained(aabb: THREE.Box3): boolean
// isLineContained(line: THREE.Line3): boolean
// isTriangleContained(tarianlg: THREE.Triangle): boolean
// intersectsAABB(box: THREE.Box3): boolean
// intersectsSphere(sphere: THREE.Sphere): boolean
// intersectsOBB(box: OBB): boolean;
// intersectsPlane(plane: Plane): boolean
// intersectsRay(ray: Ray): boolean
// intersectRay(ray: Ray): Vector3
// intersectSphere(sphere: Sphere): Vector3
// size(optionalTarget: Vector3): Vector3
// translate(offset: Vector3): OBB
// copy(obb: OBB): OBB
// clone(obb: OBB): OBB
size = size.clone().multiplyScalar(0.5);
let center = size.clone().applyMatrix4(ocs);
return new OBB(center, size, new Matrix3().setFromMatrix4(ocs));
}

Loading…
Cancel
Save