diff --git a/__test__/quokka.test.ts b/__test__/quokka.test.ts new file mode 100644 index 000000000..dde52f0ce --- /dev/null +++ b/__test__/quokka.test.ts @@ -0,0 +1,67 @@ +import * as THREE from 'three'; + +import { GeUtils } from "../src/Geometry/GeUtils" + +let v = new THREE.Vector3(1, 0, 0); + +let v2 = new THREE.Vector3(1, 0.1, 0) + + +let an = v.angleTo(v2); + +console.log('an: ', an); + + + +console.log(an); + +console.log(v.angleTo(v2)); + +console.log(Math.PI * 0.25); + + +console.log(v); +console.log(v2); + +console.log(v.dot(v2)); + +function fixAngle(an) +{ + let pi4 = Math.PI * 0.5; + let rem = an % pi4; + if (rem < 0.1) + { + an -= rem; + } + else + { + an += 0.2; + rem = an % pi4; + if (rem < 0.1) + { + an -= rem; + } + else + { + an -= 0.2 + } + } + return an; +} + +an = fixAngle(an); + +console.log(an); + +GeUtils.angle(v, an, 1); + +console.log(v); + +console.log(fixAngle(Math.PI / 2 + 0.0)); +console.log(fixAngle(Math.PI / 2 + 0.05)); + +console.log(Math.PI % Math.PI); + + + +console.log(fixAngle(Math.PI / 2 + 0.05) % Math.PI / 2); diff --git a/src/Editor/Editor.ts b/src/Editor/Editor.ts index 33d3509ea..78969043b 100644 --- a/src/Editor/Editor.ts +++ b/src/Editor/Editor.ts @@ -13,6 +13,7 @@ import { KeyBoardControls } from './KeyBoardControls'; import { MouseControls } from './MouseControls'; import { PromptPointResult, PromptStatus } from './PromptResult'; import { SelectControls } from './SelectControls'; +import { GeUtils } from '../Geometry/GeUtils'; //TODO: 增加鼠标状态. 鼠标位置. export class Editor @@ -39,7 +40,7 @@ export class Editor this.m_InputState = InputState.GetPoint; let retValue = new PromptPointResult(); - let removeSnap = this.Snap(); + let removeSnap = this.Snap(prompt ? prompt.BasePoint : undefined); let res = new Promise((resolve, reject) => { let line: Line, removeDrag; @@ -139,10 +140,57 @@ export class Editor } noSnapList = new Set(); - Snap() + Snap(basePoint?: THREE.Vector3) { let testSnap = () => { + if (basePoint) + { + function fixAngle(an) + { + let pi2 = Math.PI * 0.5; + let rem = an % pi2; + if (rem < 0.1) + { + an -= rem; + } + else + { + an += 0.2; + rem = an % pi2; + if (rem < 0.1) + { + an -= rem; + } + else + { + an -= 0.2 + } + } + return an; + } + let p = this.m_MouseCtrl.m_CurMousePointWCS.clone().sub(basePoint); + + let an = Math.atan2(p.y, p.x); + if (an < 0) an += Math.PI * 2; + an = fixAngle(an); + console.log('an: ', an); + + + if (an % (Math.PI * 0.5) < 0.01) + { + + let ptC = basePoint.clone(); + GeUtils.angle(ptC, an, basePoint.dot(this.m_MouseCtrl.m_CurMousePointWCS)); + + + app.m_Viewer.WorldToScreen(ptC); + app.m_CursorViewer.SerCursorPostion(ptC); + app.m_CursorViewer.render(); + return; + } + } + for (let obj of app.m_Viewer.m_Scene.children) { if (this.noSnapList.has(obj)) diff --git a/src/Editor/SelectControls.ts b/src/Editor/SelectControls.ts index 684aa9ee3..e7cecc824 100644 --- a/src/Editor/SelectControls.ts +++ b/src/Editor/SelectControls.ts @@ -10,6 +10,7 @@ import { Editor } from './Editor'; import { SelectBox } from './SelectBox'; import { SelectPick } from './SelectPick'; import { SelectSet, SelectType } from './SelectSet'; +import { commandMachine } from './CommandMachine'; export class SelectControls { @@ -88,6 +89,10 @@ export class SelectControls let snapEvent = () => { + if (commandMachine.m_CommandIng) + { + return; + } for (let pts of app.m_Viewer.m_GripScene.children) { if (pts instanceof THREE.Points) diff --git a/src/Geometry/GeUtils.ts b/src/Geometry/GeUtils.ts index a783c40b7..226eb8bef 100644 --- a/src/Geometry/GeUtils.ts +++ b/src/Geometry/GeUtils.ts @@ -17,6 +17,12 @@ export namespace GeUtils return v1.manhattanDistanceTo(v2) < 1e-8; } + export function angle(v: THREE.Vector3, an: number, dis: number) + { + v.x += Math.cos(an) * dis; + v.y += Math.sin(an) * dis; + } + export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3 { if (dir.equals(cZeroVec))