How to customize the meshes in the selected 3D shape with FlexScript?

How to customize the meshes in the selected 3D shape with FlexScript?

jouky_d
Not applicable
189 Views
9 Replies
Message 1 of 10

How to customize the meshes in the selected 3D shape with FlexScript?

jouky_d
Not applicable

[ FlexSim 23.1.2 ]

Hello everyone,

I want to change by code the color of Mesh of a Shape. Normally I go to More Visuals (of the Object) and then I press the button of Customize the meshes in the selected 3D shape. After that I select a Mesh and I check Override to change the Diffuse Color. Is there a way to change the color of the mesh I want (from the object) in FlexScript?

1687855609002.png
Thank you!

Accepted solutions (1)
190 Views
9 Replies
Replies (9)
Message 2 of 10

moehlmann_fe
Enthusiast
Enthusiast
Accepted solution

Any information that is unique to an object should be located in its attribute tree. If you compare a default object to one that had these values changed, you will find that making changes in the menu from your screenshot adds the following node structure to the visuals attribute subnode.

1687864870019.png

If you copy these nodes to a different object, it will use the same settings (remember to adjust the value of the shapedata node to point to the correct subnode).

And with the knowledge of where the information is stored, you can change it in code.

// Change the diffuse color
setsdtvalue(Model.find("BasicFR1>visual/localshapedata/1/block"), "diffuseColor", [0.6, 0.2, 0.8, 1]);
0 Likes
Message 3 of 10

jouky_d
Not applicable

The localshapedata subnode only appears after I activate it manually the Customize Mesh. Is there a way to activate it with Flexscript and not using manual clicks?

And is there a way to mantain the same object color as the imported object? Why do we have to change the colors again?

0 Likes
Message 4 of 10

moehlmann_fe
Enthusiast
Enthusiast
I don't know if there is a way to generate the simple data type node with the necessary values in FlexScript. As a workaround you could just keep an object with these nodes in the model so you can copy them to other objects.

I don't understand you second question. Any imported 3d shape should have its default coloring unless you change it. (Wasn't this your original question?)

0 Likes
Message 5 of 10

jouky_d
Not applicable
Yes, but I don't know why I have to recolor it because the colors from the original object are not the same as the ones in FlexSim. FlexSim transforms the colors to more darkness colors, that's why I have to use the option I asked.
0 Likes
Message 6 of 10

moehlmann_fe
Enthusiast
Enthusiast
The way colors and textures of imported shapes work depends on the file type. I'm also not an expert on this topic. I believe the default diffuse color FlexSim uses is a light grey, which darkens any color of imported objects. Changing it to white should result in the original color.

The lighting in the model can also make a difference.

0 Likes
Message 7 of 10

jouky_d
Not applicable

Thank you Felix! Do you know how to change the default diffuse color FlexSim to white?

0 Likes
Message 8 of 10

Jeanette_Fullmer
Community Manager
Community Manager

Hello @Jouky D,

You could try a few things to change the lighting in FlexSim.

You can customize or turn off shadows in your global preferences.

Image.png

You can add model lighting

Image.png

You can edit the view's light sources (store them in the model Views section)

1688047145365.png


0 Likes
Message 9 of 10

jouky_d
Not applicable
Thank you @Jeanette F , but the first thing, only changes the shadows ON or OFF, it doesn't change type of light (green to White as @Felix Möhlmann said before.
0 Likes
Message 10 of 10

julie_weller
Not applicable
@Jouky D what about the other suggestions?
0 Likes