Jump to content

Real-Time Material/Mesh Swap


photo

Recommended Posts

Hi there,

 

I'm wondering if there are any internal Unigine projects, or a scripting example that shows how you can enable real-time material or mesh swapping for an ArchViz scene, allowing users to change fabrics or pieces of furniture at runtime?

 

Thanks!

Link to comment

Hi, Andre!

I have written a small C++ sample for you, which shows how to "switch" one node to another node.

 

You can find in the attachment 3 files: 

  • AppWorldLogic.h
  • AppWorldLogic.cpp
  • unigine.cpp

When you create new C++ project (like in this tutorial), you have these files in your project folder:

  • AppWorldLogic.h and AppWorldLogic.cpp are in the into the your_project_folder/source folder
  • unigine.cpp is in the your_project_folder/data/project_name/ folder

You can simply replace these files (or write the same instructions from scratch). After building the application, you can launch it and click on the material_ball node and it will be switched to a box primitive.

The essential thing of the project is located into update() method where we check the mouse button click and perform a raycasting to find intersected objects.

 

Don't hesitate to ask any questions!

 

Regards

 

 

unigine.cpp

AppWorldLogic.cpp

AppWorldLogic.h

Link to comment

Hi, Andre!

 

How the things are going? Any updates?

I've slightly improved the sample above: from now on LMB click changes material on the left box, albedo_color parameter on the right box.

 

Here are two files in the attachment, 

  • AppWorldLogic.h
  • AppWorldLogic.cpp

unigine.cpp can be used from the previous answer.

 

Pay attention to the update() method, where the logic is implemented.

 

 

Regards,
Andrey
 

AppWorldLogic.cpp

AppWorldLogic.h

Link to comment

Thanks Andrey, I was actually delayed solving some other issues I've been having. I will test this implementation tomorrow and let you the moment I'm done. Thanks again!

Link to comment
×
×
  • Create New...