Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get diffuseColor from every 3D objects

Explorer ,
Sep 19, 2017 Sep 19, 2017

Hi all,

I'm working on a dynamic 3D PDF for the company I'm working with.


This company needs to produce a PDF showing the 3D model and a list of all the materials contained in the model.

I need to:
- Extract the diffuseColor (I think is at Page 39 of the Acrobat 3D documentation) and use it as fillColor for or a text field

- Get the name of the mesh and print it in a Text Field

I'd set up a button with this code to extract the layers names and the materials settings:

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

function printObjectsNames() {

    for (var i=0; i < c3d.scene.meshes.count; i++) {

       

        var array = c3d.scene.meshes.getByIndex(i);

        console.println("Array: "+array);

        console.println("Object name: "+array.name);

        console.println("Ambient Color: "+array.ambientColor);

        console.println("Diffuse Color: "+array.diffuseColor);

        console.println("Emissive: "+array.emissiveColor);

        console.println("Opacity: "+array.opacity);

        console.println("Phong: "+array.phongExponent);

        console.println("Specular Color: "+array.specularColor);

     }   

}

printObjectsNames();

it prints this, why the texture maps are undefined? In the "Diffuse color" I expect a color value.

Array: [object Mesh]

Object name: ML1703

Ambient Color: undefined

Diffuse Color: undefined

Emissive: undefined

Opacity: 1

Phong: undefined

Specular Color: undefined

You can understand better by looking at this image

PDF3D.jpg

Thank you very much for the help!

Julio

TOPICS
Rich media and 3D
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Sep 20, 2017 Sep 20, 2017

The Material object doesn't have a name property. The following assumes you mean the mesh.

JavaScript isn't precious about types so rather than getting the field objects first you can use the fact that the field names are sequential to set their values by concatenating a string and your counter integer.

Inside your loop add...

this.getField("Mesh "+(i+1)).value = array.name;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2017 Sep 19, 2017

The "undefined" properties are properties of the material, not the mesh. See my example line below. You just need to get the material first, then the properties.

console.println("Ambient Color: "+array.material.ambientColor);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 20, 2017 Sep 20, 2017

Yes I fix that looking at the documentation but I didn't update the question sorry. Thanks for the help!

I have another problem that I can't figure out.

Now I have a 3 objects array and 3 text fields that I want to populate with the array.material.name property.

This is my code:

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

var MeshField1 = this.getField("Mesh 1");

var MeshField2 = this.getField("Mesh 2");

var MeshField3 = this.getField("Mesh 3");

function printObjectsNames()

    for (var i=0; i < c3d.scene.meshes.count; i++) {

       

        var array = c3d.scene.meshes.getByIndex(i);

           

        console.println("Array: "+array);

        console.println("Object name: "+array.name);

        console.println("Diffuse Color: "+array.material.diffuseColor);

     }

}

printObjectsNames();

The text field to populate are "Mesh 1", "Mesh 2" and "Mesh 3". How can I loop the process?

Thanks for the help!
- Julio

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2017 Sep 20, 2017

The Material object doesn't have a name property. The following assumes you mean the mesh.

JavaScript isn't precious about types so rather than getting the field objects first you can use the fact that the field names are sequential to set their values by concatenating a string and your counter integer.

Inside your loop add...

this.getField("Mesh "+(i+1)).value = array.name;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 21, 2017 Sep 21, 2017

Thank you very much! It works.

I have another problem,

I'm currently working on a script to extract the mesh material color and replace this value to the fillColor attribute of some buttons.

This is the script that runs when a button is pressed:

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

function printObjectsNames() {

    for (var i = 0; i < c3d.scene.meshes.count; i++) {

        /*Creates an array of the 3D meshes in the scene*/

        var array = c3d.scene.meshes.getByIndex(i);

       

        /*Extract the mesh name and populate some Text Fields*/

        this.getField("Mesh " + (i + 1)).value = array.name;

        /*Extract the mesh material color and replace some buttons background color*/

        ? ? ? ? ?

    

        /*Print some values in the console*/

        console.println("Object: " + array);

        console.println("Object name: " + array.name);

        console.println("Diffuse Color: " + array.material.diffuseColor);

    }

}

printObjectsNames();

As expected when I run the command the console shows this

Object: [object Mesh]

Object name: STK1000

Diffuse Color: Color: ( 0, 1, 1 )

Object: [object Mesh]

Object name: LUCIDO

Diffuse Color: Color: ( 1, 0, 1 )

Object: [object Mesh]

Object name: STRUTTURA

Diffuse Color: Color: ( 0.7451, 0.7451, 0.7451 )

The 3 meshes have different diffuseColor

The problem is that I can't put the value diffuseColor in the background color attribute because the array.material.diffuseColor extracts

Color: ( 0, 1, 1 ) and not only ( 0, 1, 1 )

How can I extract only the ( 0, 1, 1 ) value?

Thank you very much for the help,

Julio

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2017 Sep 21, 2017

You'd do something like...

var objColor = array.material.diffuseColor

var r = objColor.r

var g = objColor.g

var b = objColor.b

this.getField("foo").fillColor = [ "RGB", r, g, b ];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 21, 2017 Sep 21, 2017
LATEST

Thanks!! It works very well.
You're great!

- Julio

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines