add dimension to origin
parent
a7c211a105
commit
ea32b0cc73
Binary file not shown.
|
@ -300,7 +300,7 @@ async function addSketch() {
|
|||
}
|
||||
|
||||
window.sc = new Scene(store)
|
||||
sc.loadState()
|
||||
// sc.loadState()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
import * as THREE from '../node_modules/three/src/Three';
|
||||
|
||||
import { _vec2, _vec3, raycaster, awaitPts } from './shared'
|
||||
import { _vec2, _vec3, raycaster, awaitPts, ptObj } from './shared'
|
||||
|
||||
import { drawOnClick1, drawOnClick2, drawPreClick2, drawClear } from './drawEvents'
|
||||
import { drawOnClick1, drawOnClick2, drawPreClick2, drawClear, drawPoint } from './drawEvents'
|
||||
import { onHover, onDrag, onPick, onRelease } from './mouseEvents'
|
||||
import { setCoincident } from './constraintEvents'
|
||||
import { setCoincident, setOrdinate } from './constraintEvents'
|
||||
import { get3PtArc } from './drawArc'
|
||||
import { replacer, reviver } from './utils'
|
||||
import { AxesHelper } from './sketchAxes'
|
||||
|
@ -47,13 +47,25 @@ class Sketch {
|
|||
this.l_id = 0;
|
||||
|
||||
this.constraints = new Map()
|
||||
this.c_id = 0;
|
||||
this.c_id = 1;
|
||||
|
||||
this.obj3d.add(new THREE.Group().add(new AxesHelper(0.5)));
|
||||
this.obj3d.add(new THREE.Group());
|
||||
this.obj3d.add(new THREE.Group());
|
||||
|
||||
this.labels = []
|
||||
|
||||
|
||||
const p1 = ptObj()
|
||||
p1.matrixAutoUpdate = false;
|
||||
p1.userData.constraints = []
|
||||
this.obj3d.add(p1)
|
||||
this.updatePointsBuffer()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
|
@ -138,7 +150,7 @@ class Sketch {
|
|||
this.canvas.addEventListener('pointermove', this.onHover)
|
||||
this.store.dispatch({ type: 'set-active-sketch', sketch: this.obj3d.name })
|
||||
|
||||
|
||||
|
||||
this.setDimLines()
|
||||
|
||||
window.sketcher = this
|
||||
|
@ -199,6 +211,14 @@ class Sketch {
|
|||
case 'd':
|
||||
this.drawDimension()
|
||||
this.mode = ""
|
||||
break;
|
||||
case 'p':
|
||||
this.canvas.addEventListener('pointerdown',
|
||||
(e) => {
|
||||
drawPoint.call(this, e)
|
||||
}
|
||||
)
|
||||
|
||||
break;
|
||||
case 'x':
|
||||
this.deleteSelected()
|
||||
|
@ -207,6 +227,18 @@ class Sketch {
|
|||
|
||||
setCoincident.call(this)
|
||||
|
||||
this.mode = ""
|
||||
break;
|
||||
case 'v':
|
||||
|
||||
setOrdinate.call(this, 0)
|
||||
|
||||
this.mode = ""
|
||||
break;
|
||||
case 'h':
|
||||
|
||||
setOrdinate.call(this, 1)
|
||||
|
||||
this.mode = ""
|
||||
break;
|
||||
|
||||
|
@ -340,12 +372,12 @@ class Sketch {
|
|||
|
||||
|
||||
updateBoundingSpheres() {
|
||||
for (let x = 3; x < this.obj3d.children.length; x++) {
|
||||
for (let x = 3; x < this.obj3d.children.length; x++) { // geometry boundign spheres
|
||||
const obj = this.obj3d.children[x]
|
||||
obj.geometry.computeBoundingSphere()
|
||||
}
|
||||
|
||||
for (let x = 0; x < this.obj3d.children[1].children.length; x++) {
|
||||
|
||||
for (let x = 0; x < this.obj3d.children[1].children.length; x++) { // dimension bounding sphere
|
||||
const obj = this.obj3d.children[1].children[x]
|
||||
obj.geometry.computeBoundingSphere()
|
||||
}
|
||||
|
@ -354,8 +386,8 @@ class Sketch {
|
|||
|
||||
raycaster.setFromCamera(
|
||||
_vec2.set(
|
||||
(e.clientX - this.rect.left)/ this.rect.width * 2 - 1,
|
||||
- (e.clientY - this.rect.top)/ this.rect.height * 2 + 1
|
||||
(e.clientX - this.rect.left) / this.rect.width * 2 - 1,
|
||||
- (e.clientY - this.rect.top) / this.rect.height * 2 + 1
|
||||
),
|
||||
this.camera
|
||||
);
|
||||
|
|
|
@ -1,22 +1,5 @@
|
|||
|
||||
|
||||
export function addDimension(ent1, ent2, distance) {
|
||||
|
||||
|
||||
// if (ent1.type ==)
|
||||
|
||||
this.constraints.set(++this.c_id,
|
||||
[
|
||||
'distance', distance,
|
||||
[p1, p2, -1, -1]
|
||||
]
|
||||
)
|
||||
|
||||
ent1.userData.constraints.push(this.c_id)
|
||||
ent2.userData.constraints.push(this.c_id)
|
||||
}
|
||||
|
||||
|
||||
export function setCoincident() {
|
||||
const s = new Set()
|
||||
const toComb = []
|
||||
|
@ -41,12 +24,37 @@ export function setCoincident() {
|
|||
|
||||
this.updateOtherBuffers()
|
||||
this.solve()
|
||||
|
||||
this.updateBoundingSpheres()
|
||||
|
||||
// update state of points
|
||||
for (let obj of this.selected) {
|
||||
obj.geometry.computeBoundingSphere()
|
||||
obj.material.color.set(0x555555)
|
||||
}
|
||||
// for (let obj of this.selected) {
|
||||
// obj.geometry.computeBoundingSphere()
|
||||
// obj.material.color.set(0x555555)
|
||||
// }
|
||||
this.selected = []
|
||||
this.obj3d.dispatchEvent({ type: 'change' })
|
||||
}
|
||||
|
||||
|
||||
export function setOrdinate(dir = 0) {
|
||||
|
||||
|
||||
const line = this.selected[0]
|
||||
this.constraints.set(++this.c_id,
|
||||
[
|
||||
dir ? 'vertical' : 'horizontal', -1,
|
||||
[-1, -1, line.name, -1] ///////
|
||||
]
|
||||
)
|
||||
line.userData.constraints.push(this.c_id)
|
||||
|
||||
|
||||
this.updateOtherBuffers()
|
||||
this.solve()
|
||||
this.updateBoundingSpheres()
|
||||
|
||||
this.selected = []
|
||||
this.obj3d.dispatchEvent({ type: 'change' })
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { drawArc, drawArc2 } from './drawArc'
|
||||
import { drawLine, drawLine2 } from './drawLine'
|
||||
// import { drawDimension } from "./drawDimension";
|
||||
import { ptObj } from './shared'
|
||||
|
||||
export function drawOnClick1(e) {
|
||||
if (e.buttons !== 1) return
|
||||
|
@ -95,3 +96,16 @@ export function drawClear() {
|
|||
this.toPush = []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function drawPoint(e) {
|
||||
|
||||
const mouseLoc = this.getLocation(e).toArray();
|
||||
const p1 = ptObj()
|
||||
p1.matrixAutoUpdate = false;
|
||||
p1.userData.constraints = []
|
||||
p1.geometry.attributes.position.set(mouseLoc)
|
||||
this.obj3d.add(p1)
|
||||
this.updatePointsBuffer()
|
||||
this.obj3d.dispatchEvent({ type: 'change' })
|
||||
}
|
|
@ -33,6 +33,8 @@ export function drawLine(mouseLoc) {
|
|||
p1.userData.constraints.push(this.c_id)
|
||||
this.obj3d.children[this.obj3d.children.length - 2].userData.constraints.push(this.c_id)
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ export function extrude(sketch) {
|
|||
}
|
||||
|
||||
|
||||
findPair(children[3]) //??? need fixing
|
||||
findPair(children[4]) //??? need fixing
|
||||
|
||||
const shape = new THREE.Shape(v2s);
|
||||
const extrudeSettings = { depth: 8, bevelEnabled: false };
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
|
||||
import { LineSegments, MeshBasicMaterial, Float32BufferAttribute, BufferGeometry, Mesh, DoubleSide } from '../node_modules/three/src/Three'
|
||||
|
||||
class Patch extends Mesh {
|
||||
|
||||
import * as THREE from '../node_modules/three/src/Three';
|
||||
|
||||
class Patch extends THREE.Mesh {
|
||||
|
||||
constructor(s = 1) {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ export const ToolTip = () => {
|
|||
* child mouseover is novel. If it's not, we ignore the event
|
||||
*/
|
||||
|
||||
const [state, setState] = useState(null)
|
||||
const [text, setText] = useState(null)
|
||||
|
||||
const ref = useRef()
|
||||
|
||||
|
@ -38,14 +38,11 @@ export const ToolTip = () => {
|
|||
prevTooltip.current = tooltip // svg workaround
|
||||
|
||||
clearTimeout(timeout.current)
|
||||
|
||||
if (tooltip) {
|
||||
let { left, top, width, height } = node.getBoundingClientRect()
|
||||
left = left + width / 2 - getTextWidth(tooltip) / 2 - 4 // 4 is padding
|
||||
top = top + height + 6 // 6 is arrow height/width
|
||||
|
||||
setState(tooltip)
|
||||
|
||||
setText(tooltip)
|
||||
if (activated.current) {
|
||||
ref.current.setAttribute('style', `left:${left}px; top:${top}px; visibility:visible`)
|
||||
} else {
|
||||
|
@ -54,22 +51,16 @@ export const ToolTip = () => {
|
|||
activated.current = true
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
ref.current.setAttribute('style', `visibility:hidden`)
|
||||
activated.current = false
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
}, [])
|
||||
|
||||
|
||||
return <div className="tooltip" ref={ref}>
|
||||
{state}
|
||||
{text}
|
||||
<div className="arrow"></div>
|
||||
</div>
|
||||
|
||||
|
@ -77,6 +68,7 @@ export const ToolTip = () => {
|
|||
|
||||
|
||||
function getTextWidth(text, font = "16px sans-serif") {
|
||||
// https://stackoverflow.com/a/21015393
|
||||
// re-use canvas object for better performance
|
||||
let canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
||||
let context = canvas.getContext("2d");
|
||||
|
|
|
@ -7,8 +7,8 @@ const _vec3 = new THREE.Vector3()
|
|||
|
||||
|
||||
const raycaster = new THREE.Raycaster();
|
||||
raycaster.params.Line.threshold = 0.8;
|
||||
raycaster.params.Points.threshold = 0.6;
|
||||
raycaster.params.Line.threshold = 0.1;
|
||||
raycaster.params.Points.threshold = 0.1;
|
||||
|
||||
|
||||
const color = {
|
||||
|
|
|
@ -11,7 +11,7 @@ class AxesHelper extends LineSegments {
|
|||
|
||||
const vertices = [
|
||||
0, 0, 0, 0.5 * s, 0, 0,
|
||||
0.5 * s, 0, 0, 0.35 * s, 0.08*s, 0,
|
||||
0.5 * s, 0, 0, 0.3 * s, 0.08*s, 0,
|
||||
|
||||
0, 0, 0, 0, s, 0,
|
||||
];
|
||||
|
@ -20,7 +20,7 @@ class AxesHelper extends LineSegments {
|
|||
const geometry = new BufferGeometry();
|
||||
geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
|
||||
|
||||
const material = new LineBasicMaterial({ color: 0xff0000, toneMapped: false });
|
||||
const material = new LineBasicMaterial({ color: 0xff0000, toneMapped: false, linewidth:2 });
|
||||
|
||||
super(geometry, material);
|
||||
|
||||
|
|
|
@ -69,18 +69,16 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
|
|||
Slvs_hParam vh = 301, vh_s = 301;
|
||||
Slvs_hParam lh = 400, lh_s = 400;
|
||||
|
||||
Slvs_hParam con_id = 1;
|
||||
|
||||
float *buf_pt_start = p_ptr;
|
||||
int p_start = sys.params;
|
||||
for (int i = 0; i < nPts; i++)
|
||||
{
|
||||
if (isnan((float)*p_ptr))
|
||||
{
|
||||
// printf("%i\n",i);
|
||||
p_ptr += 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
sys.param[sys.params++] = Slvs_MakeParam(ph++, g, (float)*p_ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(ph++, g, (float)*p_ptr++);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(i, g, 200, ph - 1, ph - 2);
|
||||
|
@ -93,13 +91,10 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
|
|||
switch ((int)*l_ptr++)
|
||||
{
|
||||
case 0:
|
||||
// printf("matching %i\n",(int)*(l_ptr + 2));
|
||||
sys.entity[sys.entities++] = Slvs_MakeLineSegment((int)*(l_ptr + 2), g,
|
||||
200, (int)*l_ptr, (int)*(l_ptr + 1));
|
||||
break;
|
||||
case 1:
|
||||
/* And arc, centered at point 303, starting at point 304, ending at
|
||||
* point 305. */
|
||||
sys.entity[sys.entities++] = Slvs_MakeArcOfCircle((int)*(l_ptr + 3), g, 200, 102,
|
||||
(int)*(l_ptr + 2), (int)*(l_ptr), (int)*(l_ptr + 1));
|
||||
break;
|
||||
|
@ -110,11 +105,17 @@ int solver(int nPts, float *p_ptr, int nConst, float *c_ptr, int nLinks, float *
|
|||
l_ptr += 4;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nConst; i++, c_ptr += 6)
|
||||
int c_id = 1;
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
c_id++, 2,
|
||||
SLVS_C_POINTS_COINCIDENT,
|
||||
200,
|
||||
-1,
|
||||
101, 3, -1, -1);
|
||||
for (; c_id < 2 + nConst; c_id++, c_ptr += 6)
|
||||
{
|
||||
// printf("%i here %i\n",(int)*c_ptr, nConst);
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
con_id++, g,
|
||||
c_id, g,
|
||||
(int)*c_ptr + 100000,
|
||||
200,
|
||||
*(c_ptr + 1),
|
||||
|
|
Loading…
Reference in New Issue