Last active
July 5, 2019 21:19
-
-
Save flushpot1125/dc7253a136988d1dcc1d2e3b69d637d0 to your computer and use it in GitHub Desktop.
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
var canvas = document.getElementById("renderCanvas"); | |
var createScene = function () { | |
var scene = new BABYLON.Scene(engine); | |
scene.debugLayer.show(); | |
var camera = new BABYLON.ArcRotateCamera('MainCamera1', 0, 0, 3, BABYLON.Vector3(0, 1.2, 0), scene, true); | |
camera.position = new BABYLON.Vector3(0, 1.2, -1.1); | |
camera.attachControl(canvas, true); | |
camera.inputs.attached.mousewheel.detachControl(canvas); | |
var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene); | |
var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene); | |
//for VR | |
var vrHelper = scene.createDefaultVRExperience({controllerMeshes:false}); | |
vrHelper.currentVRCamera.position.y = 300; | |
const leftHand = BABYLON.Mesh.CreateBox("",0.1, scene); | |
leftHand.scaling.z = 2; | |
leftHand.isVisible =false; | |
const rightHand = BABYLON.Mesh.CreateBox("",0.1, scene); | |
rightHand.scaling.z = 2; | |
rightHand.isVisible =false; | |
var swordMesh; | |
BABYLON.SceneLoader.ImportMeshAsync("", "../../assets/meshes/controllers/oculus/", "sword.glb", scene).then(function(result) { | |
swordMesh = result.meshes[0]; | |
}); | |
var rightQuestControllerMesh; | |
BABYLON.SceneLoader.ImportMeshAsync("", "../../assets/meshes/controllers/oculus/", "right_quest.glb", scene).then(function(result) { | |
rightQuestControllerMesh = result.meshes[0]; | |
}); | |
vrHelper.webVRCamera.onControllerMeshLoadedObservable.add(e => { | |
vrHelper.webVRCamera.leftController.attachToMesh(swordMesh); | |
vrHelper.webVRCamera.rightController.attachToMesh(rightQuestControllerMesh); | |
}); | |
scene.onBeforeRenderObservable.add(()=>{ | |
if(vrHelper.webVRCamera.leftController){ | |
leftHand.position = vrHelper.webVRCamera.leftController.devicePosition.clone(); | |
leftHand.rotationQuaternion = vrHelper.webVRCamera.leftController.deviceRotationQuaternion.clone(); | |
} | |
if(vrHelper.webVRCamera.rightController){ | |
rightHand.position = vrHelper.webVRCamera.rightController.devicePosition.clone(); | |
rightHand.rotationQuaternion = vrHelper.webVRCamera.rightController.deviceRotationQuaternion.clone(); | |
} | |
}); | |
//おまけ swodの刃(Lame)だけglowで光らせる | |
var gl = new BABYLON.GlowLayer("glow", scene,{ | |
}); | |
gl.customEmissiveColorSelector = function(mesh, subMesh, material, result) { | |
if (mesh.name === "Lame") { | |
result.set(0, 0, 0.5, 1); | |
} else { | |
result.set(0, 0, 0, 0); | |
} | |
} | |
return scene; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment