-
Content Count
9 -
Joined
-
Last visited
About Zahir Junejo
-
Rank
Newbie
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Zahir Junejo started following Emissive color change before collision
-
var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var initBallSpeed = 0.05; var ballSpeed = initBallSpeed; var xDirection = 1; var yDirection = 1; var boardX = -3.0; var boardY = 3.0; var keyState = {}; var MainScene = function () { // This creates a basic Babylon Scene object (non-mesh) var scene = new BABYLON.Scene(engine); // This creates and positions a free camera (non-mesh) var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 0, -20), scene); //camera.attachControl(canvas, true); var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene); //Setup the bat for the scene. Dont know what else to call it. var bat = BABYLON.Mesh.CreateBox("bat", 0.5, scene); bat.scaling.x = 5.0; bat.position.y = -5.0; //Setup the ball var ball = BABYLON.Mesh.CreateSphere("ball", 5, 0.5,scene); ball.position.y = bat.position.y + 1; ball.position.x = bat.position.x; //Register keypress actions with the ball scene.actionManager = new BABYLON.ActionManager(scene); window.addEventListener('keydown',function(e){ keyState[e.keyCode || e.which] = true; },true); window.addEventListener('keyup',function(e){ keyState[e.keyCode || e.which] = false; },true); // scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction( // BABYLON.ActionManager.OnEveryFrameTrigger, // function (evt) { // })); //Setup the walls // Top Wall var topWall = BABYLON.Mesh.CreateBox("topWall", 0.5, scene); topWall.position.y = 6.0; topWall.scaling.x = 25.0; // Left Wall var leftWall = BABYLON.Mesh.CreateBox("leftWall", 0.5, scene); leftWall.position.x = -6.0; leftWall.position.y = 1.0; leftWall.scaling.y = 25.0; // Right Wall var rightWall = BABYLON.Mesh.CreateBox("rightWall", 0.5, scene); rightWall.position.x = 6.0; rightWall.position.y = 1.0; rightWall.scaling.y = 25.0; var enemy = BABYLON.Mesh.CreateBox("enemy1", 1.0, scene); enemy.position.x = boardX; enemy.position.y = boardY; var matBB = new BABYLON.StandardMaterial("matBB", scene); matBB.emissiveColor = new BABYLON.Color3(1, 1, 1); enemy.material = matBB; scene.registerBeforeRender(function(){ ball.position.x += ballSpeed * xDirection; ball.position.y += ballSpeed * yDirection; if(ball.position.y < -7){ ball.position.y = bat.position.y + 1; ball.position.x = bat.position.x; ballSpeed = initBallSpeed; xDirection = yDirection = 1; } if(ball.intersectsMesh(rightWall, true)){ xDirection = -1; } if(ball.intersectsMesh(leftWall, true)){ xDirection = 1; } if(ball.intersectsMesh(topWall, true)){ yDirection = -1; } if(ball.intersectsMesh(bat, true)){ yDirection = 1; if(ballSpeed <= 0.25) ballSpeed+=0.01; } if(ball.intersectsMesh(enemy, true)) { xDirection = -1; yDirection = -1; enemy.material.emissiveColor = new BABYLON.Color3(1, 0, 0); } if (keyState[37] || keyState[65]){ bat.position.x-=ballSpeed*2; } if (keyState[39] || keyState[68]){ bat.position.x+=ballSpeed*2; } }); return scene; }; var scene = MainScene(); engine.runRenderLoop(function () { scene.render(); }); // Resize window.addEventListener("resize", function () { engine.resize(); }); Either I am really high or the enemy block is turning red before my ball can even collide with the block. Any ideas?
- 1 reply
-
- frustrated
- high
-
(and 3 more)
Tagged with:
-
-
Oh my god, are you David catuh? I will definitely look into scene.debuglayer.show but the problem has been solved for now. By using Meshes[0].getscene.getmaterialbyid... I was able to change colours for both materials. Thanks anyways everyone. But really, are you Mr Catuh?
-
Yes how did you know that?
-
-
I guess i can relate to that. Yes meshes[0] is boat mesh because that is the only mesh in the blender version of this file. I have not done any splitting.
-
I tried that but that also did not work the colour still remained grey but same thing done to skull.babylon file worked.
-
Zahir Junejo changed their profile photo
-
Hi fellow Babylonians, I tried to import a mesh of a boat, but i want to change the color of its material. I cannot change it for some reason. here is the part of code: let boat = new BABYLON.AbstractMesh("boat", scene); boatMaterial = new BABYLON.StandardMaterial("boatMat", scene); boatMaterial.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.5); BABYLON.SceneLoader.ImportMesh("", "assets/", "speedboat.babylon", scene, (meshes, particleSystems) => { meshes[0].material = boatMaterial; boat = meshes[0]; }); let boatSpeed = 1; boat.position = new BABYLON.Vector3(-10, 0, 100); But bright side, experience on babylon has been great so far. But just need help on this.
-
This file is in .babylon format. But problem is babylon.js does not seem to render its own file format correctly. Plus how do i get it to playground and how will i upload the .babylon files?
-
I tried to export a .babylon model of lamborghini avantador which i imported from clara.io, this was how it looked in clara.io: https://d3ijcvgxwtkjmf.cloudfront.net/8a268a124e80c43c3c4bf291241aab70 And this is how it looks like in my project: This is the code <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Babylon.js sample code</title> <!-- Babylon.js --> <script src="http://www.babylonjs.com/hand.minified-1.2.js"></script> <script src="http://www.babylonjs.com/cannon.js"></script> <script src="http://www.babylonjs.com/oimo.js"></script> <script src="http://www.babylonjs.com/babylon.js"></script> <style> html, body { overflow: hidden; width: 100%; height: 100%; margin: 0; padding: 0; } #renderCanvas { width: 100%; height: 100%; touch-action: none; } </style> </head> <body> <canvas id="renderCanvas"></canvas> <script> var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var createScene = function () { var scene = new BABYLON.Scene(engine); //Adding a light var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene); //Adding an Arc Rotate Camera var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene); camera.attachControl(canvas, false); camera.setTarget(BABYLON.Vector3.Zero()); /* // The first parameter can be used to specify which mesh to import. Here we import all meshes BABYLON.SceneLoader.ImportMesh("", "scenes/nissan-gt-r-nismo-babylon/", "nissan-gt-r-nismo.babylon", scene, function (newMeshes) { // Set the target of the camera to the first imported mesh camera.target = newMeshes[0].position; }); */ /*----------------------------------------------------------------------------------------------------------*/ BABYLON.SceneLoader.Load("scenes/av/", "lamborghini-aventador-pbribl.babylon", engine, function (newScene) { // Wait for textures and shaders to be ready newScene.executeWhenReady(function () { // Attach camera to canvas inputs newScene.activeCamera.attachControl(canvas); // Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { newScene.render(); }); }); }, function (progress) { // To do: give progress feedback to user }); /*------------------------------------------------------------------------------------------------------------*/ // Move the light with the camera scene.registerBeforeRender(function () { light.position = camera.position; }); return scene; } var scene = createScene(); engine.runRenderLoop(function () { scene.render(); }); // Resize window.addEventListener("resize", function () { engine.resize(); }); </script> </body> </html> Also is there a difference between Load and import mesh method?
-
I want to come up with a way to render my own car into the scene and it needs to look similar to the demo here http://www.babylonjs.com/Demos/TheCar/ in this link. I looked into the github repo of this project, I mean, where do I start? And whats a babylonmeshdata and babylonbinarymeshdata and how do we get that?
- 1 reply
-
- replicate
- realisticmodel
-
(and 7 more)
Tagged with: