Jump to content

Is there a standard format for an extension file?


JohnK
 Share

Recommended Posts

Some background followed by several related questions.

I have written a Javascript file myExtensionFile.js to submit for consideration as an extension.

The current format of the file consists of a public function that calls several private functions  and looks like this

var private1 = function(a, b) {
    //code here 
}

var private2 = function(a, b) {
    var myx = private1(c, d);    
    //more code here 
}

var myExtension = function(a, b, c) {
    //some code
    var myx = private1(m, n);
    //more code
    var myy = private2(p, q);
    //even more code
}

Once loaded you call it using myExtension(a, b, c).

Now I have noticed that some files in the Babylon Extensions use BABYLONX

Question 1 Should myExtensionFile.js be re-written so that it is called using BABYLONX.myExtension(a, b, c)?

Question 2. If I changed to using BABYLONX is this the correct way to re-write  myExtensionFile.js?

var private1 = function(a, b) {
    //code here 
}

var private2 = function(a, b) {
    var myx = private1(c, d);    
    //more code here 
}

var BABYLONX;
(function (BABYLONX) {
    var myExtension = function(a, b, c) {
        //some code
        var myx = private1(m, n);
        //more code
        var myy = private2(p, q);
        //even more code
    }
 }());

Something to do with closures (I think) but haven't got to grips with them as yet.

Question 3. Would using BABYLONX in this way clash with other extensions?

Question 4. I can see that using BABYLONX rather than BABYLON shows in code that an extension is needed and should be loaded but would using just BABYLON be better for continuity? Is it possible to do that?

Question 5. How would you format the myExtensionFile as typescript. I know I could just change the js file extension to ts but to be  'proper' typescript should I be using modules and classes?

Question 6. For someone with a limited skill set  (like me) would it be useful to have an 'How To Format A Babylon Extension for Javascript and Typescript' document?

                   When I am clear whether there could be a standard format for writing extension code, what the format looks like and how to do it I wouldn't mind having a go at the documentation.

                  Whether I will ever have sufficient clarity is another issue.

 

Link to comment
Share on other sites

1) This is your decision, actually. namespace is nice to have, but sometimes it is not needed. I would personally use my own namespace.

2) not entirely. You can try using typescript if you want to use extensions, or check a simple .js file from BABYLON. What you are missing is adding this function to the BABYLONX variable. (https://github.com/BabylonJS/Babylon.js/blob/master/src/Layer/babylon.layer.js#L94 for example)

3) Nope, unless you use the same class names and of course only if the other extension is loaded.

4) BABYLON is reserved to core functionality alone. The same clash that might happen with BABYLONX extensions can of course happen with BABYLON. There is no law against it, and everything is allowed, but for the sake of separation and to keep the users informed that what they are using is an extension and not a part of the core, using BABYLONX is better.

5) Your decision alone. I love the way typescript organizes the code, but this is a personal opinion. Use classes, or don't, up to you.

6) There are no official extensions. There is just a collection of useful applications that happen to use Babylon in a nice way :) 

I think that the first misconception is that the extensions are a part of the community's work. The extensions repository is simply a collection of nice tools. It is a service for the users. This is not an official supported repository. It is more for the extension creators  and the community to use. You can do whatever you want, really. 

I created once https://github.com/BabylonJSX , but I don't quite maintain it at the moment. This is also nothing official. Just a fun side project(s). A place for developers to find cool babylon plugins.

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