jangbi

Members
  • Content count

    9
  • Joined

  • Last visited

About jangbi

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. @JohnK I've already read that page. Be more specifically, in this demo, i want to move the cylinder's location to (0,0,1), but not using the position.z += 1, use the local frame of reference and a local orientation vector to finish the translation.And calculate the correct segment's vertex position while need it.
  2. Here's the demo. https://www.babylonjs-playground.com/#LS4I1S Firstly, I want to move the cylinder forward(in local axes), so i use mesh.translate(BABYLON.Vector3.Forward(), 1). The cylinder move 1 unit in the y axis instead of z axis(that's what i want), I can understand why the cylinder move in the y axis(because of the rotation), but I want to know how to move the cylinder on the x-z plane forward after rotation by using the local frame of reference. Secondly, how to compute the segments' two end points dynamically, is my code right? this.mesh.computeWorldMatrix(); let matrix = this.mesh.getWorldMatrix(true); this.vertex1 = BABYLON.Vector3.TransformCoordinates(this.vertex1, matrix); this.vertex2 = BABYLON.Vector3.TransformCoordinates(this.vertex2, matrix); (My english is poor, please forgive me)
  3. https://stackoverflow.com/questions/50235364/create-mesh-before-render-in-babylon-js @Deltakosh Is my explanation correct?
  4. @jerome @Magilla I know what you guys mean. But my point is, my expecting code behavior is to generate a series of spheres instead of just 3. And if you add snake.pop().dispose() before each render, you will see there's only one sphere, not three.
  5. https://www.babylonjs-playground.com/#RLJDN8 @Deltakosh
  6. @Deltakosh What's the meaning of this link?
  7. let canvas, engine, camera, scene; function initEngine(){ canvas = document.getElementById("renderCanvas"); engine = new BABYLON.Engine(canvas, true); } function createScene(){ initEngine(); let scene = new BABYLON.Scene(engine); camera = new BABYLON.ArcRotateCamera("camera", Math.PI / 2, Math.PI / 2, 4, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, true); let light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0,1,0), scene); let ground = BABYLON.MeshBuilder.CreateGround( "ground", { width:30, height:30 }, scene ); ground.position.y -= 0.5; let sphere1 = BABYLON.MeshBuilder.CreateSphere( "sphere1", { }, scene ); let sphere2 = sphere1.clone("sphere2"); let sphere3 = sphere1.clone("sphere3"); sphere1.position.z = -18; sphere2.position.z = -19; sphere3.position.z = -20; let snake = [ sphere1, sphere2, sphere3 ]; (function(){ let counter = 4; scene.registerBeforeRender(function(){ let newOne = BABYLON.MeshBuilder.CreateSphere( "sphere" + counter, { }, scene ); let head = snake[0]; newOne.position = head.position; newOne.position.x += 0.02; snake.unshift(newOne); ++counter; }); })(); window.addEventListener("resize", function(){ engine.resize(); }); return scene; } scene = createScene(); engine.runRenderLoop(function(){ // box.position.z += 0.01; scene.render(); }); @DeltakoshHere's the minimal demo.
  8. @Deltakosh Thanks for your answer, but as for my first question, I expected that will produce a series of spheres, but there're only three spheres existed all the time, I want to know what's wrong with my implementation.
  9. I want to create new mesh before each render, here's my code: let snake = [ sphere1, sphere2, sphere3 ]; (function(){ let counter = 4; scene.registerBeforeRender(function(){ let newOne = BABYLON.MeshBuilder.CreateSphere( "sphere" + counter, { }, scene ); let head = snake[0]; newOne.position = head.position; newOne.position.x += 0.02; snake.unshift(newOne); ++counter; }); })(); My expecting behavior is to create a series of spheres, each position.x is slightly higher than the previous one. However, there are only three meshes in the scene after rendering, like this: I want to know what is wrong with my code, and how to implement it properly? By the way, what is the difference between scene.removeMesh(mesh) and mesh.dispose()? Here's the relative link in stackoverflow: https://stackoverflow.com/questions/50235364/create-mesh-before-render-in-babylon-js