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

Color Control on 3D object

whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66

Hello,

My french entreprise use Solidworks to create Agricole machine.
Solidworks export a 3D image (extension .pdf)

I want to know, if its possible, in acrobat extended pro) to change color of a part with a script?

Thanks for answers

UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
Yes it is - you can change both colors and textures on any "node" within the scene using JavaScript.

See my Tech Talk for a detailed introduction:

http://adobechats.adobe.acrobat.com/p32622737/
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
Hi UVSAR and thanks,

I watch your Tech Talk and i see you change render mode. but i don't see anything about change color....

Can you help me please!!

Regards
UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
The principles are the same for any materials in a scene - you can collect the material from a node using

var mtl = scene.meshes.getByName( "name_of_part" ).material;

or

mtl = scene.materials.getByName( "name_of_material" );

then use any of the properties defined in the SDK. For example to change the diffuse color to blue, you would call

mtl.diffuseColor.set( 0, 0, 1 );

Node colors are set using R, G and B values from 0 to 1.


or to import a bitmap from the resource array into the diffuse slot, you'd use

mtl.diffuseTexture.image = new Image( new Resource( "pdf://bitmap_file_name.jpg" ) );
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
Thanks,

i show that tomorrow
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
I don't know why but my code don't run.

There are need a context?
Or ohter things?


i test your code but it doesn't work....
UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
The code must be run inside the 3D annotation (by embedding it via the 3D annotation's properties panel).

If you want to run it directly in the console or from a button.script in the document, you need to first connect to the 3D engine by running

var c3d = this.getAnnots3D(this.pageNum)[0].context3D;

or

var c3d = this.getAnnotsRichMedia(this.pageNum)[0].context3D;

(use the second one if you have any Flash content attached to the 3D model)



then use "c3d.scene" instead of "scene" in the example I posted above.
whirpett
whirpett's picture
Registered: May 20 2010
Posts: 66
Very thanks to help me , UVSAR.... Its work.
itsraghuin
itsraghuin's picture
Registered: Sep 8 2009
Posts: 18
Hi,
I know that we can change the part color using the approach you suggested. But I would like to know how do we reset it back to its original color.

-Nilesh
UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
There is no built-in memory, so you must store the color in a variable before changing it, then use that variable to re-apply the previous value again.
Shlomo Perets
Shlomo Perets's picture
Expert
Registered: Feb 8 2007
Posts: 18
Sample PDFs desmonstrating this functionality are available at:
http://microtype.com/showcase/3DAsst/PartColor.pdf
http://microtype.com/showcase/3DAsst/Hinge.pdf

Shlomo Perets, http://www.microtype.com

Shlomo Perets, http://www.microtype.com
Acrobat training & consulting

itsraghuin
itsraghuin's picture
Registered: Sep 8 2009
Posts: 18
Thanks UVSAR & Shlomo for your help!-Nilesh
Forrest Gimp
Forrest Gimp's picture
Registered: Mar 4 2010
Posts: 7
Is there a way to access the "resource array" of an annotation? I'm specifically looking for a way to add an image-file during runtime. In the document-script I used importDataObject to load the file (user has to pick the path to the image) which seems to work. I have also managed to load an image which already is a resource as diffuse texture. Now I want to combine both, hence

- letting the user load an image from local disk
- adding this image to the resources of a 3D-Annotation
- using the image as diffuse-texture
.

As mentioned, steps 1 and 3 seem to work. But how about step 2?
sanjigento
sanjigento's picture
Registered: Mar 22 2011
Posts: 7
Hello,

Your Tech Talk and sample files were very helpful. Thank you.

I have successfully created a button to change the color of a mesh using the sample models you provided. But when I try to apply it to an imported Catia v5 model, this script does not work for me. The model does have color information on it. Please give me some advise on what I may be missing?

Applied to a button:

c3d = this.getAnnots3D(this.pageNum)[0].context3D;
matl = c3d.scene.meshes.getByName( "HULL-ABOVE" ).material;

matl.diffuseColor.set( 0, 0, 1 );

[object global]
ReferenceError: matl is not defined
1:Console:Exec
undefined
UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
If you can't get the name shown in the model tree to return a mesh node using getByName, it means the model was imported using extended naming (something the API doesn't talk about but it happens with PRC models). The true name will be what's shown in the model tree, plus a huge random hex number. In those cases it's better to use getByIndex to identify each node.

You can check for extended naming by running a scan of your SceneObjectList :


c3d = this.getAnnots3D(this.pageNum)[0].context3D;
msh = c3d.scene.meshes;
for (var i = 0; i < msh.count; i++) {
console.println("Mesh at index " + i + " name = " + msh.getByIndex(i).name);
}


If you get things like

Mesh at index 0 name = RobotBase.ded5e77dd566fba7fe202cc59e4b467a1020ded5e77dd566fba7fe202cc59e4b464da02c30

that's the name the API is expecting you to use for getByName() even if the model tree says "RobotBase". No, you can't stop it happening, it's one of those quirks that make the 3D API so fun to use.
sanjigento
sanjigento's picture
Registered: Mar 22 2011
Posts: 7
Thank you for your quick support.

I get a syntax error when I run:

c3d = this.getAnnots3D(this.pageNum)[0].context3D;
msh = c3d.scene.meshes;
for (var i = 0; i < msh.count; i++) {
console.println("Mesh at index " + i + " name = " + msh.getByIndex(i).name);
}
[object global]
SyntaxError: syntax error
1:Console:Exec
undefined

Im a novice with Java scripting, sorry for the trouble.
sanjigento
sanjigento's picture
Registered: Mar 22 2011
Posts: 7
Hi again,

I re-imported the model with .u3d settings and now it WORKS!
Thank you so much!
chenet0005
chenet0005's picture
Registered: Aug 11 2011
Posts: 4
hi,

I applied the color for particular item, but all objects color were changed. how to assign the material for particular item

CHENTHIL KUMAR
ADOBE CERTIFIED EXPERT in Indesign CS2, Illustrator CS3, Photoshop CS4, Photoshop CS5

UVSAR
UVSAR's picture
Expert
Registered: Oct 29 2008
Posts: 1357
You can't - material assignments within a 3D scene are not editable in Acrobat. You must recreate the 3D model with different materials on each item, so you can target them individually with your scripts.

chenet0005 wrote:
hi,I applied the color for particular item, but all objects color were changed. how to assign the material for particular item
chenet0005
chenet0005's picture
Registered: Aug 11 2011
Posts: 4
hi uvsar,

how to create playrange in prc type animation in acrobat. a little more help is very useful to me

CHENTHIL KUMAR
ADOBE CERTIFIED EXPERT in Indesign CS2, Illustrator CS3, Photoshop CS4, Photoshop CS5