-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
128 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as THREE from "three"; | ||
import { ISimulationObject } from "./SimulationObject"; | ||
|
||
const defaultMaterial = new THREE.MeshPhongMaterial({ side: THREE.DoubleSide, transparent: true, opacity: 0.5, wireframe: true }); | ||
|
||
//https://stackoverflow.com/questions/37090942/how-to-render-clipped-surfaces-as-solid-objects/37093210#37093210 | ||
defaultMaterial.onBeforeCompile = function (shader) { | ||
|
||
shader.fragmentShader = shader.fragmentShader.replace( | ||
|
||
`gl_FragColor = vec4( outgoingLight, diffuseColor.a );`, | ||
|
||
`gl_FragColor = ( gl_FrontFacing ) ? vec4( outgoingLight, diffuseColor.a ) : vec4( diffuse, opacity );` | ||
|
||
); | ||
}; | ||
|
||
const boxGeometry = new THREE.BoxGeometry(1, 1, 1, 1, 1, 1); | ||
|
||
export class BoxMesh extends THREE.Mesh<THREE.BoxGeometry> implements ISimulationObject { | ||
type = 'BoxMesh'; | ||
name = 'Box'; | ||
constructor(geometry?: THREE.BoxGeometry, material?: THREE.Material) { | ||
super(geometry ?? boxGeometry, material ?? defaultMaterial.clone()); | ||
} | ||
} | ||
|
||
|
||
const cylinderGeometry = new THREE.CylinderGeometry(1, 1, 1, 16, 1, false, 0, Math.PI * 2); | ||
|
||
export class CylinderMesh extends THREE.Mesh<THREE.CylinderGeometry> implements ISimulationObject { | ||
type = 'CylinderMesh'; | ||
name = 'Cylinder'; | ||
constructor(geometry?: THREE.CylinderGeometry, material?: THREE.Material) { | ||
super(geometry ?? cylinderGeometry, material ?? defaultMaterial.clone()); | ||
} | ||
} | ||
|
||
|
||
const sphereGeometry = new THREE.SphereGeometry(1, 16, 8, 0, Math.PI * 2, 0, Math.PI); | ||
|
||
export class SphereMesh extends THREE.Mesh<THREE.SphereGeometry> implements ISimulationObject { | ||
readonly notRotatable = true; | ||
type = 'SphereMesh'; | ||
name = 'Sphere'; | ||
constructor(geometry?: THREE.SphereGeometry, material?: THREE.Material) { | ||
super(geometry ?? sphereGeometry, material ?? defaultMaterial.clone()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Object3D, ObjectLoader } from "three"; | ||
import { BoxMesh, CylinderMesh, SphereMesh } from "./BasicMeshes"; | ||
|
||
export class EditorObjectLoader extends ObjectLoader { | ||
|
||
parseObject<T extends Object3D<THREE.Event>>(data: any, geometries: any[], materials: THREE.Material[], animations: THREE.AnimationClip[]): T { | ||
const geometry = geometries[data.geometry]; | ||
const material = materials[data.material]; | ||
|
||
let object = super.parseObject<T>(data, geometries, materials, animations); | ||
let editorObject; | ||
switch (data.type) { | ||
case 'SphereMesh': | ||
editorObject = new SphereMesh(); | ||
break; | ||
case 'BoxMesh': | ||
editorObject = new BoxMesh(); | ||
break; | ||
case 'CylinderMesh': | ||
editorObject = new CylinderMesh(); | ||
break; | ||
default: | ||
// not custom object type | ||
} | ||
|
||
// rewrite properties from parsed data if object is custom | ||
if (editorObject) { | ||
|
||
// hacky way to copy parsed data | ||
editorObject.copy(object as any); | ||
|
||
editorObject.uuid = object.uuid; | ||
editorObject.material = material; | ||
editorObject.geometry = geometry; | ||
|
||
return editorObject as Object3D<THREE.Event> as T; | ||
} | ||
|
||
return object; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export interface ISimulationObject { | ||
notRemovable: boolean, | ||
notMovable: boolean, | ||
notRotatable: boolean, | ||
notScalable: boolean, | ||
readonly isObject3D: true; | ||
readonly notRemovable?: boolean, | ||
readonly notMovable?: boolean, | ||
readonly notRotatable?: boolean, | ||
readonly notScalable?: boolean, | ||
} |