leorus

Applying textures

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

Share this post


Link to post
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? 

Share this post


Link to post
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

Share this post


Link to post
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;             

                }

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.