Jump to content

Applying textures


leorus
 Share

Recommended Posts

I have recently started to make a simple game with babylon.js. I have created a scene and a sphere(ball). When I tried to apply texture to the sphere with the following code:

var ballTex = new BABYLON.StandardMaterial("texture1", scene);
ballTex.diffuseTexture = new BABYLON.Texture("ball2.png", scene);

ball.material = ballTex;

 

But the sphere is not visible.

I tried full path and then also same thing happened.

But when I applied color with

ballTex.diffuseColor = new BABYLON.Color3(1.0, 0, 0);
ball.material = ballTex;

the sphere is viosibel. What  and where is the problem?

 

leorus

Link to comment
Share on other sites

Hi,

 

I encountered the same problem and it was in my case a problem of file path. When the texture is not found the mesh is drawn with the diffuse color. Do you have an error in the console that would help narrow down the problem ? Also where is the texture file located relative to the html page running BabylonJS ?

 

Also, it's hard to suggest anything without a bit of context. Do you have other textured meshes that display correctly? 

Link to comment
Share on other sites

the ball2.png file is in the same dir as the html file. I have also placed the same file in its parent dir also. There is no error message in the console. The html file is in babylon\breakout\bout\index.html. the png file is in both babylon\breakout and babylo9n\breakout\bout dirs. I tries to apply texture to other object also. but, same thing happens - that object alos vanishes from the scene.

 

leorus

Link to comment
Share on other sites

I have tried diffuse, specular and emmisive , but the same thing happens.web links:|

www.namchennai.com/babylone/Breakout/BOut/index.html ( with diffuse color) and

www.namchennai.com/babylone/Breakout/BOut/index1.html ( with diffuse Texture).

The code is attached:

applyTextures();

function applyTextures()
 {
     var ballTex = new BABYLON.StandardMaterial("texture1", scene);
     ballTex.diffuseTexture = new BABYLON.Texture("ball2.png", scene);
      //ballTex.diffuseColor = new BABYLON.Color3(1.0, 0, 0);
      ball.material = ballTex;                  
                     var wallTex = new BABYLON.StandardMaterial("texture1", scene);
                   wallTex.diffuseColor = new BABYLON.Color3(0, 0, 1.0);
                     wallTex.alpha = 0.5;
                     //wallTex.diffuseTexture = new BABYLON.Texture("Wall.jpg", scene);
             Lwall.material = wallTex;
                     Rwall.material = wallTex;
                     ceiling.material = wallTex;
                     ground.material = wallTex;             

                }

Link to comment
Share on other sites

You seem to have edited your post. I had the following line in the notification email that I got for your post:

 

ballTex.emissiveTexture = new BABYLON.Texture("C:\users\admin\Documents\babylone\BreakOut\BOut\ball2.png", scene);

 

Your issue could be relative to:

http://www.html5gamedevs.com/topic/5255-using-non-minified-babylonjs-version/?p=32599

 

And since you are on Windows, this tool could help you: https://github.com/BabylonJS/Babylon.js/tree/master/Tools/BuildOurOwnBabylonJS

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...