These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adding texture from document level javascript

antros
antros's picture
Registered: Jul 22 2010
Posts: 6

Hello,

I've managed to add a texture to a model from 3D default script. Now I would like to do the same from the document level script when the pdf document is opened.

Here's the snippet I've tried:

var open;

function start()
{
if (open != "open")
{
c3d = this.getAnnots3D(0)[0].context3D;
var modelResource = new Resource( "pdf://sphere.u3d" );
var model = c3d.scene.addModel( modelResource );
model = c3d.scene.meshes.getByName("Sphere");
imageResource = new Resource( "pdf://grid.jpg" );
image = new Image( imageResource );
model.material.diffuseTexture.setImage( image );
bump = new Image( new Resource( "pdf://knurl.jpg" ) );
model.material.bumpTexture.setImage( bump );
open = "open";
}
}

However, all I receive are "Resource is not defined" error messages. All the files are defined in the resources of 3D box. What am I doing wrong? All the help is highly appreciated.

My Product Information:
Acrobat Pro 9.3.1, Windows
UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
Change it to c3d.Resource, c3D.Image, etc. - the objects only works in the context of the 3D scene, as that's where the textures are attached.
antros
antros's picture
Registered: Jul 22 2010
Posts: 6
UVSAR wrote:
Change it to c3d.Resource, c3D.Image, etc. - the objects only works in the context of the 3D scene, as that's where the textures are attached.
Thanks for the reply! I did what you suggested and got rid of "Resource is not define" problems. However, images seem to still cause troubles as int the debugger it says:

Line: 0: Code: 20(0x14): Bad argument list

GeneralError: Operation failed.
Root.(null):13:Document-Level:start
Constructor function needs to be called with new

If I remove c3d from the image definitions I receive "Image is not defined" messages. Here's the updated code:

function start()
{
if (open != "open")
{
console.println("Here");
var annot = this.getAnnots3D(0)[1];
annot.activated = true;
c3d = annot.context3D;
model = c3d.scene.meshes.getByName("Sphere");
imageResource = new c3d.Resource( "pdf://grid.jpg" );
image = new c3d.Image( imageResource );
model.material.diffuseTexture.setImage( image );
imageResource2 = new c3d.Resource( "pdf://knurl.jpg");
bump = new c3d.Image( imageResource2);
model.material.bumpTexture.setImage( bump );
open = "open";
}
}

Did I misunderstand something? Thanks for your support.