Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
New Plugin: behavior_DoOnFunctionCall

BMSKiwi
Guest
Quote
2014-10-13 05:12:03

I wrote a new extension will hopefully be available soon on the extensions page.

behavior_DoOnFunctionCall

1) Attach this behaviour to a given node (or root)
2) Create a list of actions to execute
3) Type a name string into the FunctionName field

At runtime, this tiny extension will create a global function object called 'FunctionName'. Calling FunctionName() from anywhere in your document - such as a button or some other user interface - will then execute the list of CCB actions you attached.

You can even invoke the actions from another CCB action, using the 'execute javascript' action.

This rectifies the lack of an API for most CopperCube actions. It lets you effectively build your own simple API, using the complete range of CopperCube actions, and accessible in the global scope. It is tested and working on WebGL and Flash, and probably the other targets too.


santito
Registered User
Quote
2014-10-13 06:47:09

Wow, that's pretty good work there, BMSKiwi.

Will this extension let you invoke the actions of an external, non-CopperLicht JavaScript runtime script?

I was thinking that maybe a CopperCube made WebGL scene can be further enhanced through an outside 3D physics engine, like for an example this one called "Cannon.js" from here: http://schteppe.github.io/cannon...

The reason that I am asking about this, if you look through the Cannon.js website's examples and demos, you will notice that their physics engine seems to really have an emphasis on gravity. And the ability to control, deploy and assign gravity to any node in Coppercube is something that I am really interested in.

I don't know if you have already noticed and read my previous thread titled "Is Point of Gravity Posible in Coppercube?", but if you have, I'm sure you will understand why I am asking about all of this.

Now, from all of the different Cannon.js demos on their site, there is one in particular Cannon.js demo that I saw that will fit right in with the Point of Gravity feature that I am hoping for Coppercube to have, and it is this one: http://schteppe.github.io/cannon...

I don't know if your new behavior_DoOnFunctionCall plugin will be able to help me on this little challenge of mine, that's why I will leave this matter to the experts like you and hope for the best.


BMSKiwi
Guest
Quote
2014-10-13 08:58:40

Hmmm, this not so easy Amigo.

Integrating cannon.js into CCB is something else altogether. This extension won't help. CCB5 has a physics engine built in, bullet.js, which presumably supports gravity but is not available in WebGL for performance reasons. (I think this is a mistake)

Your best move is to petition Niko to provide physics in the WebGl and Flash targets.


santito
Registered User
Quote
2014-10-13 15:43:37

@BMSKiwi: Yea, I had a feeling about that. You see, I learn something new everyday. Thanks for your sincere and informative response. Well, Niko did say me if (quote) "we get a few more people wanting this feature, I'll implement this in a future version of CopperCube", so if you like my idea about the "Point of Gravity" feature, then by all means please join the small, but growing list of us who want this feature.


niko
Moderator
Quote
2014-10-13 19:13:19

Nice addition. Will be added to the website soon.

About bullet.js: That one doesn't support collisions between bodies and 'real' 3d geometry, so it won't work, unfortunately.


niko
Moderator
Quote
2014-10-15 05:38:12

Update: It's uploaded now to the extension website.


kurtmel
Registered User
Quote
2015-07-24 20:07:12

@BMSKiwi, Thanks for this!! I think this may solve my problem in terms of calling SCORM functions (E-learning standard in JS) form CC5. I'm still not quite sure of the implementation though. This is basically how SCORM works, a Student clicks a hyperlink for a SCORM conformant lesson there's a SCORMAPI.js file already loaded within the html file in the API file there are two of the most basic calls to make a Flash or HTML-based lesson SCORM conformant/compliant -

LMSinitialize() and before unloading the CC file would pass LMSfinish() to the SCORMAPI.js file 
there are numerous other values like lesson_Status etc. which are done by LMSsetValue() or LMSGetValue() to set scores, status or retrieve bookmarks etc.
you would use data pairs LMSSetValue ("lesson_status", "Completed") The LMSfinish() is usually set with a BeforeUnload action

So, how would I best use you great new behavior DoOnFunctionCall and does every possible value pair of SCORM that I want to use be assigned as vars under "FunctionCall" e.g., Var Init=LMSinitialize(); Var Quit=LMSFinish();


An example of how this might work with this behavior would be MOST helpful, and you can find out more about SCORM 1.2 calls by getting the following PDF file http://scorm.com/wp-content/asse...

Thanks!! and thanks for all the great work at providing this behavior, I hope it really helps solve this issue for me.


Chris
Guest
Quote
2022-12-03 12:53:57

I'm reading these old threads and wonder if there is a straight forward solution for physics in CCB.
Is cannon.js still the way to go in 2022/23; or are there any other alternatives?

Is there an more indepth "How-to" available on doing it with the neat tool from @BMSKiwi "behavior_DoOnFunctionCall"?

May I ask if anyone got a simple working example of any physics in CCB with WebGL output?
I've seen the cannoncar example; i really like it.
But i don't really see how I can use cannon in CCB; for example with chain-like-physics.

Another example uses Copperlicht; but I have no clue how to implement it into CCB - never thought about it until now.

I think @VP shared such a CCB file back in the days; it's just not online anymore.

Thanks @all


Chris
Guest
Quote
2022-12-03 13:02:23

@niko: I just found out that there is an "ammo.js" ported from bullet.js - do you think this can be just swapped and it will work?
https://github.com/kripken/ammo....

wrote:
Nice addition. Will be added to the website soon.

About bullet.js: That one doesn't support collisions between bodies and 'real' 3d geometry, so it won't work, unfortunately.



okeoke
Registered User
Quote
2022-12-04 14:41:30

@Chris

Hi,

You can find a sort of working cannon js example here:
https://youtu.be/GrxBSINym_8

The idea is that you use cannon js for physics calculation, and only use ccb for the graphics representation.


Chris
Guest
Quote
2022-12-06 02:41:48

@okeoke - thx!


Chris
Guest
Quote
2022-12-06 02:46:28

Do you know if ccb uses "mesh.useQuaternion = true;" like three.js does? Couldn't find a lot of infos on it...

https://github.com/schteppe/cann...


okeoke
Registered User
Quote
2022-12-07 12:35:06

Nope, I believe, ccb doesn't use quaternion coordinates at all. I used a custom function to recalculate those to euler:
const radsToDegrees = 180 / Math.PI;
function quaternionToEuler(q) {
var w = -q.w;
var x = q.x;
var y = q.y;
var z = -q.z;

var t = 2 * (w * y - z * x);

return {
// X-axis rotation
x: (Math.atan2(2 * (w * x + y * z), 1 - 2 * (x * x + y * y))) * radsToDegrees,
// Y-axis rotation
y: (t >= 1 ? Math.PI / 2 : (t <= -1 ? -Math.PI / 2 : Math.asin(t))) * radsToDegrees,
// Z-axis rotation
z: (Math.atan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z))) * radsToDegrees,
};
}

Also Z axis direction in coppercube and cannons js are pointed to the opposite sides. So when translating it from cannon you should change z to -z. Same with rotation, but you should do w = -w and z = -z.

There is also a built in cannon method in Quaternion class to do the translation to euler, but it didn't work for me:
https://schteppe.github.io/cannon.js/docs/classes/Quaternion.html
It's called toEuler - I can't pass the anchor link here.


Chris
Guest
Quote
2022-12-13 13:22:09

@okeoke

thanks, took me some time to wrap my head around it :)

@all
Does someone know how to replace bullet.js from CCB with ammo.js? I'd like to get (kinda need) bullets with physics and physics within WebGL.

So far the samples rock (cannon.js); but I'm having a little hard time understanding the basics of how to implement it.
The car is awesome; but it's not suitable for my gameplay.

Does anyone got a simple example running which uses some "scale" physics; like the kids used to play back in the old days in the park; bouncing up and down each one another? Or some kinda carousel?


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact