Jump to content

texture atlas sprites


fenomas
 Share

Recommended Posts

Hi,

 

Just in case anyone else finds this useful:

https://github.com/andyhall/babylon-atlas-sprite

 

A container class that takes a texture atlas (JSON format), creates a plane mesh, and handles the messy job of texturing that mesh with any given sprite out of the atlas.

 

Note: this uses a regular plane mesh internally, so it doesn't have any of the advantages or drawbacks of babylon "Sprite" objects. 

 

Link to comment
Share on other sites

I was thinking about that. I figure, right now this module is just a convenience - it does some math and async loading for the user but it doesn't use the fact that your textures are sewn into an atlas to create any performance or rendering benefit.

 

So if BJS was going to add atlas support, I guess it would be ideal if there's some way to exploit the atlas for performance. I don't know how of course, that's your department :)

Link to comment
Share on other sites

Side note: I did my module this way to keep it simple, but if BJS were to support atlases, it would be more powerful (and maybe easier to understand) if the atlas acted like a provider for textures. Like:

var atlas = new BABYLON.Atlas('atlas.png', 'atlas.json')var texture = atlas.getTexture('walk_0001')myMesh.material.diffuseTexture = texture

I don't know if that would work in practice. I guess it would be very difficult to make the derived texture work like a normal texture (e.g., I guess it would require shader changes for the extracted texture to support uv-offset and scale and repeat modes). But if this could be done, it would be a very clean and easy way for the user to use texture atlases.

Link to comment
Share on other sites

Hi fenomas,

 

I have to notice that you to often forget (can voluntarily be) to put semicolons in all your codes. But if your code is to compress, that is likely to cause many bug. Moreover the engine Javascript, him, systematically add them at the time of interpretation if they are missing. what makes make works in more with the engine Javascript unnecessarily if the semicolon existed.

Link to comment
Share on other sites

Hi dad72,

 

Semicolons in JS are basically a matter of preference and coding style. Leaving them out doesn't affect performance, and the code I linked should run fine minimized. The arguments for and against semicolons have been well hashed out by the JS gods, but mostly I omit them lately because I work with other libraries written in that style.

Link to comment
Share on other sites

The performances have a very tiny impact, even at all, but it is a work furthermore for the JavaScripts engine which adds the semicolons if they are missing.
Your code cannot be minimized. I already tested and you to find itself with bugs.
I think that those which omit to add points commas by style, is not a good thing. Javascript and enough "cool" not to inform us of this kind of error, but it is an error, not a style.
 
If you to look in all the other languages (C#, C, C++, PHP, CSS and others) the semicolon is obligatory, if not that an error announces you. Javascript does not say anything to him, but it is an invisible error which appears if you to minimize your code for example. I read that in books writes by experts that this semicolon forget is an error.
 
I think it is not because some libraries do not put of semicolon, did not make a mistake. Their code can not be compressed down and put the work in JavaScript engine. Look in Babylon engine, the semicolon is present everywhere.
 

 

Link to comment
Share on other sites

dad72, omitting semicolons in JS (when they're optional) is a matter of style, and not something we need to debate here. It's not an error, and the performance difference is not measurable (you might as well tell me to use shorter variable names!).

 

Also, the module works for me when minified with closure compiler. If you've found a bug please file a github issue!

Link to comment
Share on other sites

No offense taken ;)  It's just that ASI was a big thing in the JS world a few years ago, and has already been debated by the experts from every angle. Brendan Eich summed the whole thing up as well as anyone.

 

And again, if my module breaks under minification please file a bug or tell me how to reproduce.

Link to comment
Share on other sites

I send you the file minimize and what I use for minimize :

 

http://www.castorengine.com/babylon/atlas.zip

 

I do not use your script personally, but it is that I is so much to accustom to write my code with semicolons, especially on languages like PHP or C#, if a semicolon is to forget, it is an error, therefore I take the good practice to put some at each end of instruction. (I think that it is a good practice to take when one uses several computer programming languages.)
 
Link to comment
Share on other sites

Uh, what minifier did you use on that? Was it made to minimize specific code in a specific format? It appears to have randomly stripped all linebreaks without regard to context.

 

If you try a general-purpose minifier like closure/jsmin/uglify it should work okay.

Link to comment
Share on other sites

minifier simply removes the line breaks, like Babylon does. What I used was previously used by babylon.

 

If you add semicolons, this fixes the problem, and the script works. That is why I said that the missing semicolon is a syntax error that Javascript does not report (javascript is less strict).

Link to comment
Share on other sites

Sigh.

 

 

1. Syntax rules for JS are defined by the ECMA 262 specification, not by this or that minifier.

 

2. Stripping all linebreaks out of JS code isn't minifying, it's just stripping linebreaks, and it will break some valid JS -- even if semicolons are used. It happens not to break babylon, but that's a result of how babylon is formatted - it's not something that's true of all valid javascript.

 

 

It's fine that you have a coding style you're happy with, but that's no reason to claim anything else is a syntax error. If you want to understand when semicolons in JS are and aren't required, here is the spec.

Link to comment
Share on other sites

I think we do not we understand, probably the language barrier for me.
 
Try to code in another language with your style, genre PHP you will have problems. I'm just saying it's a good habit to have.
I show you with me fichier.min adding semicolons, I run your script, it work, so now it does not work because they are missing altogether.
 
brief: Try to forget semicolons in compiled languages, you do not compile.

 

I use the word "error", I should not. Javascript not consider it really a mistake, but Javascript engine added them when it is missing. why not add them to his place by good habit.

Link to comment
Share on other sites

But, Java, C#, C++, PHP and other use semicolons.

but good, I do not go further, that is useless. You are right, that it bad idea to put semicolons.
But one distant from my simple matter from "why?"

 

Let's go about it, I necessarily wrong. But for me, it stings my eyes, it's like punctuation in a book. I'm sure the other person thinks that the semicolons are useful but say they are not useful.

Forget my question. I do not say that you should do otherwise, I wondered why this style.

 

Jerome: je parle dans des langages que l'on utilise que un point virgules oublier est une erreur et cela dans beaucoup de langage et que c'est une bonne habitude à prendre, pas un style. C’est comme dans un livre, la ponctuation, c’est pas une question de style elle est la pour aider la lecture. mais chacun fait ce qu'il veux, je demandait pourquoi cela (ce que vous appeler "style") moi je vois pas ou est le style, mais bon, la mode et le style, c’est comme les couleurs ?

 

 

Link to comment
Share on other sites

:)

Tu avais dit à Fenomas que c'était une erreur de syntaxe corrigée par l'insertion automatique de points virgules à la compilation.

Ce n'est pas une erreur de syntaxe, il a raison : les points virgules ne sont pas obligatoires comme séparateur d'expressions (sauf cas très particuliers).

 

Donc ne pas mettre ou mettre des points virgules n'est ensuite que ce que l'on appelle une question de style.

On peut argumenter que c'est une bonne habitude, que c'est cohérent avec beaucoup d'autres langages (pas tous : ruby et python sont bien plus lisibles que JS et n'ont pas de points virgules), etc.

Tout est valable : il n'y a pas de jugement de bonne ou mauvaise pratique ici.

Le mot "style" est utilisé par Fenomas pour dire que c'est juste un choix syntaxique particulier du développeur (tout comme cela pourrait être autre chose, comme mettre des points virgules au début de chaque ligne par exemple, ce qui reste valide) et pas une règle du langage.

Il préfère ne pas en mettre, c'est son choix et c'est valide.

Je sais que ça n'a pas d'utilité en fin de ligne, j'en mets par habitude (parce que je suis habitué à lire du JS comme ça, comportement purement humain... et un peu stupide parce que quand je repasse à Ruby, je continue d'en mettre et le compilateur Ruby râle :P ) et ça reste valide.

 

 

English in brief :

Fenomas is right. JS is a standardized language and its rules are written : the semi-colons are not mandatory after statements (except some special case).

So omitting semi-colons is definetly not a syntax error.

That's why choosing to put or to omit them is then just a question of style... as any other syntaxly correct style would be acceptable : put semi-colons on each line start, ident with 36 tabs, etc

Link to comment
Share on other sites

> You are right, that it bad idea to put semicolons.

 

I don't think anyone is saying that. Both styles are valid, and I think using semicolons is safer for most people, especially beginners. All I'm saying here is that it's a matter of style, not errors, correctness, performance, etc.

 

I wondered why this style.

 

As I said, recently I've been working with a lot of libraries written in this style. So I'm used to it. No other reason.

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