Created
April 24, 2023 09:44
-
-
Save rhulha/06729f1db19c73256052f524cebd7e9e to your computer and use it in GitHub Desktop.
PirateFort asset with collisions enabled using Babylon.js 6.0 and Havok Physics
This file contains hidden or 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 createScene = function () { | |
var scene = new BABYLON.Scene(engine); | |
var camera = new BABYLON.FlyCamera("FlyCamera", new BABYLON.Vector3(0, 5, -10), scene); | |
camera.attachControl(canvas, true); | |
var light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene); | |
light.intensity = 0.7; | |
var hk = new BABYLON.HavokPlugin(); | |
scene.enablePhysics(new BABYLON.Vector3(0, -9.8, 0), hk); | |
BABYLON.SceneLoader.ImportMesh("", Assets.meshes.pirateFort.rootUrl, Assets.meshes.pirateFort.filename, scene, function (meshes, particleSystems, skeletons) { | |
var meshAggregate = new BABYLON.PhysicsAggregate(meshes[2], BABYLON.PhysicsShapeType.MESH, { mass: 0}, scene); | |
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2, segments: 32}, scene); | |
sphere.position.y = 4; | |
var sphereAggregate = new BABYLON.PhysicsAggregate(sphere, BABYLON.PhysicsShapeType.SPHERE, { mass: 1, restitution:0.75}, scene); | |
var ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 10, height: 10}, scene); | |
var groundAggregate = new BABYLON.PhysicsAggregate(ground, BABYLON.PhysicsShapeType.BOX, { mass: 0 }, scene); | |
}); | |
var skybox = BABYLON.MeshBuilder.CreateBox("skyBox", {size:1000.0}, scene); | |
var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene); | |
skyboxMaterial.backFaceCulling = false; | |
skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/TropicalSunnyDay", scene); | |
skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE; | |
skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0); | |
skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0); | |
skybox.material = skyboxMaterial; | |
return scene; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paste the code here: https://playground.babylonjs.com/