angle doesnt work

This commit is contained in:
howard 2021-04-22 19:31:30 -07:00
parent aa82b313fd
commit b3925bbbe4
11 changed files with 58 additions and 80 deletions

File diff suppressed because one or more lines are too long

1
demo_parts/test.jsonn Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -26,10 +26,6 @@ window.STLexp = new STLExporter();
window.id = 0 window.id = 0
const pointMaterial = new THREE.PointsMaterial({
color: color.selpoint,
size: 4,
})
export class Scene { export class Scene {
constructor(store) { constructor(store) {

View File

@ -47,19 +47,6 @@ class Sketch {
this.constraints = new Map() this.constraints = new Map()
this.c_id = 1; this.c_id = 1;
this.helpersGroup = new THREE.Group()
this.obj3d.add(this.helpersGroup);
// this.freePt = new THREE.Points(
// new THREE.BufferGeometry().setAttribute('position',
// new THREE.Float32BufferAttribute(3, 3)
// ),
// custPtMat.clone()
// )
// this.freePt.matrixAutoUpdate = false
// this.freePt.visible = false
// this.freePt.userData.type = 'selpoint'
// this.helpersGroup.add(this.freePt);
this.obj3d.add(new THREE.Group()); this.obj3d.add(new THREE.Group());
this.geomStartIdx = this.obj3d.children.length this.geomStartIdx = this.obj3d.children.length
this.obj3d.userData.geomStartIdx = this.geomStartIdx this.obj3d.userData.geomStartIdx = this.geomStartIdx

View File

@ -1,4 +1,4 @@
import { color } from './shared' import { color, setHover } from './shared'
export async function setCoincident(sel) { export async function setCoincident(sel) {
let selection let selection
@ -39,7 +39,7 @@ export async function setCoincident(sel) {
for (let x = 0; x < this.selected.length; x++) { for (let x = 0; x < this.selected.length; x++) {
const obj = this.selected[x] const obj = this.selected[x]
obj.material.color.set(color[obj.userData.type]) setHover(obj, 0)
} }
this.selected = [] this.selected = []
@ -72,7 +72,11 @@ export async function setOrdinate(dir = 0) {
this.updateOtherBuffers() this.updateOtherBuffers()
this.solve() this.solve()
this.updateBoundingSpheres() this.updateBoundingSpheres()
for (let x = 0; x < this.selected.length; x++) {
const obj = this.selected[x]
setHover(obj, 0)
}
this.selected = [] this.selected = []
this.scene.render() this.scene.render()
} }
@ -152,6 +156,11 @@ export async function setTangent() {
this.solve() this.solve()
this.updateBoundingSpheres() this.updateBoundingSpheres()
for (let x = 0; x < this.selected.length; x++) {
const obj = this.selected[x]
setHover(obj, 0)
}
this.selected = [] this.selected = []
this.scene.render() this.scene.render()
} }

View File

@ -93,8 +93,10 @@ export function extrude(sketch, depth) {
mesh.userData.featureInfo = [sketch.obj3d.name, depth] mesh.userData.featureInfo = [sketch.obj3d.name, depth]
mesh.layers.enable(1) mesh.layers.enable(1)
const vertices = new THREE.Points(mesh.geometry, new THREE.PointsMaterial({ size: 0 })); // const vertices = new THREE.Points(mesh.geometry, new THREE.PointsMaterial({ size: 0 }));
const vertices = new THREE.Points(mesh.geometry, new THREE.PointsMaterial());
vertices.userData.type = 'point' vertices.userData.type = 'point'
vertices.visible = false
vertices.layers.enable(1) vertices.layers.enable(1)
mesh.add(vertices) mesh.add(vertices)

View File

@ -20,12 +20,9 @@ export function onHover(e) {
if (this.obj3d.userData.type != 'sketch') { if (this.obj3d.userData.type != 'sketch') {
this.selpoints[0].visible = false // hide selpoint[0] before each redraw
raycaster.layers.set(1) raycaster.layers.set(1)
hoverPts = raycaster.intersectObjects(this.obj3d.children, true) hoverPts = raycaster.intersectObjects(this.obj3d.children, true)
} else { } else {
// this.freePt.visible = false // hide freept before each redraw
this.scene.selpoints[0].visible = false // hide selpoint[0] before each redraw
raycaster.layers.set(2) raycaster.layers.set(2)
// intersectObjects has side effect of updating bounding spheres // intersectObjects has side effect of updating bounding spheres
// which may lead to unexpected results if you leave boundspheres un-updated // which may lead to unexpected results if you leave boundspheres un-updated
@ -37,7 +34,6 @@ export function onHover(e) {
const thresh = this.snap ? 1 : 0.0001 const thresh = this.snap ? 1 : 0.0001
if (hoverPts.length) { if (hoverPts.length) {
// console.log('here', hoverPts)
let minDist = Infinity; let minDist = Infinity;
for (let i = 0; i < hoverPts.length; i++) { for (let i = 0; i < hoverPts.length; i++) {
if (!hoverPts[i].distanceToRay) continue; if (!hoverPts[i].distanceToRay) continue;
@ -58,8 +54,11 @@ export function onHover(e) {
if (idx.length) { // after filtering, if hovered objs still exists if (idx.length) { // after filtering, if hovered objs still exists
if (
if (hoverPts[idx[0]].object != this.hovered[0]) { // if the previous hovered obj is not the same as current !this.hovered.length
|| (typeof this.hovered[0] == 'number' && this.hovered[0] != hoverPts[idx[0]].index)
|| (typeof this.hovered[0] == 'object' && this.hovered[0] != hoverPts[idx[0]].object)
) { // if the previous hovered obj is not the same as current
for (let x = 0; x < this.hovered.length; x++) { // first clear old hovers that are not selected for (let x = 0; x < this.hovered.length; x++) { // first clear old hovers that are not selected
@ -72,43 +71,25 @@ export function onHover(e) {
for (let x = 0; x < idx.length; x++) { for (let x = 0; x < idx.length; x++) {
let obj = hoverPts[idx[x]].object let obj = hoverPts[idx[x]].object
setHover(obj, 1, false) setHover(obj, 1, false)
if (this.obj3d.userData.type != 'sketch') {
if (obj.userData.type == 'point') {
ptLoc = obj.geometry.attributes.position.array
.slice(
3 * hoverPts[idx[x]].index,
3 * hoverPts[idx[x]].index + 3
)
this.selpoints[0].geometry.attributes.position.array.set(ptLoc)
this.selpoints[0].matrix = obj.parent.matrix
this.selpoints[0].geometry.attributes.position.needsUpdate = true
this.selpoints[0].visible = true
if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') { obj = hoverPts[idx[x]].index
ptLoc = obj.geometry.attributes.position.array this.selpoints[0].idx = obj
.slice( } else {
3 * hoverPts[idx[x]].index, this.selpoints[0].visible = false
3 * hoverPts[idx[x]].index + 3 }
)
this.selpoints[0].geometry.attributes.position.array.set(ptLoc)
this.selpoints[0].matrix = obj.parent.matrix
this.selpoints[0].geometry.attributes.position.needsUpdate = true
this.selpoints[0].visible = true
obj = hoverPts[idx[x]].index
}
if (this.obj3d.userData.type == 'sketch' && obj.userData.type == 'point') {
// ptLoc = obj.geometry.attributes.position.array
// .slice(
// 3 * hoverPts[idx[x]].index,
// 3 * hoverPts[idx[x]].index + 3
// )
// this.freePt.geometry.attributes.position.array.set(ptLoc)
// this.freePt.matrix = obj.parent.matrix
// this.freePt.geometry.attributes.position.needsUpdate = true
// this.freePt.visible = true
ptLoc = obj.geometry.attributes.position.array
.slice(
3 * hoverPts[idx[x]].index,
3 * hoverPts[idx[x]].index + 3
)
this.scene.selpoints[0].geometry.attributes.position.array.set(ptLoc)
this.scene.selpoints[0].matrix = obj.parent.matrix
this.scene.selpoints[0].geometry.attributes.position.needsUpdate = true
this.scene.selpoints[0].visible = true
} }
@ -121,15 +102,15 @@ export function onHover(e) {
} else { // no hovered object after filtering } else { // no hovered object after filtering
if (this.hovered.length) { // if previously something was hovered, then we need to clear it if (this.hovered.length) { // if previously something was hovered, then we need to clear it
for (let x = 0; x < this.hovered.length; x++) { for (let x = 0; x < this.hovered.length; x++) {
const obj = this.hovered[x] const obj = this.hovered[x]
if (typeof obj == 'object' && !this.selected.includes(obj)) { if (typeof obj == 'number') {
this.selpoints[0].visible = false
} else if (!this.selected.includes(obj)) {
setHover(obj, 0) setHover(obj, 0)
} }
} }
this.hovered = [] this.hovered = []
@ -149,7 +130,6 @@ export function onPick(e) {
let obj = this.hovered[this.hovered.length - 1] let obj = this.hovered[this.hovered.length - 1]
// if (sc.selected.includes(obj3d)) continue // if (sc.selected.includes(obj3d)) continue
console.log(obj, 'heere')
if (typeof obj != 'object') { // special sketchplace define pts in feature mode if (typeof obj != 'object') { // special sketchplace define pts in feature mode
const pp = this.selpoints[this.fptIdx % 3 + 1] const pp = this.selpoints[this.fptIdx % 3 + 1]

View File

@ -31,12 +31,16 @@ export async function saveFile(fileHandle, file, dispatch) {
if (!fileHandle) { if (!fileHandle) {
return await saveFileAs(file, dispatch); return await saveFileAs(file, dispatch);
} }
await writeFile(fileHandle, file);
const writable = await fileHandle.createWritable();
await writable.write(file);
await writable.close();
dispatch({ type: 'set-modified', status: false }) dispatch({ type: 'set-modified', status: false })
} catch (ex) { } catch (ex) {
const msg = 'Unable to save file'; const msg = 'Unable to save file';
console.error(msg, ex); console.error(msg, ex);
console.log('heeeeeeeeerree')
alert(msg); alert(msg);
} }
}; };
@ -56,6 +60,7 @@ export async function saveFileAs(file, dispatch) {
} catch (ex) { } catch (ex) {
if (ex.name === 'AbortError') { if (ex.name === 'AbortError') {
console.log('aborted')
return; return;
} }
const msg = 'An error occured trying to open the file.'; const msg = 'An error occured trying to open the file.';
@ -66,9 +71,7 @@ export async function saveFileAs(file, dispatch) {
try { try {
const writable = await fileHandle.createWritable(); const writable = await fileHandle.createWritable();
// Write the contents of the file to the stream.
await writable.write(file); await writable.write(file);
// Close the file and write the contents to disk.
await writable.close() await writable.close()
dispatch({ type: 'set-file-handle', fileHandle, modified: false }) dispatch({ type: 'set-file-handle', fileHandle, modified: false })

View File

@ -115,12 +115,7 @@ export const NavBar = () => {
[Icon.Tangent, () => sc.activeSketch.command('t'), 'Tangent (T)'], [Icon.Tangent, () => sc.activeSketch.command('t'), 'Tangent (T)'],
[MdSave, [MdSave,
async () => { async () => {
if (await verifyPermission(fileHandle) === false) return
sc.refreshNode(sc.activeSketch.obj3d.name, treeEntries)
sc.activeSketch.clearSelection()
saveFile(fileHandle, JSON.stringify([id, sc.sid, sc.mid, treeEntries]), dispatch) saveFile(fileHandle, JSON.stringify([id, sc.sid, sc.mid, treeEntries]), dispatch)
sc.render()
sc.activeSketch.setClean()
} }
, 'Save'], , 'Save'],
] ]
@ -129,7 +124,8 @@ export const NavBar = () => {
const partModeButtons = [ const partModeButtons = [
[FaEdit, addSketch, 'Sketch'], [FaEdit, addSketch, 'Sketch'],
[Icon.Extrude, () => { [Icon.Extrude, () => {
if (sc.selected[0] && treeEntries.byId[sc.selected[0].name].userData.type == 'sketch') { console.log(treeEntries.byId[sc.selected[0].name], 'here')
if (sc.selected[0] && treeEntries.byId[sc.selected[0].name].obj3d) {
dispatch({ type: 'set-dialog', action: 'extrude', target: treeEntries.byId[sc.selected[0].name] }) dispatch({ type: 'set-dialog', action: 'extrude', target: treeEntries.byId[sc.selected[0].name] })
} else { } else {
alert('please select a sketch from the left pane extrude') alert('please select a sketch from the left pane extrude')

View File

@ -45,12 +45,14 @@ const hoverColor = {
const lineMaterial = new THREE.LineBasicMaterial({ const lineMaterial = new THREE.LineBasicMaterial({
linewidth: 1, linewidth: 1,
color: color.line, color: color.line,
depthTest: false
}) })
const pointMaterial = new THREE.PointsMaterial({ const pointMaterial = new THREE.PointsMaterial({
color: color.point, color: color.point,
size: 4, size: 4,
depthTest: false
}) })
@ -64,6 +66,7 @@ const ptObj = (n, visibility = true) => {
ret.name = "p" + id++ ret.name = "p" + id++
ret.userData.type = 'point' ret.userData.type = 'point'
ret.visible = visibility ret.visible = visibility
ret.renderOrder = 1
return ret return ret
} }
@ -76,6 +79,7 @@ const lineObj = (n = 1) => {
); );
ret.name = 'l' + id++ ret.name = 'l' + id++
ret.userData.type = 'line' ret.userData.type = 'line'
ret.renderOrder = 1
return ret return ret
} }
@ -171,6 +175,9 @@ function setHover(obj, state, meshHover = true) {
} else { } else {
break break
} }
case 'point':
obj.material.color.set(colObj[obj.userData.type])
obj.material.size = state ? 8 : 4
default: default:
obj.material.color.set(colObj[obj.userData.type]) obj.material.color.set(colObj[obj.userData.type])
break; break;
@ -196,13 +203,10 @@ const fragmentShader = `
uniform float pointWidth; uniform float pointWidth;
void main() { void main() {
gl_FragColor = vec4(color, 1.0); gl_FragColor = vec4(color, 1.0);
// distance = len(x: [-1, 1], y: [-1, 1])
float distance = length(2.0 * gl_PointCoord - 1.0); float distance = length(2.0 * gl_PointCoord - 1.0);
// pixels [0, ~15/20]
float totalWidth = pointWidth + edgeSize; float totalWidth = pointWidth + edgeSize;
float edgeStart = pointWidth; float edgeStart = pointWidth;
float edgeEnd = pointWidth + 2.0; float edgeEnd = pointWidth + 2.0;
// [edgeStart, edgeEnd] -> [0, 1]
float sEdge = smoothstep(edgeStart, edgeEnd, distance * totalWidth); float sEdge = smoothstep(edgeStart, edgeEnd, distance * totalWidth);
// transition from edgeColor to color along the edge // transition from edgeColor to color along the edge
gl_FragColor = ( vec4(edgeColor, 1.0) * sEdge) + ((1.0 - sEdge) * gl_FragColor); gl_FragColor = ( vec4(edgeColor, 1.0) * sEdge) + ((1.0 - sEdge) * gl_FragColor);
@ -222,7 +226,7 @@ const custPtMat = new THREE.ShaderMaterial({
}, },
vertexShader, vertexShader,
fragmentShader, fragmentShader,
depthTest:false depthTest: false
// depthWrite:false // depthWrite:false
}); });