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

[Do Not Merge] Surgical planning and Office #6

Closed
Closed
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
5 changes: 2 additions & 3 deletions src/engine/engine.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// scene to run:

import { scene } from "../examples/defaultscene"

import { scene } from "../examples/ryansoffice/scene"
import { State } from "./state";
import { PerspectiveCamera } from "three";
import { EngineEditorCamera } from "./util/cameracontrols/EngineEditorCamera";
Expand All @@ -12,7 +11,7 @@ import { Physics } from "./physics/physics";
import { XRInput } from "./xrinput"

// editor camera
const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000);
export const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000);
CodeRhymesLife marked this conversation as resolved.
Show resolved Hide resolved
scene.add(new EngineEditorCamera(camera, Renderer.domElement));
scene.add(camera);

Expand Down
5 changes: 5 additions & 0 deletions src/engine/xrinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class XRInputClass
{
constructor()
{
this.showDebugOutput = true;
CodeRhymesLife marked this conversation as resolved.
Show resolved Hide resolved

this.controllerGrips = [ Renderer.xr.getControllerGrip(0), Renderer.xr.getControllerGrip(1) ];
this.controllers = [];
this.controllerModelFactory = new XRControllerModelFactory();
Expand Down Expand Up @@ -75,6 +77,9 @@ class XRInputClass
}
debugOutput()
{
if (!this.showDebugOutput)
return;

this.inputDebugString = "";
this.controllers.forEach((e) =>
{
Expand Down
Binary file not shown.
241 changes: 241 additions & 0 deletions src/examples/ryansoffice/assets/models/office/ryans-home-office.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.0.5",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "Object_0"
}
],
"materials" : [
{
"name" : "Material_0",
"pbrMetallicRoughness" : {
"baseColorTexture" : {
"index" : 0,
"texCoord" : 0
},
"metallicFactor" : 1,
"roughnessFactor" : 1
}
}
],
"meshes" : [
{
"name" : "Mesh_0",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1,
"TEXCOORD_0" : 2
},
"indices" : 3,
"material" : 0
},
{
"attributes" : {
"POSITION" : 4,
"NORMAL" : 5,
"TEXCOORD_0" : 6
},
"indices" : 3,
"material" : 0
},
{
"attributes" : {
"POSITION" : 7,
"NORMAL" : 8,
"TEXCOORD_0" : 9
},
"indices" : 10,
"material" : 0
}
]
}
],
"textures" : [
{
"source" : 0
}
],
"images" : [
{
"mimeType" : "image/png",
"name" : "ryans-home-office",
"uri" : "ryans-home-office.png"
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 65535,
"max" : [
3.107424259185791,
2.9375267028808594,
2.3338735103607178
],
"min" : [
-3.0253734588623047,
-0.1320248693227768,
-1.996368646621704
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 65535,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5126,
"count" : 65535,
"type" : "VEC2"
},
{
"bufferView" : 3,
"componentType" : 5123,
"count" : 65535,
"type" : "SCALAR"
},
{
"bufferView" : 4,
"componentType" : 5126,
"count" : 65535,
"max" : [
3.083371877670288,
2.5834414958953857,
2.401257038116455
],
"min" : [
-2.548391580581665,
-0.12034652382135391,
-1.1427083015441895
],
"type" : "VEC3"
},
{
"bufferView" : 5,
"componentType" : 5126,
"count" : 65535,
"type" : "VEC3"
},
{
"bufferView" : 6,
"componentType" : 5126,
"count" : 65535,
"type" : "VEC2"
},
{
"bufferView" : 7,
"componentType" : 5126,
"count" : 46608,
"max" : [
3.1146740913391113,
2.8516790866851807,
2.251183032989502
],
"min" : [
-2.881847381591797,
-0.14745531976222992,
-1.9958205223083496
],
"type" : "VEC3"
},
{
"bufferView" : 8,
"componentType" : 5126,
"count" : 46608,
"type" : "VEC3"
},
{
"bufferView" : 9,
"componentType" : 5126,
"count" : 46608,
"type" : "VEC2"
},
{
"bufferView" : 10,
"componentType" : 5123,
"count" : 46608,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 786420,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 786420,
"byteOffset" : 786420
},
{
"buffer" : 0,
"byteLength" : 524280,
"byteOffset" : 1572840
},
{
"buffer" : 0,
"byteLength" : 131070,
"byteOffset" : 2097120
},
{
"buffer" : 0,
"byteLength" : 786420,
"byteOffset" : 2228192
},
{
"buffer" : 0,
"byteLength" : 786420,
"byteOffset" : 3014612
},
{
"buffer" : 0,
"byteLength" : 524280,
"byteOffset" : 3801032
},
{
"buffer" : 0,
"byteLength" : 559296,
"byteOffset" : 4325312
},
{
"buffer" : 0,
"byteLength" : 559296,
"byteOffset" : 4884608
},
{
"buffer" : 0,
"byteLength" : 372864,
"byteOffset" : 5443904
},
{
"buffer" : 0,
"byteLength" : 93216,
"byteOffset" : 5816768
}
],
"buffers" : [
{
"byteLength" : 5909984,
"uri" : "ryans-home-office.bin"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions src/examples/ryansoffice/scene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SURGICAL PLANNING sample code
// important: test in metachromium which enables transparent WebXR rendering on desktop!
// https://github.com/webaverse/metachromium-bin

import { AmbientLight, LoadingManager, Scene, Color, Mesh, Plane, DoubleSide, SphereBufferGeometry, PlaneBufferGeometry, MeshBasicMaterial, MeshNormalMaterial, MeshPhongMaterial, Object3D, HemisphereLight, DirectionalLight, SpotLight, ShaderMaterial, AdditiveBlending, BufferGeometry, TextureLoader, Float32BufferAttribute, Points, DynamicDrawUsage, Vector3 } from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"
import { camera } from "../../engine/engine"
import { Renderer } from "../../engine/renderer"
import { XRInput } from "../../engine/xrinput";
import { State } from "../../engine/state";
import { PeerConnection } from '../../engine/networking/PeerConnection'

const GLTFOffice = require("./assets/models/office/ryans-home-office.gltf");
const GLTFOfficeBin = require("./assets/models/office/ryans-home-office.bin");
const GLTFOfficePng = require("./assets/models/office/ryans-home-office.png");

export const scene = new Scene();
//const networking = new PeerConnection(scene);

scene.init = () =>
{
var light = new AmbientLight( 0x404040 ); // soft white light
light.intensity = 10;
scene.add( light );

const manager = new LoadingManager();
const oldResolve = manager.resolveURL;
manager.resolveURL = (uri) => {
console.log("Resolving uri: " + uri);

// When the GLTF loader reads "ryan-home-office.jpg" in the GLTF json
// it thinks it is in the directory as the gltf file (i.e. /assets/models/)
// However, in webpack.common.js we put images in /assets/images
// so we need to point the image at the appropriate path
if (uri.includes("ryans-home-office.png"))
{
uri = GLTFOfficePng
}

return oldResolve(uri)
};

const loader = new GLTFLoader(manager);

// "A simulated heart" developed by Ryan James
let heart;
loader.load(GLTFOffice, function (gltf)
{
gltf.scene.traverse( child => {

if ( child.material ) child.material.metalness = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to update the gltf object's metalness so that it would reflect ambient light.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fascinating, thanks. Curious to hear more about your pipeline and the loader issues you ran into.


} );

const office = gltf.scene.children[ 0 ];
office.position.set(0, 0, 0);

scene.add(office);
});
}
scene.init();
22 changes: 22 additions & 0 deletions src/examples/surgicalplanning/alternative.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Sandcastle from "sandcastle"
import { Vector3 } from "three"
const GLTFHeart = require("./assets/models/heart/heart.glb");

Sandcastle.run(async (scene, controllers) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative, on-rails version of SandCastle. Probably too far on the "easy of use" side at the expense of flexibility, but just wanted to throw some ideas out there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To restate my sentiment: YES, I'd love to see that component!:). Also a super quick way to XRPackagify sandcastle "model viewers", although does present the question of when a simple gltf XRPackage (a future, separate XRPackage format) would be more appropriate.

var heart = await Sandcastle.loadGLTF({
path: GLTFHeart,
position: new Vector3(0, 1, 2),
shared: true,
canGrab: true,
canZoom: true,
onLoaded: (heartSceneObj) => {
// Apply bounding box?
}
})

scene.camera.add(heart)

// Add clipping plane

// Add lighting
})
Binary file not shown.
Loading