Jump to content

Rotating textures


freezereagle
 Share

Recommended Posts

I am trying to apply a different texture to each face of a cube.

I have been able to do this using MultiMaterial and subMeshes, but my images are not oriented on the faces of the box the way I need them to be. 

 

I tried using vAng, wAng, and uAng, but they do not seem to give me the results I need. I just get black faces.

 

I only need to rotate the images by increments of 90 degrees (PI/2)

I cannot pre-rotate the images, because they are used in other areas and the orientation is correct for those purposes.

 

Here is a sample of the code I have so far.

 

    var box = BABYLON.Mesh.CreateBox("Box", 1.0, scene);
 
    var FrontMaterial = new BABYLON.StandardMaterial("cubeFront", scene);
    FrontMaterial.emissiveTexture = new BABYLON.Texture("images/front.png", scene);
 
    var BackMaterial = new BABYLON.StandardMaterial("cubeBack", scene);
    BackMaterial.emissiveTexture = new BABYLON.Texture("images/back.png", scene, false, true);
 
    var LeftMaterial = new BABYLON.StandardMaterial("cubeLeft", scene);
    LeftMaterial.emissiveTexture = new BABYLON.Texture("images/left.png", scene);
 
    var RightMaterial = new BABYLON.StandardMaterial("cubeRight", scene);
    RightMaterial.emissiveTexture = new BABYLON.Texture("imagesright.png", scene);
 
    var TopMaterial = new BABYLON.StandardMaterial("cubeTop", scene);
    TopMaterial.emissiveTexture = new BABYLON.Texture("images/top.png", scene);
 
    var BottomMaterial = new BABYLON.StandardMaterial("cubeBottom", scene);
    BottomMaterial.emissiveTexture = new BABYLON.Texture("images/bottom.png", scene);
 
    var cubeMultiMat = new BABYLON.MultiMaterial("cubeMulti", scene);
    cubeMultiMat.subMaterials.push(BackMaterial);
    cubeMultiMat.subMaterials.push(FrontMaterial);
    cubeMultiMat.subMaterials.push(RightMaterial);
    cubeMultiMat.subMaterials.push(LeftMaterial);
    cubeMultiMat.subMaterials.push(TopMaterial);
    cubeMultiMat.subMaterials.push(BottomMaterial);
 
    box.subMeshes = [];
    box.subMeshes.push(new BABYLON.SubMesh(0, 0,  4,  0, 6, box));
    box.subMeshes.push(new BABYLON.SubMesh(1, 4,  4,  6, 6, box));
    box.subMeshes.push(new BABYLON.SubMesh(2, 8,  4, 12, 6, box));
    box.subMeshes.push(new BABYLON.SubMesh(3, 12, 4, 18, 6, box));
    box.subMeshes.push(new BABYLON.SubMesh(4, 16, 4, 24, 6, box));
    box.subMeshes.push(new BABYLON.SubMesh(5, 20, 4, 30, 6, box));
 
 
    box.material = cubeMultiMat;
 
 
Thanks,
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...