Quantcast
Viewing all articles
Browse latest Browse all 388

Rounded Box

Hi everyone. First of all I would like to apologize in case this topic was already discussed here but I just couldn't find an answer anywhere. I am new to BABYLON, WEBGL and also 3D Programming in general so please excuse me if my queries seem not to complicated.

 

My question is: Can a rounded box be created in BABYLON (without the use of other 3d tools and export to BABYLON) ?

 

What I am trying to achieve is creating a dice that has rounded corners. I have created a box using BABYLON.Mesh.CreateBox and used subMeshes to add 6 images with the dice numbers as diffuseTextures for each face of the Dice. This looks ok, it's just that I need the dice to have rounded corners and edges. Can anybody please help me with this ? Thanks a lot in advance.

 

This is the code I used to create my dice:

 

  this.dice = new BABYLON.Mesh.CreateBox('dice', 3, BjsApp.scene);
  this.dice.showBoundingBox = false;
 
  var f = new BABYLON.StandardMaterial("material0", BjsApp.scene);
  f.diffuseTexture = new BABYLON.Texture('assets/images/DiceFace1.png', BjsApp.scene);
 
  var ba = new BABYLON.StandardMaterial("material1", BjsApp.scene);
  ba.diffuseTexture = new BABYLON.Texture('assets/images/DiceFace2.png', BjsApp.scene);
 
  var l = new BABYLON.StandardMaterial("material2", BjsApp.scene);
  l.diffuseTexture = new BABYLON.Texture('assets/images/DiceFace3.png', BjsApp.scene);
 
  var r = new BABYLON.StandardMaterial("material3", BjsApp.scene);
  r.diffuseTexture = new BABYLON.Texture('assets/images/DiceFace4.png', BjsApp.scene);
 
  var t = new BABYLON.StandardMaterial("material4", BjsApp.scene);
  t.diffuseTexture = new BABYLON.Texture('assets/images/DiceFace5.png', BjsApp.scene);
 
  var bo = new BABYLON.StandardMaterial("material5", BjsApp.scene);
 
  bo.diffuseTexture = new BABYLON.Texture('assets/images/DiceFace6.png', BjsApp.scene);
 
  var multi = new BABYLON.MultiMaterial("nuggetman", BjsApp.scene);
  multi.subMaterials.push(f);
  multi.subMaterials.push(ba);
  multi.subMaterials.push(l);
  multi.subMaterials.push®;
  multi.subMaterials.push(t);
  multi.subMaterials.push(bo);
  
  this.dice.subMeshes = [];
  var verticesCount = this.dice.getTotalVertices();
  this.dice.subMeshes.push(new BABYLON.SubMesh(0, 0, verticesCount, 0, 6, this.dice));
  this.dice.subMeshes.push(new BABYLON.SubMesh(1, 1, verticesCount, 6, 6, this.dice));
  this.dice.subMeshes.push(new BABYLON.SubMesh(2, 2, verticesCount, 12, 6, this.dice));
  this.dice.subMeshes.push(new BABYLON.SubMesh(3, 3, verticesCount, 18, 6, this.dice));
  this.dice.subMeshes.push(new BABYLON.SubMesh(4, 4, verticesCount, 24, 6, this.dice));
  this.dice.subMeshes.push(new BABYLON.SubMesh(5, 5, verticesCount, 30, 6, this.dice));
  this.dice.material = multi;

Viewing all articles
Browse latest Browse all 388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>