From 606e83e2d6fd6a939ea98c3e6f3dd7e7b63a9ad6 Mon Sep 17 00:00:00 2001 From: howard Date: Sat, 10 Apr 2021 16:50:12 -0700 Subject: [PATCH] clean up directory --- {src => lib}/csg-lib.js | 0 {src => lib}/stats.module.js | 0 {src => lib}/three-csg.js | 0 {src => lib}/trackball.js | 0 src/Scene.js | 11 +- src/datums.js | 74 ---------- src/extrude.js | 16 +- src/icons.jsx | 276 ----------------------------------- src/mouseEvents.js | 2 +- src/patch.js | 70 --------- src/react/app.css | 2 +- src/react/depTree.mjs | 2 +- src/rect.js | 81 ---------- 13 files changed, 13 insertions(+), 521 deletions(-) rename {src => lib}/csg-lib.js (100%) rename {src => lib}/stats.module.js (100%) rename {src => lib}/three-csg.js (100%) rename {src => lib}/trackball.js (100%) delete mode 100644 src/datums.js delete mode 100644 src/icons.jsx delete mode 100644 src/patch.js delete mode 100644 src/rect.js diff --git a/src/csg-lib.js b/lib/csg-lib.js similarity index 100% rename from src/csg-lib.js rename to lib/csg-lib.js diff --git a/src/stats.module.js b/lib/stats.module.js similarity index 100% rename from src/stats.module.js rename to lib/stats.module.js diff --git a/src/three-csg.js b/lib/three-csg.js similarity index 100% rename from src/three-csg.js rename to lib/three-csg.js diff --git a/src/trackball.js b/lib/trackball.js similarity index 100% rename from src/trackball.js rename to lib/trackball.js diff --git a/src/Scene.js b/src/Scene.js index e29d00d..04a6027 100644 --- a/src/Scene.js +++ b/src/Scene.js @@ -2,11 +2,10 @@ import * as THREE from '../node_modules/three/src/Three'; -import { TrackballControls } from './trackball' +import { TrackballControls } from '../lib/trackball' import { Sketch } from './Sketch' -import Stats from './stats.module.js'; +import Stats from '../lib/stats.module.js'; -import { add3DPoint } from './datums' import { extrude } from './extrude' import { onHover, onPick } from './mouseEvents'; import { _vec2, _vec3, color, awaitSelection, ptObj } from './shared' @@ -14,7 +13,7 @@ import { _vec2, _vec3, color, awaitSelection, ptObj } from './shared' import { AxesHelper } from './axes' -import CSG from "./three-csg.js" +import CSG from "../lib/three-csg" const eq = (a1, a2) => { @@ -116,10 +115,10 @@ export class Scene { const dist = 50 const light1 = new THREE.PointLight(color.lighting, 0.7); light1.position.set(dist, dist, dist); - this.obj3d.add(light1); + helpersGroup.add(light1); const light2 = new THREE.PointLight(color.lighting, 0.6); light2.position.set(-dist, -dist, -dist); - this.obj3d.add(light2); + helpersGroup.add(light2); this.render = render.bind(this); diff --git a/src/datums.js b/src/datums.js deleted file mode 100644 index c036132..0000000 --- a/src/datums.js +++ /dev/null @@ -1,74 +0,0 @@ -import * as THREE from '../node_modules/three/src/Three'; - - - - -export function add3DPoint(e) { - - // const mouse = new THREE.Vector2( - // (e.clientX / window.innerWidth) * 2 - 1, - // - (e.clientY / window.innerHeight) * 2 + 1 - // ) - - // console.log(new THREE.Vector3(mouse.x, mouse.y, 0).unproject(this.camera)) - - // this.raycaster.ray.intersectPlane(this.plane, this.target).applyMatrix4(this.inverse) - - this.raycaster.setFromCamera( - new THREE.Vector2( - (e.clientX / window.innerWidth) * 2 - 1, - - (e.clientY / window.innerHeight) * 2 + 1 - ), - this.camera - ); - - // const hoverPts = this.raycaster.intersectObjects(this.sketch.children) - const hoverPts = this.raycaster.intersectObjects(this.sketch.children) - - console.log(hoverPts) - - let idx = [] - if (hoverPts.length) { - let minDist = Infinity; - for (let i = 0; i < hoverPts.length; i++) { - if (!hoverPts[i].distanceToRay) continue; - if (hoverPts[i].distanceToRay < minDist) { - minDist = hoverPts[i].distanceToRay - idx = [i] - } else if (hoverPts[i].distanceToRay == minDist) { - idx.push(i) - } - } - if (!idx.length) idx.push(0) - } - - if (idx.length) { - if (hoverPts[idx[0]].object != this.hovered[0]) { - - for (let ob of this.hovered) { - if (ob && !this.selected.includes(ob)) { - ob.material.color.set(0x555555) - } - } - this.hovered = [] - - for (let i of idx) { - hoverPts[i].object.material.color.set(0x00FFFF) - this.hovered.push(hoverPts[i].object) - } - // console.log('render1') - this.render() - } - } else { - if (this.hovered.length) { - for (let ob of this.hovered) { - if (ob && !this.selected.includes(ob)) { - ob.material.color.set(0x555555) - } - } - this.hovered = [] - // console.log('render2') - this.render() - } - } -} diff --git a/src/extrude.js b/src/extrude.js index 2a3e0f1..96afbab 100644 --- a/src/extrude.js +++ b/src/extrude.js @@ -9,7 +9,7 @@ export function extrude(sketch) { let visited = new Set() let v2s = [] let offSetPts = [] - + function findPair(node) { @@ -70,39 +70,33 @@ export function extrude(sketch) { const extrudeSettings = { depth: 8, bevelEnabled: false }; - - - - - - const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings); - + // const material = new THREE.MeshLambertMaterial({ const material = new THREE.MeshPhongMaterial({ color: color.mesh, emissive: color.emissive, // flatShading:true, }); + const mesh = new THREE.Mesh(geometry, material) mesh.name = 'm' + id++ mesh.userData.type = 'mesh' mesh.layers.enable(1) - const vertices = new THREE.Points( mesh.geometry, new THREE.PointsMaterial() ); + const vertices = new THREE.Points(mesh.geometry, new THREE.PointsMaterial({ size: 0 })); vertices.userData.type = 'point' - vertices.layers.disable(0) vertices.layers.enable(1) mesh.add(vertices) mesh.matrixAutoUpdate = false; mesh.matrix.multiply(sketch.obj3d.matrix) + this.obj3d.add(mesh) this.render() - // sketch.visible = false this.store.dispatch({ type: 'rx-extrusion', mesh, sketchId: sketch.obj3d.name }) } diff --git a/src/icons.jsx b/src/icons.jsx deleted file mode 100644 index c37418b..0000000 --- a/src/icons.jsx +++ /dev/null @@ -1,276 +0,0 @@ -import * as React from "react"; -function Arc(props) { - return ( - - - - - - - ); -} - -function Dimension(props) { - return ( - - - - - - - - - - - - - ); -} - -function Intersect(props) { - return ( - - - - - - ); -} - -function Intersect_thin(props) { - return ( - - - - - - ); -} - -function Line(props) { - return ( - - - - - - - ); -} - -function Subtract(props) { - return ( - - - - - - ); -} - -function Union(props) { - return ( - - - - - - - ); -} -export { Arc, Dimension, Intersect, Intersect_thin, Line, Subtract, Union }; \ No newline at end of file diff --git a/src/mouseEvents.js b/src/mouseEvents.js index 7833f92..467a0ed 100644 --- a/src/mouseEvents.js +++ b/src/mouseEvents.js @@ -18,7 +18,7 @@ export function onHover(e) { let hoverPts; if (this.obj3d.userData.type != 'sketch') { - this.obj3d.children[0].children[0].visible = false + this.obj3d.children[0].children[0].visible = false // hide selpoint[0] before each redraw raycaster.layers.set(1) hoverPts = raycaster.intersectObjects(this.obj3d.children, true) } else { diff --git a/src/patch.js b/src/patch.js deleted file mode 100644 index c890b85..0000000 --- a/src/patch.js +++ /dev/null @@ -1,70 +0,0 @@ -// import { LineSegments } from '../objects/LineSegments.js'; -// import { LineBasicMaterial } from '../materials/LineBasicMaterial.js'; -// import { Float32BufferAttribute } from '../core/BufferAttribute.js'; -// import { BufferGeometry } from '../core/BufferGeometry.js'; - - - -import * as THREE from '../node_modules/three/src/Three'; -import {ArrowHelper} from './ArrowHelper' - - - - - - - - - - -class Patch extends THREE.Mesh { - - - constructor(s = 1) { - - - - - const positions = [ - 0.5, 0, - 0.3, 0.06, - 0.3, 0.01, - 0.0, 0.01, - 0.0, -0.01, - 0.3, -0.01, - 0.3, -0.06, - ]; - - const shape = new THREE.Shape() - - shape.moveTo(positions[0], positions[1]) - - for (let i = 2; i < positions.length; i += 2) { - shape.lineTo(positions[i], positions[i+1]) - } - - console.log(shape) - - const geometry = new THREE.ShapeGeometry( shape );; - - - super( - geometry, - new MeshBasicMaterial({ - color: 0x0000ff, - opacity: 0.2, - side: DoubleSide, - transparent: true, - depthWrite: false, - toneMapped: false - }) - ) - - this.scale.set( 1, 1, 1 ); - return this; - } - -} - - -export { Patch }; diff --git a/src/react/app.css b/src/react/app.css index 8e93353..ee19777 100644 --- a/src/react/app.css +++ b/src/react/app.css @@ -49,7 +49,7 @@ body { cursor: pointer; @apply fill-current bg-transparent text-gray-200 - hover:bg-gray-600 hover:text-gray-200; + hover:bg-gray-500 hover:text-gray-200; } .btn-light { diff --git a/src/react/depTree.mjs b/src/react/depTree.mjs index f41c114..626f581 100644 --- a/src/react/depTree.mjs +++ b/src/react/depTree.mjs @@ -69,7 +69,7 @@ export class DepTree { this.allIds.splice(spliceIdx, 1) - const deletedObj = sc.obj3d.children.splice(spliceIdx + 4, 1)[0] // first 4 elements are non geom + const deletedObj = sc.obj3d.children.splice(spliceIdx + 1, 1)[0] // first 1 elements are non geom deletedObj.traverse((obj)=>{ if (obj.geometry) obj.geometry.dispose() diff --git a/src/rect.js b/src/rect.js deleted file mode 100644 index d5b8c96..0000000 --- a/src/rect.js +++ /dev/null @@ -1,81 +0,0 @@ - const lines = [ - DlineObj(), // 0: - DlineObj(), // 1: - DlineObj(), // 2: - DlineObj(), // 2: - ] - - const points = [ - DptObj(), // 1: | - DptObj(), // 1: | - DptObj(), // 1: | - DptObj(), // 2: | - DptObj(), // 3: | - DptObj(), // 4: | - DptObj(), // 5: | - DptObj(), // 6: | - ] - - const updatePoint = this.obj3d.children.length - let prev = points[points.length - 1] - for (let i = 0, j = 0; i < points.length; i++) { - const cur = points[i] - if (i % 2 == 0) { - this.constraints.set(++this.c_id, //??? increment investigation - [ - 'points_coincident', -1, - [prev.name, cur.name, -1, -1] - ] - ) - cur.userData.constraints.push(this.c_id) - prev.userData.constraints.push(this.c_id) - } else { - const toPush = [prev, cur, lines[j]] - this.linkedObjs.set(this.l_id, ['line', toPush.map(e => e.name)]) - for (let obj of toPush) { - obj.userData.l_id = this.l_id - } - this.l_id += 1 - - if (j > 0) { - this.constraints.set(++this.c_id, //??? - [ - 'perpendicular', -1, - [-1, -1, lines[j - 1].name, lines[j].name] - ] - ) - lines[j - 1].userData.constraints.push(this.c_id) - lines[j].userData.constraints.push(this.c_id) - } - this.obj3d.add(...toPush) - - j += 1 - } - - if (i >= 3 && i <= 6) { - points[i].geometry.attributes.position.set(p2.geometry.attributes.position.array) - } else { - points[i].geometry.attributes.position.set(p1.geometry.attributes.position.array) - } - - prev = cur - } - - - this.constraints.set(++this.c_id, //??? increment investigation - [ - 'points_coincident', -1, - [p2.name, points[5].name, -1, -1] - ] - ) - points[5].userData.constraints.push(this.c_id) - p2.userData.constraints.push(this.c_id) - - this.constraints.set(++this.c_id, //??? increment investigation - [ - 'points_coincident', -1, - [p1.name, points[0].name, -1, -1] - ] - ) - points[0].userData.constraints.push(this.c_id) - p1.userData.constraints.push(this.c_id) \ No newline at end of file