!82 实现点实体和div功能

pull/83/MERGE
ChenX 6 years ago
parent e4b7ce6acd
commit bd4f42af39

@ -0,0 +1,98 @@
import { app } from '../ApplicationServices/Application';
import { Curve } from '../DatabaseServices/Curve';
import { Point } from '../DatabaseServices/Point';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus, PromptEntityResult } from '../Editor/PromptResult';
export class CMD_Divide implements Command
{
async exec()
{
let enRes = await app.m_Editor.GetEntity(
{
Msg: "请选择定数等分的对象",
KeyWordList: [{ key: "D", msg: "定数等分" }, { key: "S", msg: "定距等分" }]
});
switch (enRes.Status)
{
case PromptStatus.Cancel:
{
return;
}
case PromptStatus.Keyword:
{
if (enRes.StringResult == "D")//定数等分
{
await this.Divided(enRes);
}
else if (enRes.StringResult == "S")//定距等分
{
await this.Measured();
}
}
break;
case PromptStatus.OK:
{
await this.Divided(enRes);
}
break;
default:
break;
}
}
async Divided(enRes: PromptEntityResult)//定数等分
{
let numRes = await app.m_Editor.GetDistance({ Msg: "请输入段数" });
if (numRes.Status != PromptStatus.OK)
return;
let divCount = numRes.Value;
if (divCount === 0)
{
app.m_Editor.m_CommandStore.Prompt("您不能等分0");
return;
}
if (enRes.Entity instanceof Curve)
{
let cu = enRes.Entity;
let len = cu.Length;
let divLen = len / numRes.Value;
for (let i = 0; i < divCount - 1; i++)
{
let pt = cu.GetPointAtDistance(divLen * (i + 1));
let ptEnt = new Point(pt);
app.m_Database.ModelSpace.Append(ptEnt);
}
}
}
async Measured()//定距等分
{
let enRes = await app.m_Editor.GetEntity({ Msg: "请选择定距等分的对象" });
let numRes = await app.m_Editor.GetDistance({ Msg: "请指定分段的长度" });
let divLen = numRes.Value;
if (divLen === 0)
{
app.m_Editor.m_CommandStore.Prompt("分段长度不能为0");
return;
}
if (enRes.Entity instanceof Curve)
{
let cu = enRes.Entity;
let len = cu.Length;
if (divLen > len)
{
app.m_Editor.m_CommandStore.Prompt("分段长度不能超过对象长度");
return;
}
let divCount = len / divLen;
for (let i = 0; i < divCount - 1; i++)
{
let pt = cu.GetPointAtDistance(divLen * (i + 1));
let ptEnt = new Point(pt);
app.m_Database.ModelSpace.Append(ptEnt);
}
}
}
}

@ -0,0 +1,17 @@
import { app } from '../ApplicationServices/Application';
import { Point } from '../DatabaseServices/Point';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus, PromptEntityResult } from '../Editor/PromptResult';
export class CMD_DrawPoint implements Command
{
async exec()
{
let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入或点取点的位置" });
if (ptRes.Status != PromptStatus.OK)
return;
let ptEnt = new Point(ptRes.Value);
app.m_Database.ModelSpace.Append(ptEnt);
}
}

@ -3,8 +3,8 @@ import { Box3, EllipseCurve, Geometry, Object3D, Vector3, Shape, Quaternion } fr
import { arrayLast, arrayRemoveDuplicateBySort } from '../Common/ArrayExt';
import { ColorMaterial } from '../Common/ColorPalette';
import { clamp } from '../Common/Utils';
import { Arc } from '../DatabaseServices/Arc';
import { angle, equaln, MoveMatrix, polar } from '../Geometry/GeUtils';
import { Arc } from './Arc';
import { MoveMatrix, angle, equaln, polar } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum';
import { IntersectCircleAndArc, IntersectCircleAndCircle, IntersectLineAndCircle, IntersectOption, IntersectPolylineAndCurve, reverseIntersectOption } from '../GraphicsSystem/IntersectWith';
import { Factory } from './CADFactory';

@ -0,0 +1,118 @@
import { AdditiveBlending, BufferGeometry, Float32BufferAttribute, Geometry, Object3D, Points, PointsMaterial, TextureLoader, Vector3 } from "three";
import { MoveMatrix } from "../Geometry/GeUtils";
import { RenderType } from "../GraphicsSystem/Enum";
import { Factory } from "./CADFactory";
import { CADFile } from "./CADFile";
import { Entity } from "./Entity";
let pointMaterial: PointsMaterial;
function LoadPointMaterial()
{
if (!pointMaterial)
{
let textureLoader = new TextureLoader();
pointMaterial = new PointsMaterial({
size: window.screen.height * 0.025,
map: textureLoader.load(require("../textures/ddptype/target.png")),
blending: AdditiveBlending,
depthTest: false,
transparent: true,
sizeAttenuation: false
});
}
return pointMaterial;
}
LoadPointMaterial();
@Factory
export class Point extends Entity
{
private m_Position: Vector3;
constructor(position: Vector3 = new Vector3())
{
super();
this.m_Position = position;
}
/**
* threejs,.
*
* @param {RenderType} [renderType=RenderType.Wireframe]
* @returns {Object3D} threejs.
* @memberof Entity
*/
protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
{
let geometry = new BufferGeometry();
geometry.addAttribute("position", new Float32BufferAttribute(this.m_Position.toArray(), 3));
return new Points(geometry, LoadPointMaterial());
}
private UpdateGeometry(geometry: Geometry)
{
}
/**
* ,,
*
* @param {RenderType} type
* @param {Object3D} en
* @memberof Entity
*/
UpdateDrawObject(type: RenderType, en: Object3D)
{
}
GetSnapPoints(): Array<Vector3>
{
return [this.m_Position.clone().applyMatrix4(this.OCS)];
}
MoveSnapPoints(indexList: number[], vec: Vector3)
{
if (indexList.length === 1)
{
this.WriteAllObjectRecord();
this.ApplyMatrix(MoveMatrix(vec));
}
}
GetStretchPoints(): Array<Vector3>
{
return this.GetSnapPoints();
}
/**
* ,Stretch
*
* @param {Array<number>} indexList .
* @param {Vector3} vec
* @memberof Entity
*/
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
{
this.MoveSnapPoints(indexList, vec);
}
//#region -------------------------File-------------------------
//对象从文件中读取数据,初始化自身
ReadFile(file: CADFile)
{
let ver = file.Read();
super.ReadFile(file);
this.m_Position.fromArray(file.Read());
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)
{
file.Write(1);
super.WriteFile(file);
file.Write(this.m_Position.toArray());
}
}

@ -68,6 +68,8 @@ import { Sweep } from '../Add-on/Sweep';
import { Command_Scale } from '../Add-on/Scale';
import { Command_Break } from '../Add-on/Break';
import { Command_Length } from '../Add-on/Length';
import { CMD_Divide } from '../Add-on/Divide';
import { CMD_DrawPoint } from '../Add-on/DrawPoint';
export function registerCommand()
{
@ -161,6 +163,8 @@ export function registerCommand()
commandMachine.RegisterCommand("dl", new TestDrawDirectionalLight());
commandMachine.RegisterCommand("oo", new OffsetX());
commandMachine.RegisterCommand("div", new CMD_Divide());
commandMachine.RegisterCommand("pt", new CMD_DrawPoint());
commandMachine.RegisterCommand("sl", new TestDrawSpotLight());
commandMachine.RegisterCommand("dal", new DrawAlignedDimension());

@ -1,15 +1,13 @@
import { Object3D, Vector3 } from 'three';
import * as THREE from 'three';
import { GripScene } from '../GraphicsSystem/GripScene';
import { Object3D, Points, Vector3 } from 'three';
import { PreViewer } from '../GraphicsSystem/PreViewer';
import { Viewer } from '../GraphicsSystem/Viewer';
import { SelectBox } from './SelectBox';
import { SelectType } from './SelectSet';
import { PreViewer } from '../GraphicsSystem/PreViewer';
function IsNotRayCaster(obj: THREE.Object3D)
{
return (!obj.visible || obj instanceof THREE.Line || obj instanceof GripScene);
return (!obj.visible || obj instanceof THREE.Line || obj instanceof Points);
}
/**
@ -54,8 +52,6 @@ export function PointPick(ptVcs: Vector3, view: Viewer | PreViewer, selectObject
if (pickObj)
return [pickObj];
let selectList = [];
let pCenter = new THREE.Vector2(ptVcs.x, ptVcs.y);
let selectSize = new THREE.Vector2(10, 10);
let minPt = pCenter.clone().sub(selectSize);

@ -154,7 +154,7 @@ export class SelectBox extends SelectSetBase
}
}
return this.m_BoxCheck.Check(p1, p2);
return this.m_BoxCheck.IsIntersectLine(p1, p2);
}
IntersectObject(obj: THREE.Object3D): Boolean
{

@ -1,6 +1,6 @@
import * as THREE from 'three';
import { ColorMaterial } from './../../Common/ColorPalette';
import { ColorMaterial } from '../../Common/ColorPalette';
import { AxisType } from './CoorAxes';
//构造一个旋转轴 ,供旋转变换控制器,或者其他地方使用

@ -12,7 +12,7 @@ import { Editor } from '../Editor';
import { PointPick } from '../PointPick';
import { PromptStatus } from '../PromptResult';
import { MatrixToPreViewMat } from '../UCSServices';
import { EditorService } from './../Editor';
import { EditorService } from '../Editor';
import { AxisType } from './CoorAxes';
import { RotateAxes } from './RotateAxes';
import { TranslateAxex } from './TranslateAxes';

@ -1,4 +1,4 @@
import { Box2, Vector2 } from "three";
import { Box2, Vector2, Math as Math3 } from "three";
interface Vec2
{
@ -30,11 +30,11 @@ function ComputeOutCode(x: number, y: number, box: Box2): number
export class BoxCheckIntersect
{
p1
p2
p3
p4
box
p1: Vec2;
p2: Vec2;
p3: Vec2;
p4: Vec2;
box: Box2;
constructor(box: Box2)
{
this.p1 = box.min;
@ -44,7 +44,7 @@ export class BoxCheckIntersect
this.box = box;
}
Check(p1: Vec2, p2: Vec2): boolean
IsIntersectLine(p1: Vec2, p2: Vec2): boolean
{
let code1 = ComputeOutCode(p1.x, p1.y, this.box);
let code2 = ComputeOutCode(p2.x, p2.y, this.box);
@ -64,6 +64,14 @@ export class BoxCheckIntersect
return false;
}
//ref https://yal.cc/rectangle-circle-intersection-test/
IsIntersectCircle(cen: Vec2, radius: number): boolean
{
let nearestX = Math3.clamp(cen.x, this.box.min.x, this.box.max.x);
let nearestY = Math3.clamp(cen.y, this.box.min.y, this.box.max.y);
return ((nearestX - cen.x) ** 2 + (nearestY - cen.y) ** 2) <= radius ** 2;
}
}

@ -1,4 +1,4 @@
import * as React from "React";
import * as React from "react";
import { CSSProperties } from 'react';
export class SelectMarquee extends React.Component<{}, null>{
@ -26,4 +26,4 @@ export class SelectMarquee extends React.Component<{}, null>{
</div>
);
}
}
}

@ -79,7 +79,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
// this.handleOnChangeIntelliSense(this.m_InputEl.value);
this.handleKeyboardEvent(e);
if (e.keyCode === KeyBoard.Space)
if (e.keyCode === KeyBoard.Space || e.keyCode === KeyBoard.Enter)
return true;
})
}

@ -1,4 +1,4 @@
import { observable } from "../../../node_modules/mobx";
import { observable } from "mobx";
class FilePanelStore
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

@ -86,7 +86,7 @@ const config: webpack.Configuration = {
},
//字体加载 blueprint
{
test: /\.(woff|woff2|jpg)$/,
test: /\.(woff|woff2|jpg|png)$/,
use: {
loader: 'url-loader',
options: {

Loading…
Cancel
Save