Skip to content

Commit

Permalink
clean up frontend code
Browse files Browse the repository at this point in the history
  • Loading branch information
ghackenberg committed Oct 8, 2024
1 parent cdf3fd5 commit 5d13e11
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class ModelView3D extends React.Component<Props> {

if (intersections.length > 0) {
let iterator = intersections[0].object
while (iterator && !iterator.name) {
while (iterator && (!iterator.name || (iterator.parent && !iterator.parent.name))) {
iterator = iterator.parent
}
this.hovered = iterator
Expand Down
8 changes: 7 additions & 1 deletion packages/frontend/src/scripts/functions/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ const renderer = initializeRenderer()
const orbit = initializeOrbit(camera, renderer)

export function initializeScene() {
const ambient_light = new AmbientLight(0xffffff, 0.5)
const ambient_light = new AmbientLight(0xffffff, 0.125)

const directional_light = new DirectionalLight(0xffffff, 1)
directional_light.position.set(1, 1, 1)

const directional_light_2 = new DirectionalLight(0xffffff, 0.25)
directional_light_2.position.set(-1, -1, -1)

const scene = new Scene()
scene.add(ambient_light)
scene.add(directional_light)
scene.add(directional_light_2)
scene.add(new Object3D())

return scene
Expand Down
26 changes: 4 additions & 22 deletions packages/frontend/src/scripts/loaders/fcstd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextWriter, Uint8ArrayWriter, ZipReader } from '@zip.js/zip.js'
import initOpenCascade, { OpenCascadeInstance } from 'opencascade.js'
import { Color, Group, Mesh, MeshStandardMaterial, Object3D, Quaternion, Vector3 } from 'three'
import { Color, Group, Mesh, MeshStandardMaterial, Object3D } from 'three'
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader'

import { BRep, parseBRep } from './brep'
Expand All @@ -20,12 +20,6 @@ export class FreeCADDocument {
public objects: {[name: string]: FreeCADObject} = {}
}

export class FreeCADPlacement {
constructor(public position: Vector3, public quaternion: Quaternion, public angle: number, public origin: Vector3) {

}
}

export class FreeCADObject {
public parents: { property: string, object: FreeCADObject }[] = []

Expand All @@ -43,7 +37,6 @@ export class FreeCADObject {
public shape: FreeCADObject

public label: string
public placement: FreeCADPlacement
public visibility: boolean

public shape_file: string
Expand Down Expand Up @@ -189,6 +182,9 @@ function convertFCObject(obj: FreeCADObject) {
container.name = obj.label

if (obj.shape_file) {
const clone = obj.shape_gltf.scene.clone(true)
traverse(clone, new MeshStandardMaterial({ color: 'black', wireframe: true }))
container.add(clone)
container.add(obj.shape_gltf.scene)
} else if (obj.group) {
for (const child of obj.group) {
Expand Down Expand Up @@ -274,20 +270,6 @@ function parseFCStdDocumentObjectProperty(data: Element, obj: FreeCADObject, doc
if (name == 'Label') {
const child = data.getElementsByTagName('String')[0]
obj.label = child.getAttribute('value')
} else if (name == 'Placement') {
const child = data.getElementsByTagName('PropertyPlacement')[0]
const px = Number.parseFloat(child.getAttribute('Px'))
const py = Number.parseFloat(child.getAttribute('Py'))
const pz = Number.parseFloat(child.getAttribute('Pz'))
const q0 = Number.parseFloat(child.getAttribute('Q0'))
const q1 = Number.parseFloat(child.getAttribute('Q1'))
const q2 = Number.parseFloat(child.getAttribute('Q2'))
const q3 = Number.parseFloat(child.getAttribute('Q3'))
const a = Number.parseFloat(child.getAttribute('A'))
const ox = Number.parseFloat(child.getAttribute('Ox'))
const oy = Number.parseFloat(child.getAttribute('Oz'))
const oz = Number.parseFloat(child.getAttribute('Oz'))
obj.placement = new FreeCADPlacement(new Vector3(px, py, pz), new Quaternion(q0, q1, q2, q3), a, new Vector3(ox, oy, oz))
} else if (name == 'Shape') {
if (type == 'Part::PropertyPartShape') {
const child = data.getElementsByTagName('Part')[0]
Expand Down

0 comments on commit 5d13e11

Please sign in to comment.