Deleting objects using Javascript

Deleting objects using Javascript

I have the items in the attached list. I'm trying to delete "head-tongue" using Javascript but having no luck. I've tried:

Code:
delete doc["head-tongue"];

var name = "head-tongue";
delete doc[name];

var root = doc.root();
delete root["head-tongue"];

var root = doc.root();
var name = "head-tongue";
delete root[name];

Nothing seems to work. Either throws an error (no surprise) or does nothing.

I will be the first to admit that Objective C is my forte and Javascript is... well, falls out after Lisp.

Thanks!
 

Attachments

  • From Clipboard.jpg
    From Clipboard.jpg
    38.5 KB · Views: 304
Hmm, well document.root points to the thing you'd expect it to. I'm not sure why you expect document[...] to do what you want (yeah it would be nice if it did, but...)

So you probably need to write a function that finds objects by name, something like:

Code:
function findObjectByName( name, parent ){
  for( var i = 0; i < parent.childCount(); i++ ){
    var obj = parent.childAtIndex(i);
    if( obj.getParameter("name") === name ){
      return obj;
    }
  }
  return false;
}

There are some sample scripts that spelunk the scene graph, I'd suggest looking at them.

Simple ASCII Export is a good place to start (in Finder use Command-Shift-G to got to ~/Library/Application Support/Cheetah3D/Scripts/Macro/)

Any yes, this is a lot more cumbersome than it needs to be. It would be great if something like obj['foo'] would return a child named 'foo' or null/false if none existed, but there are bigger fish to fry.
 
Summary (from the scripting): 30+ year veteran programmer, proficient in large number of languages - Javascript just isn't one of them.

Getting the object is trivial (my function actually recurses through the scene graph.

If I have the following:

Code:
  var objectToDelete = objectWithName(doc, "head-tongue");

What is the next line of code that actually DELETES the object from the scene graph?
 
Ah, my apologies. I assumed from the ways you were trying to delete the object that you were under the impression that the scene graph is a native JavaScript object, whereas it's a foreign object exposing accessor methods (and hence -- for example -- childCount is a function; if it were a native object you'd use the length property).

So the problem isn't with your knowledge of JavaScript, which is fine, so much as your assumptions about the scripting environment.

As far as I can tell there's no method exposed for removing/deleting objects from the scene graph (there is clearly a method for creating new objects). It doesn't look like you can even set an object's parent (e.g. if such a method existed you could create a folder called "trash" and move stuff into it). So I guess you if what you want to do can't be achieved by -- say -- turning an object invisible the put it on the wish list (along with being able to assign objects to new parents would be even more useful).
 
Ah, okay, this answers a lot of questions. I had assumed that the scene graph was a foreign object and that Javascript was there merely to implement scripting. But I didn't know how "deep" the scripting went.

That also would explain why some things seem to be proper properties (in the Javascript sense) and others require a setter/getter.

My current "hack" has been to move objects I want to delete into a "delete" folder - this allows me to delete the objects all in one step.

The script I'm working on is to take a MakeHuman .OBJ file and generate a full rig (face included).

The only tricky part is the fact that you can't easily copy, import children, or delete (although you can delete polygons and vertices - weird).

One of the aspects of my code is to fix the mouth - MakeHuman gloms everything together - the roof of the mouth with the upper and lower gums. The net result is a nightmare. Part of the script is an attempt to fix this.

BTW, if anyone wants this code, just ask. It's not terribly complex at the moment (less than 800 lines). But it builds a rig from the foot to all the fingers that should (unless I'm mistaken) be compatible with Mixamo.
 
I'm curious about what you've done with this, especially how you're dealing with the import children and delete problems.
Would love to have a look.

-cg

BTW, if anyone wants this code, just ask. It's not terribly complex at the moment (less than 800 lines). But it builds a rig from the foot to all the fingers that should (unless I'm mistaken) be compatible with Mixamo.
 
I'm curious about what you've done with this, especially how you're dealing with the import children and delete problems.
Would love to have a look.

-cg

I've run into several roadblocks two of which you mentioned:

a) import children: not all of functions that you can "point and click" on work using Javascript per the developer. This means that there are points where you have to "do things by hand". One of which is import children.

b) deleting C3D objects is non-existent under Javascript (again per the developer). So, once again, we have to resort to "doing things by hand".

Now, about my code, I have created two libraries (boneLibrary.js and standardLibrary.js) that must exist in ~/Application Support/Cheetah3D/Scripts/Library - a folder you will have to create BTW.

The other is MakeHumanHumanizer.js and it exists ~/Application Support/Cheetah3D/Scripts/MakeHuman/ folder (again one you will have to create).

One nice thing about this script is that it creates a skeleton for any size character (a plus). The down side is that Make Human "glues" the inner mouth as a blob. I'm trying to write code to break it apart but I don't have a lot of confidence in it. The mouth part is PURELY low res since I am working on SPECIFIC points (boo make human).

Feel free to make changes and if you come up with something interesting, let me know!

What is missing

1. Button to move the jaw to the jaw bone. We need to keep this independent of the mesh so that things don't get all creepy looking.
2. Moving all pertinent objects under a single object prior to "import children" - right now I'm doing it by hand because I've not been able to play with this lately.
3. I've never had the eyelashes or eyebrows work right. I suspect it has to do with the alpha but again, one more thing to mess with.
4. I would like to manipulate the face using bones rather than messing directly with the mesh. However, again, I'm not sure if this is a reasonable or just plain stupid way of doing things. :) I've seen some awesome examples where people manipulate the mesh, but the thought of doing this with 10 different characters makes me cry.

Good Luck!
 

Attachments

  • MakeHumanHumanizer.js.zip
    10.1 KB · Views: 236
  • Library.zip
    4.4 KB · Views: 267
Well, they reworked how MakeHuman exports and it is all a single mesh. Basically means I have to start from scratch.

I'm happier the characters look better, but unhappier about all the work.
 
Back
Top