Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat-zoom-to-fit #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/engine-test/src_bundle/bundle.threejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export { Color } from 'three/src/math/Color.js';
export { AmbientLight } from 'three/src/lights/AmbientLight.js';
export { HemisphereLight } from 'three/src/lights/HemisphereLight.js';
export { DirectionalLight } from 'three/src/lights/DirectionalLight.js';
// export { PlaneGeometry } from 'three/src/geometries/PlaneGeometry';
// export { PlaneGeometry } from 'three/src/geometries/PlaneGeometry.js';
export { BoxGeometry } from 'three/src/geometries/BoxGeometry.js';
export { EdgesGeometry } from 'three/src/geometries/EdgesGeometry.js';
export { MeshPhongMaterial } from 'three/src/materials/MeshPhongMaterial.js';
export { LineBasicMaterial } from 'three/src/materials/LineBasicMaterial.js';
Expand All @@ -25,6 +26,7 @@ export { Group } from 'three/src/objects/Group.js';
export { Line } from 'three/src/objects/Line.js';
export { Matrix4 } from 'three/src/math/Matrix4.js';
export { Vector3 } from 'three/src/math/Vector3.js';
export { Box3 } from 'three/src/math/Box3.js';
// export { Euler } from 'three/src/math/Euler.js';
// export { Texture } from 'three/src/textures/Texture.js';
// export * from 'three/src/constants.js';
Expand Down
6 changes: 3 additions & 3 deletions apps/jscad-web/src/viewState.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export class ViewState {
updateScene() {
const { axes, grid, model } = this
const items = []
if (axes) items.push({ id: 'axes', items: axes })
if (grid) items.push({ id: 'grid', items: grid })
if (model) items.push({ id: 'model', items: model })
if (axes) items.push({ id: 'axes', items: axes, ignoreBB:true })
if (grid) items.push({ id: 'grid', items: grid, ignoreBB:true })
if (model) items.push({ id: 'model', items: model, ignoreBB:false })

this.viewer?.setScene({ items }, { smooth: this.smoothRender })
}
Expand Down
2 changes: 2 additions & 0 deletions apps/jscad-web/src_bundle/bundle.threejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { AmbientLight } from 'three/src/lights/AmbientLight.js';
export { HemisphereLight } from 'three/src/lights/HemisphereLight.js';
export { DirectionalLight } from 'three/src/lights/DirectionalLight.js';
// export { PlaneGeometry } from 'three/src/geometries/PlaneGeometry';
export { BoxGeometry } from 'three/src/geometries/BoxGeometry.js';
export { EdgesGeometry } from 'three/src/geometries/EdgesGeometry.js';
export { MeshPhongMaterial } from 'three/src/materials/MeshPhongMaterial.js';
export { LineBasicMaterial } from 'three/src/materials/LineBasicMaterial.js';
Expand All @@ -25,6 +26,7 @@ export { Group } from 'three/src/objects/Group.js';
export { Line } from 'three/src/objects/Line.js';
export { Matrix4 } from 'three/src/math/Matrix4.js';
export { Vector3 } from 'three/src/math/Vector3.js';
export { Box3 } from 'three/src/math/Box3.js';
// export { Euler } from 'three/src/math/Euler.js';
// export { Texture } from 'three/src/textures/Texture.js';
// export * from 'three/src/constants.js';
Expand Down
23 changes: 23 additions & 0 deletions packages/render-threejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function RenderThreejs({
DirectionalLight,
Scene,
Group,
Box3,
BoxGeometry,
Vector3,
Color, // used by both
// used by CommonToThree
Expand Down Expand Up @@ -199,6 +201,7 @@ export function RenderThreejs({
}

function setScene(scene,{smooth}={}) {
console.log('setScene', scene)
groups.forEach(group => {
_scene.remove(group)
})
Expand All @@ -208,19 +211,39 @@ export function RenderThreejs({
setTimeout(()=>{
old.forEach(ent => ent.geometry?.dispose?.())
},0)

scene.items.forEach(item => {
const group = new Group()
group.jscadId = item.id
group.ignoreBB = item.ignoreBB
groups.push(group)
let box = new Box3()
item.items.forEach(obj => {
const obj3d = csgConvert(obj, { smooth, scene, meshColor})
if (obj3d) {
entities.push(obj3d)
console.log('obj3d', obj3d)
if(!group.ignoreBB) box.expandByObject(obj3d)
group.add(obj3d)
} else {
console.error('could not convert to obj3d', obj)
}
})
_scene.add(group)
console.log('box', box)
let {x,y,z} = box.max
let min = box.min
let wx = x-min.x, wy=y-min.y,wz=z-min.z
let boxGeom = new BoxGeometry(wx,wy,wz)
// boxGeom.position.x = min.x + wx/2
// boxGeom.position.y = min.y + wy/2
// boxGeom.position.z = min.z + wz/2
console.log('BoxGeometry(wx,wy,wz)', wx,wy,wz)
let mesh = new Mesh(boxGeom, new MeshPhongMaterial({color:'90909090',opacity:0.5, transparent:true}))
mesh.position.x = min.x + wx/2
mesh.position.y = min.y + wy/2
mesh.position.z = min.z + wz/2
groups[0].add(mesh)
})
updateView()
}
Expand Down