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
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
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.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!