MasterSword314

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. Hello, I am new to Babylon.js, and fairly new to JavaScript. I have a project in which I need to give each face on a cube I am making a different texture. I have read articles on SubMeshes, but to no avail, because I don't understand about the parameters for "box.subMeshes.push(new BABYLON.SubMesh(#,#,#,#,#,box));" . Could anyone help? I tried the following slightly messy code: var canvas=document.getElementById("nuggetCanvas");var engine=new BABYLON.Engine(canvas, true);var createScene=function(){ //scene and background color var scene=new BABYLON.Scene(engine); scene.clearColor=new BABYLON.Color3(1,1,1); //create camera var camera=new BABYLON.ArcRotateCamera("camera",1.0,1.0,12,BABYLON.Vector3.Zero(),scene); //attach camera to canvas camera.attachControl(canvas,false); //add a light var light=new BABYLON.HemisphericLight("hemi",new BABYLON.Vector3(0,1,0),scene); //reflect the light off the ground to light the mesh bottom light.groundColor=new BABYLON.Color3(0,0,0.5); //create a builtin shape var box=BABYLON.Mesh.CreateBox("box",5,scene); box.showBoundingBox=false; //Define a material var f=new BABYLON.StandardMaterial("material0",scene); f.diffuseColor=new BABYLON.Color3(0,0,0.75); f.diffuseTexture=new BABYLON.Texture("nugget.png",scene); var ba=new BABYLON.StandardMaterial("material1",scene); ba.diffuseColor=new BABYLON.Color3(0,0,0.75); var l=new BABYLON.StandardMaterial("material2",scene); l.diffuseColor=new BABYLON.Color3(0,0,0.75); var r=new BABYLON.StandardMaterial("material3",scene); r.diffuseColor=new BABYLON.Color3(0,0,0.75); var t=new BABYLON.StandardMaterial("material4",scene); t.diffuseColor=new BABYLON.Color3(0,0,0.75); var bo=new BABYLON.StandardMaterial("material5",scene); bo.diffuseColor=new BABYLON.Color3(0,0,0.75); //put into one var multi=new BABYLON.StandardMaterial("nuggetman",scene); multi.subMaterials.push(f); multi.subMaterials.push(ba); multi.subMaterials.push(l); multi.subMaterials.push(r); multi.subMaterials.push(t); multi.subMaterials.push(bo); //apply material box.subMeshes=[]; var verticesCount=box.getTotalVertices(); box.subMeshes.push(new BABYLON.SubMesh(0, 0, verticesCount, 0, 6, box)); box.subMeshes.push(new BABYLON.SubMesh(1, 1, verticesCount, 6, 6, box)); box.subMeshes.push(new BABYLON.SubMesh(2, 2, verticesCount, 12, 6, box)); box.subMeshes.push(new BABYLON.SubMesh(3, 3, verticesCount, 18, 6, box)); box.subMeshes.push(new BABYLON.SubMesh(4, 4, verticesCount, 24, 6, box)); box.subMeshes.push(new BABYLON.SubMesh(5, 5, verticesCount, 30, 6, box)); box.material=multi; box.material=f; return scene;};var scene=createScene();engine.runRenderLoop(function(){ scene.render();});//resizewindow.addEventListener("resize", function(){ engine.resize();});The values I have inside the BABYLON.SubMesh are placeholders, part of it I got from examples. I am not sure what to use for the parameters. What are the indices? In one example for a cube I saw, the developer used 4 vertices as the vertex count instead of 8 (the number of vertices a cube has), which I do not understand. Thanks for any help you can provide.
  2. Hey, I am new to Babylon.js. I began by making a cube with a solid diffuse color. I wanted to add my own texture to it, but nothing I did worked: it just showed my background color for the scene. I went to the example 04 on the Babylon.js playground for Materials and could not find anything that I was doing wrong. I decided to download the zip file of that particular section locally and see if there was a problem with my HTML. I still couldn't find anything. I then ran the sample program and none of its textures showed up either. I can't fathom how the same file would work on the playground, but not stored locally... Please help me with this, it would be much appreciated.