Jump to content

Creating same texture. Is this bad?


ozRocker
 Share

Recommended Posts

I've been running these commands every time a new object is added to the scene:

var material = new BABYLON.StandardMaterial("material01", Assets.scene);
material.diffuseTexture = new BABYLON.Texture("images/textures/wood.jpg", Assets.scene);

So if 100 cubes are added to my scene this would get called 100 times. Am I doing this wrong?  Would this end up loading the same image into memory 100 times?  Should I be creating one wooden texture and pointing all cube textures to that one?  Should I be doing the same with materials, assuming the diffuse colour doesn't change? 

Link to comment
Share on other sites

The texture file itself will be loaded only once. The texture data is cached internally from the engine.
But you should also try to reduce the amount of texture/material instances you create. It will save a bit of memory and for the materials it will also improve the performance a bit. Switching between different materials during the rendering process adds some overhead.

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