|
|
@ -1,13 +1,15 @@
|
|
|
|
import * as THREE from 'three';
|
|
|
|
import * as THREE from 'three';
|
|
|
|
import { Object3D } from 'three';
|
|
|
|
import { Object3D, Vector2, Vector3 } from 'three';
|
|
|
|
import * as verb from 'verb-nurbs-web';
|
|
|
|
import { Vec2DTo3D } from '../Common/CurveUtils';
|
|
|
|
|
|
|
|
|
|
|
|
import { Entity } from '../DatabaseServices/Entity';
|
|
|
|
import { Entity } from '../DatabaseServices/Entity';
|
|
|
|
|
|
|
|
import { Line } from '../DatabaseServices/Line';
|
|
|
|
import { GripScene } from '../GraphicsSystem/GripScene';
|
|
|
|
import { GripScene } from '../GraphicsSystem/GripScene';
|
|
|
|
|
|
|
|
import { IntersectOption } from '../GraphicsSystem/IntersectWith';
|
|
|
|
import { PreViewer } from '../GraphicsSystem/PreViewer';
|
|
|
|
import { PreViewer } from '../GraphicsSystem/PreViewer';
|
|
|
|
import { Viewer } from '../GraphicsSystem/Viewer';
|
|
|
|
import { Viewer } from '../GraphicsSystem/Viewer';
|
|
|
|
import { SelectSetBase, SelectType } from './SelectSet';
|
|
|
|
import { SelectSetBase, SelectType } from './SelectSet';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 矩形选区
|
|
|
|
* 矩形选区
|
|
|
|
* 如果图形无法选择,那么注意该图形是否调用计算图形的包围球.
|
|
|
|
* 如果图形无法选择,那么注意该图形是否调用计算图形的包围球.
|
|
|
@ -20,7 +22,7 @@ export class SelectBox extends SelectSetBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private m_SelectBox: THREE.Box2 = new THREE.Box2();
|
|
|
|
private m_SelectBox: THREE.Box2 = new THREE.Box2();
|
|
|
|
private m_RectLines = new Array<verb.core.PolylineData>();
|
|
|
|
private m_RectLines: Line[] = [];
|
|
|
|
private m_Frustom: THREE.Frustum = new THREE.Frustum();
|
|
|
|
private m_Frustom: THREE.Frustum = new THREE.Frustum();
|
|
|
|
|
|
|
|
|
|
|
|
private m_bIsPerCamera;
|
|
|
|
private m_bIsPerCamera;
|
|
|
@ -33,24 +35,22 @@ export class SelectBox extends SelectSetBase
|
|
|
|
|
|
|
|
|
|
|
|
this.m_SelectBox.setFromPoints([p1, p2]);
|
|
|
|
this.m_SelectBox.setFromPoints([p1, p2]);
|
|
|
|
|
|
|
|
|
|
|
|
let px1 = this.m_SelectBox.min.toArray();
|
|
|
|
let px1 = Vec2DTo3D(this.m_SelectBox.min);
|
|
|
|
let px3 = this.m_SelectBox.max.toArray();
|
|
|
|
let px3 = Vec2DTo3D(this.m_SelectBox.max);
|
|
|
|
px1.push(0);
|
|
|
|
let px2 = new Vector3(this.m_SelectBox.max.x, this.m_SelectBox.min.y, 0);
|
|
|
|
px3.push(0);
|
|
|
|
let px4 = new Vector3(this.m_SelectBox.min.x, this.m_SelectBox.max.y, 0);
|
|
|
|
let px2 = [this.m_SelectBox.max.x, this.m_SelectBox.min.y, 0];
|
|
|
|
|
|
|
|
let px4 = [this.m_SelectBox.min.x, this.m_SelectBox.max.y, 0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.m_RectLines.push(new verb.core.PolylineData([px1, px2], [0, 1]));
|
|
|
|
this.m_RectLines.push(new Line(px1, px2));
|
|
|
|
this.m_RectLines.push(new verb.core.PolylineData([px2, px3], [0, 1]));
|
|
|
|
this.m_RectLines.push(new Line(px2, px3));
|
|
|
|
this.m_RectLines.push(new verb.core.PolylineData([px3, px4], [0, 1]));
|
|
|
|
this.m_RectLines.push(new Line(px3, px4));
|
|
|
|
this.m_RectLines.push(new verb.core.PolylineData([px4, px1], [0, 1]));
|
|
|
|
this.m_RectLines.push(new Line(px4, px1));
|
|
|
|
|
|
|
|
|
|
|
|
//init frustom.
|
|
|
|
//init frustom.
|
|
|
|
|
|
|
|
|
|
|
|
let camera = this.m_Viewer.Camera;
|
|
|
|
let camera = this.m_Viewer.Camera;
|
|
|
|
if (camera instanceof THREE.OrthographicCamera || camera instanceof THREE.PerspectiveCamera)
|
|
|
|
if (camera instanceof THREE.OrthographicCamera || camera instanceof THREE.PerspectiveCamera)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let size = this.m_SelectBox.getSize();
|
|
|
|
let size = this.m_SelectBox.getSize(new Vector2());
|
|
|
|
|
|
|
|
|
|
|
|
camera.setViewOffset(view.Width, view.Height, this.m_SelectBox.min.x, this.m_SelectBox.min.y, size.x, size.y);
|
|
|
|
camera.setViewOffset(view.Width, view.Height, this.m_SelectBox.min.x, this.m_SelectBox.min.y, size.x, size.y);
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
@ -139,7 +139,7 @@ export class SelectBox extends SelectSetBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let p1 = screenPts[index1];
|
|
|
|
let p1 = screenPts[index1];
|
|
|
|
let p2 = screenPts[index2];
|
|
|
|
let p2 = screenPts[index2];
|
|
|
|
let line = new verb.core.PolylineData([[p1.x, p1.y, 0], [p2.x, p2.y, 0]], [0, 1]);
|
|
|
|
let line = new Line(p1.clone(), p2.clone());
|
|
|
|
|
|
|
|
|
|
|
|
//如果是透视相机,则需要 裁剪算法. 保证线在视图内部
|
|
|
|
//如果是透视相机,则需要 裁剪算法. 保证线在视图内部
|
|
|
|
if (this.m_bIsPerCamera)
|
|
|
|
if (this.m_bIsPerCamera)
|
|
|
@ -155,19 +155,19 @@ export class SelectBox extends SelectSetBase
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
else if (!px1InFrusum || !px2InFrusum)
|
|
|
|
else if (!px1InFrusum || !px2InFrusum)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let intersecPt = nearPlan.intersectLine(new THREE.Line3(px1, px2));
|
|
|
|
let intersecPt = nearPlan.intersectLine(new THREE.Line3(px1, px2), new Vector3());
|
|
|
|
this.WorldToScreenPoint(intersecPt);
|
|
|
|
this.WorldToScreenPoint(intersecPt);
|
|
|
|
|
|
|
|
|
|
|
|
if (!px1InFrusum)
|
|
|
|
if (!px1InFrusum)
|
|
|
|
line.points[0] = [intersecPt.x, intersecPt.y, 0];
|
|
|
|
line.StartPoint = intersecPt;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
line.points[1] = [intersecPt.x, intersecPt.y, 0];
|
|
|
|
line.EndPoint = intersecPt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (let l of this.m_RectLines)
|
|
|
|
for (let l of this.m_RectLines)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let ins = verb.eval.Intersect.polylines(l, line, 1e-8)
|
|
|
|
let ins = l.IntersectWith(line, IntersectOption.OnBothOperands);
|
|
|
|
if (ins.length > 0)
|
|
|
|
if (ins.length > 0)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -186,6 +186,7 @@ export class SelectBox extends SelectSetBase
|
|
|
|
this.WorldToScreenPoint(p);
|
|
|
|
this.WorldToScreenPoint(p);
|
|
|
|
if (this.ContainerScreenPoint(p))
|
|
|
|
if (this.ContainerScreenPoint(p))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
p.z = 0;
|
|
|
|
screenPts.push(p);
|
|
|
|
screenPts.push(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|