I am currently using Acrobat Pro Extended v9.3.1 on windows XP. I am trying to add a simple model of a 3D disk into an existing model using the 3D javascript API and then move the disk to wherever the user clicks the mouse. The existing model is embedded in a 3D PDF that was created from a VRML file and the model I am trying to add to it via javascript was created using Google SketchUp to export a Collada file that was then converted into a U3D file using Adobe 3D Reviewer. I know that in order to add a model to another model I must first attach it to the PDF as a resource which I have done by right clicking the existing model, selecting properties, and adding the U3D file using the controls on the resources tab. The relevant javascript I am using to add the model to the existing model is:
var modelResource = new Resource( "pdf://disk.u3d" );
var model = scene.addModel( modelResource );
This code does indeed add the disk model to my existing model, however while I would expect that the "model" variable would then contain a reference to the top level node of the disk model whose transform I could then translate to a mouse click location, it does not, "model" is actually null.
I am obviously getting the following error in the Javascript console window upon trying to use the resulting node:
Line: 24: Code: 21(0x15): null is not an object
I believe that I am either missing an initialization step or there is a problem with my process of creating my disk model u3d file using SketchUp and Reviewer.
I suppose my question is what might I be doing wrong and why am I getting Null when I believe that I should be getting a reference to the top level node of my added model?
I know that this can be done because I have seen several PDF's that do this successfully. Any help or suggestions are always appreciated. Thanks.
Remember though - if the loaded model has a root-level group then it's not a mesh (it's a Node3), so you can't use the getByName() method on it.
If you're loading a model and don't know the names inside it, remember that the new model is always added at the end of the sceneObjectList - so if you store scene.meshes.count in a variable X, load the model, and call scene.meshes.getByIndex(X), it will return the new node. If the model is grouped it'll return the first true mesh node within the new model.