angle doesnt work
This commit is contained in:
parent
aa82b313fd
commit
b3925bbbe4
File diff suppressed because one or more lines are too long
1
demo_parts/test.jsonn
Normal file
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
@ -26,10 +26,6 @@ window.STLexp = new STLExporter();
|
||||
window.id = 0
|
||||
|
||||
|
||||
const pointMaterial = new THREE.PointsMaterial({
|
||||
color: color.selpoint,
|
||||
size: 4,
|
||||
})
|
||||
|
||||
export class Scene {
|
||||
constructor(store) {
|
||||
|
@ -47,19 +47,6 @@ class Sketch {
|
||||
this.constraints = new Map()
|
||||
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.geomStartIdx = this.obj3d.children.length
|
||||
this.obj3d.userData.geomStartIdx = this.geomStartIdx
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { color } from './shared'
|
||||
import { color, setHover } from './shared'
|
||||
|
||||
export async function setCoincident(sel) {
|
||||
let selection
|
||||
@ -39,7 +39,7 @@ export async function setCoincident(sel) {
|
||||
|
||||
for (let x = 0; x < this.selected.length; x++) {
|
||||
const obj = this.selected[x]
|
||||
obj.material.color.set(color[obj.userData.type])
|
||||
setHover(obj, 0)
|
||||
}
|
||||
|
||||
this.selected = []
|
||||
@ -72,6 +72,10 @@ export async function setOrdinate(dir = 0) {
|
||||
this.updateOtherBuffers()
|
||||
this.solve()
|
||||
this.updateBoundingSpheres()
|
||||
for (let x = 0; x < this.selected.length; x++) {
|
||||
const obj = this.selected[x]
|
||||
setHover(obj, 0)
|
||||
}
|
||||
|
||||
this.selected = []
|
||||
this.scene.render()
|
||||
@ -152,6 +156,11 @@ export async function setTangent() {
|
||||
this.solve()
|
||||
this.updateBoundingSpheres()
|
||||
|
||||
for (let x = 0; x < this.selected.length; x++) {
|
||||
const obj = this.selected[x]
|
||||
setHover(obj, 0)
|
||||
}
|
||||
|
||||
this.selected = []
|
||||
this.scene.render()
|
||||
}
|
||||
|
@ -93,8 +93,10 @@ export function extrude(sketch, depth) {
|
||||
mesh.userData.featureInfo = [sketch.obj3d.name, depth]
|
||||
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.visible = false
|
||||
vertices.layers.enable(1)
|
||||
|
||||
mesh.add(vertices)
|
||||
|
@ -20,12 +20,9 @@ export function onHover(e) {
|
||||
|
||||
|
||||
if (this.obj3d.userData.type != 'sketch') {
|
||||
this.selpoints[0].visible = false // hide selpoint[0] before each redraw
|
||||
raycaster.layers.set(1)
|
||||
hoverPts = raycaster.intersectObjects(this.obj3d.children, true)
|
||||
} 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)
|
||||
// intersectObjects has side effect of updating bounding spheres
|
||||
// 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
|
||||
if (hoverPts.length) {
|
||||
// console.log('here', hoverPts)
|
||||
let minDist = Infinity;
|
||||
for (let i = 0; i < hoverPts.length; i++) {
|
||||
if (!hoverPts[i].distanceToRay) continue;
|
||||
@ -58,8 +54,11 @@ export function onHover(e) {
|
||||
|
||||
|
||||
if (idx.length) { // after filtering, if hovered objs still exists
|
||||
|
||||
if (hoverPts[idx[0]].object != this.hovered[0]) { // if the previous hovered obj is not the same as current
|
||||
if (
|
||||
!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
|
||||
|
||||
@ -72,11 +71,10 @@ export function onHover(e) {
|
||||
|
||||
for (let x = 0; x < idx.length; x++) {
|
||||
let obj = hoverPts[idx[x]].object
|
||||
|
||||
setHover(obj, 1, false)
|
||||
|
||||
|
||||
if (this.obj3d.userData.type != 'sketch' && obj.userData.type == 'point') {
|
||||
if (this.obj3d.userData.type != 'sketch') {
|
||||
if (obj.userData.type == 'point') {
|
||||
ptLoc = obj.geometry.attributes.position.array
|
||||
.slice(
|
||||
3 * hoverPts[idx[x]].index,
|
||||
@ -88,27 +86,10 @@ export function onHover(e) {
|
||||
this.selpoints[0].visible = true
|
||||
|
||||
obj = hoverPts[idx[x]].index
|
||||
this.selpoints[0].idx = obj
|
||||
} else {
|
||||
this.selpoints[0].visible = false
|
||||
}
|
||||
|
||||
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
|
||||
if (this.hovered.length) { // if previously something was hovered, then we need to clear it
|
||||
|
||||
|
||||
for (let x = 0; x < this.hovered.length; 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)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
this.hovered = []
|
||||
|
||||
@ -149,7 +130,6 @@ export function onPick(e) {
|
||||
let obj = this.hovered[this.hovered.length - 1]
|
||||
// if (sc.selected.includes(obj3d)) continue
|
||||
|
||||
console.log(obj, 'heere')
|
||||
if (typeof obj != 'object') { // special sketchplace define pts in feature mode
|
||||
|
||||
const pp = this.selpoints[this.fptIdx % 3 + 1]
|
||||
|
@ -31,12 +31,16 @@ export async function saveFile(fileHandle, file, dispatch) {
|
||||
if (!fileHandle) {
|
||||
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 })
|
||||
} catch (ex) {
|
||||
const msg = 'Unable to save file';
|
||||
console.error(msg, ex);
|
||||
console.log('heeeeeeeeerree')
|
||||
alert(msg);
|
||||
}
|
||||
};
|
||||
@ -56,6 +60,7 @@ export async function saveFileAs(file, dispatch) {
|
||||
|
||||
} catch (ex) {
|
||||
if (ex.name === 'AbortError') {
|
||||
console.log('aborted')
|
||||
return;
|
||||
}
|
||||
const msg = 'An error occured trying to open the file.';
|
||||
@ -66,9 +71,7 @@ export async function saveFileAs(file, dispatch) {
|
||||
|
||||
try {
|
||||
const writable = await fileHandle.createWritable();
|
||||
// Write the contents of the file to the stream.
|
||||
await writable.write(file);
|
||||
// Close the file and write the contents to disk.
|
||||
await writable.close()
|
||||
|
||||
dispatch({ type: 'set-file-handle', fileHandle, modified: false })
|
||||
|
@ -115,12 +115,7 @@ export const NavBar = () => {
|
||||
[Icon.Tangent, () => sc.activeSketch.command('t'), 'Tangent (T)'],
|
||||
[MdSave,
|
||||
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)
|
||||
sc.render()
|
||||
sc.activeSketch.setClean()
|
||||
}
|
||||
, 'Save'],
|
||||
]
|
||||
@ -129,7 +124,8 @@ export const NavBar = () => {
|
||||
const partModeButtons = [
|
||||
[FaEdit, addSketch, 'Sketch'],
|
||||
[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] })
|
||||
} else {
|
||||
alert('please select a sketch from the left pane extrude')
|
||||
|
@ -45,12 +45,14 @@ const hoverColor = {
|
||||
const lineMaterial = new THREE.LineBasicMaterial({
|
||||
linewidth: 1,
|
||||
color: color.line,
|
||||
depthTest: false
|
||||
})
|
||||
|
||||
|
||||
const pointMaterial = new THREE.PointsMaterial({
|
||||
color: color.point,
|
||||
size: 4,
|
||||
depthTest: false
|
||||
})
|
||||
|
||||
|
||||
@ -64,6 +66,7 @@ const ptObj = (n, visibility = true) => {
|
||||
ret.name = "p" + id++
|
||||
ret.userData.type = 'point'
|
||||
ret.visible = visibility
|
||||
ret.renderOrder = 1
|
||||
return ret
|
||||
}
|
||||
|
||||
@ -76,6 +79,7 @@ const lineObj = (n = 1) => {
|
||||
);
|
||||
ret.name = 'l' + id++
|
||||
ret.userData.type = 'line'
|
||||
ret.renderOrder = 1
|
||||
return ret
|
||||
}
|
||||
|
||||
@ -171,6 +175,9 @@ function setHover(obj, state, meshHover = true) {
|
||||
} else {
|
||||
break
|
||||
}
|
||||
case 'point':
|
||||
obj.material.color.set(colObj[obj.userData.type])
|
||||
obj.material.size = state ? 8 : 4
|
||||
default:
|
||||
obj.material.color.set(colObj[obj.userData.type])
|
||||
break;
|
||||
@ -196,13 +203,10 @@ const fragmentShader = `
|
||||
uniform float pointWidth;
|
||||
void main() {
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
// distance = len(x: [-1, 1], y: [-1, 1])
|
||||
float distance = length(2.0 * gl_PointCoord - 1.0);
|
||||
// pixels [0, ~15/20]
|
||||
float totalWidth = pointWidth + edgeSize;
|
||||
float edgeStart = pointWidth;
|
||||
float edgeEnd = pointWidth + 2.0;
|
||||
// [edgeStart, edgeEnd] -> [0, 1]
|
||||
float sEdge = smoothstep(edgeStart, edgeEnd, distance * totalWidth);
|
||||
// transition from edgeColor to color along the edge
|
||||
gl_FragColor = ( vec4(edgeColor, 1.0) * sEdge) + ((1.0 - sEdge) * gl_FragColor);
|
||||
|
Loading…
Reference in New Issue
Block a user