How can i change the surface material manually on Ray Tracing Model?

12 次查看(过去 30 天)
Hi, I'm Yoojung.
I want to know how to i change manually surface materials in my design on matlab code.
i'm doing simulation using Ray Tracing model and 3D design file(.gltf).
I can get each objects surface material, but i can't change it manually.
And I want t change the value on matlab code.
But I surfaced "Can't Change value because the "Materials" of site viewer is read only." when i try to change the surface material value.
How can i solve this problem?
Thank you for your attention.
Have a good day :)

回答(1 个)

Umar
Umar 2024-10-11

Hi @ Yoojung Moon,

Please click the link below. Hope this helps resolve your problem.

https://www.mathworks.com/matlabcentral/answers/2055439-raytracing-gltf-custom-surface-material

  2 个评论
Yoojung Moon
Yoojung Moon 2024-10-11
Thank you for your answer.
But even though I already viewed that page, I still couldn't solve the problem.
How to change each Material value of My material list is what i want to know.
Can i get some solution about my question?
Umar
Umar 2024-10-11

Hi @Yoojung Moon ,

After reviewing the documentation provided at the link below

https://www.mathworks.com/help/antenna/ref/siteviewer.html#mw_ee7e2fef-52ae-4619-83b6-37f2861545be

The materials assigned to your 3D model are read-only when imported via Site Viewer, meaning you cannot change them directly through the “Materials” property. Instead, the viewer matches the materials from your glTF file to a set of supported materials in MATLAB, and this mapping is fixed once the scene is created. Based on the documentation guidelines, here are steps to change materials in your model:

Modify Materials in the Source GLTF File: One effective way to change surface materials is to modify the glTF file itself before importing it into MATLAB. You can use tools like Blender or an online glTF editor to change material properties (like color, texture, etc.) and then re-import the modified glTF file.

Using Geospatial Tables for Custom Materials: If you want to customize how materials are represented after importing, consider reading your glTF file into a geospatial table format. You can then manipulate this table before visualization.

   Here’s a simplified example of how to do that:
   % Load your GLTF file
   filename = fullfile(dataDir, "IntersectionAndBuildings.glb");
   viewer = siteviewer(SceneModel=filename);
   % Read materials into a geospatial table
   buildings = readgeotable("your_buildings_file.osm"); % Replace 
   with your OSM or other geospatial data
   % Change materials in this table as needed
   buildings.Material(buildings.Material == "glass") = "metal"; % 
   Example 
   change

Use of Material Dictionary: You can create a dictionary that maps existing material names to new ones and apply this mapping as you visualize your scene.

   % Create a dictionary for material changes
   materialDict = containers.Map({'glass', 'concrete'}, {'metal', 
   'wood'});
   % Apply changes during visualization
   for n = 1:height(buildings)
       if isKey(materialDict, buildings.Material(n))
           buildings.Material(n) = 
           materialDict(buildings.Material(n));
       end
   end
   viewer = siteviewer(Buildings=buildings);

Custom Ray Tracing Settings: If you’re performing ray tracing analysis, ensure that any custom materials you define are supported by MATLAB’s ray tracing functions. You may need to map unsupported materials to default ones.

Here are additional considerations listed below that can help out as well.

Documentation Review: Always refer back to MATLAB's official documentation for siteviewer and raytrace functions for any updates or additional capabilities introduced in newer versions.

Backup Files: Before making modifications, always keep backup copies of your original glTF files.

Hope this helps.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Material Sciences 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by