Jump to content

Centralisation of functions created by users


Recommended Posts

Hey Alby... just between you and I... ahem... don't let DK's incessant insistence upon using github... harsh your mellow (bother you).  :)


Just collect all your favorite functions in a big fat text file, try to categorize them somehow, talk talk talk about each one, and publish it somewhere near and dear. (where you can easily add-to/edit it).  You could store it in some secret folder at BabylonDocs.  Wanna?  The viewer wants .md (github markdown)... but it handles plain old ascii text JUST FINE.  Want to make many text documents, start categorizing the funcs?  Can do!  (Wingy hands you a "Just say NO to github" t-shirt)  :)


Keep the url the same... forever... and we'll all go web-sniffin' the "library" whenever we need a useful function.  It is SO easy to do control-f to find something in a big fat .txt file, eh?


GitHub... pfft.  DK has been drinkin' all day, you can tell.   (j/k)  ;)

Link to comment
Share on other sites

This will be my first contribution to a community ever, so, tell me how can I can explain better :
This defines a new Mesh, the "Advanced Ground". All of its cells are squares.
It takes the following argument :

- name : the name of mesh

- width : the width of the ground (in cells)

- height : the height of the ground (in cells)

- size : the size of a cell

- scene : the scene

- fsize : a function I will expain later

The particularity of the advanced ground is that all of its cells are cube. Which means you can change each one of them without modifying the others.
In order to midify the size of the cube of a cell, you have two ways :

The first one is the fsize function. When you make the ground, you give a "fsize" function. This fsize function tells the ground what are the size of its faces.
For instance, in the playground, we have the following fsize function :

function (i, j, width, height, size) {	if (i == 0 || i == width - 1) {		return (size);	}	if (j == 0 || j == height - 1) {		return (size);	}	return (0);}

So, what it says is that, if a face is a border one, then its height will be the size of a cell. (That's what we see on the playground.)


The second one is using the method "UpdateFaces", it takes an array of array which are made this way :
[x, y, s], where x is the x of the face you want to change, y its y, and s the size you want.

For instance, in the playground, we use it this way : 

ground.UpdateFaces([[3, 3, 2], [6, 6, 4]]);

So, what it says is "We want the face at 3,3 to have a height of 2 times the size of a cell, and we want the face at 6, 6 to have a height of 4 times the size of a cell".


You can see the result and try to modify it in the playground :)

When we deal with user input, instead of knowing when the user click, or when the user push a keyboard button, we often want to know if a keyboard button is being pushed, or if a mouse button is being clicked, so the following code can be usefull :

{    var keyPressed = [];    for (var i = 0; i < 255; i++) {        keyPressed[i] = false;    }    window.addEventListener("keydown", function (event) {        keyPressed[event.keyCode] = true;    });    window.addEventListener("keyup", function (event) {        keyPressed[event.keyCode] = false;    });} // Deal with keyboard and creates keyPressed (Use keyPressed[i] to check if key of keyCode i is pressed){    var mousePressed = [];    for (var i = 0; i < 3; i++) {        mousePressed[i] = false;    }    document.addEventListener("mousedown", function (event) {        mousePressed[event.button] = true;    });    document.addEventListener("mouseup", function (event) {        mousePressed[event.button] = false;    });} // Deal with mouse and creates mousePressed (Same as keyPressed[i])

With this, having a timed renderloop can come handy : every 10ms, we want to check userinput, and do stuff.

{    var time = +(new Date).getTime();    engine.runRenderLoop(function () {        if (Date.now() - time > 10) { // Run every 10 ms            time = Date.now();            dealWithCamera();        }        scene.render()    });} // RenderLoop timed
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.

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.


  • Recently Browsing   0 members

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