Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
removeAnimator(a)

madalin
Registered User
Quote
2017-01-23 12:36:49

I am using CopperLicht 1.12 to load a .ccbjs file created in CopperCube 5.4.2 as the main scene.

I am uploading at runtime some blocks as .ccbz file created in CopperCube 5.4.2

The main scene contain a grid, a camera and an original mesh who has two animators ('on_click') and ('keypress')

The imported blocks has no animators. When a block is imported (uploaded), I am cloning the two animators of original mesh and add them to new uploaded block (mesh).

All work fine and the uploaded blocks can be dragged by the added animator
 Drag3D Object by Axis Constraint  
and dropped by right mouse button click = the second animator.

But I want to remove the two animators from the blocks already moved. For that I am using
var animator = yourSceneNode.getAnimatorOfType('keyboardcontrolled');
// store the animator for later adding it again somehow
yourSceneNode.removeAnimator(animator);

But that doesn't work for me. The blocks can still be dragged, yet they appear without animators (see console messages). Can anyone help to remove animators? Thanks in advance.

the code I used for buttons function to load the blocks at runtime:

loadModel = function(path){
engine.load(path, true, function(){
nodeindex ++;
var importedNode = engine.getScenes()[1].getSceneNodeFromName('mesh');
engine.getScene().getRootSceneNode().addChild(importedNode);
var scenesArray = engine.getScenes();
scenesArray.pop();
importedNode.Name = importedNode.Name + nodeindex.toString();
importedNode.Id = nodeindex;

var meshNodes = scene.getAllSceneNodesOfType('mesh');
var numberOfNodes = meshNodes.length;
console.log("Number of Nodes: ",numberOfNodes);
for(var i=0;i<numberOfNodes;i++){
console.log("Name: ", meshNodes[i].Name, " index: ",meshNodes[i].Id)
}

var originalMesh = scene.getSceneNodeFromName('mesh');
var originalAnimatorsArray= originalMesh.getAnimators();
var animator1 = originalAnimatorsArray[0].createClone(importedNode, scene, originalMesh.Id, importedNode.Id);
var animator2 = originalAnimatorsArray[1].createClone(importedNode, scene, originalMesh.Id, importedNode.Id);
importedNode.addAnimator(animator1);
importedNode.addAnimator(animator2);

if (nodeindex != 1) {
console.log("Nodeindex: ",nodeindex);
var meshToRemoveAnimators = scene.getSceneNodeFromName('mesh' + (nodeindex - 1).toString());

var animatorToRemove1 = meshToRemoveAnimators.getAnimatorOfType('');
var animatorToRemove2 = meshToRemoveAnimators.getAnimatorOfType('keypress');

console.log("animatorToRemove1:", animatorToRemove1);
console.log("animatorToRemove2:", animatorToRemove2);
meshToRemoveAnimators.removeAnimator(animatorToRemove1);
meshToRemoveAnimators.removeAnimator(animatorToRemove2);
console.log(meshToRemoveAnimators.Name,": ",meshToRemoveAnimators.getAnimators());
console.log(meshNodes[1].Name,": ",meshNodes[1]);
}

})
};


The link to the working sample: http://estudio3d.eu/blocks


niko
Moderator
Quote
2017-01-24 05:08:02

Hm, you are removing the animator "keyboardcontrolled" as it seems. The extension behaviors created for CopperCube are not ordinary animators, but of type AnimatorExtensionScript. All of them have the name 'extensionscript'.

So you would be able to remove them with that name.
For WebGL, the animator object additionally then has a property named 'JsClassName', if it is a AnimatorExtensionScript. That then has the name as specified in the extension script, like "action_Drag3DObject_axis", you could check for that additionally, and see if you want to delete that animator.

Hope this helps!


madalin
Registered User
Quote
2017-01-24 07:19:02

 keyboardcontrolled
was just as example.

Actually I am removing
'on-click'
and
'keypress'


Beware, the Forum editor doesn't allow "on-click" in a body, have to remove the dash.

It's a composed animator
1: on_click do Drag 3D Object and
2. on right click (keypress event) do Drag3D Object but with all axis restricted, in order to drop the node (mesh).

🔎︎


I need to drop the object not only on-click object, but on-click anywhere on the scene, included outside object.
Maybe I can alter the extension script, to drop node not only on-click object but on-click outside object too. In this mode I need to use only one animator: on-click do Drag·dObject.

Thank you for the advice. I'm going to try the property "JSClassName" and I'll let you know if I get anything.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inte?national" (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