assigning materials to faces from their index #1190
Replies: 2 comments 12 replies
-
I'm confused by what "centers" are you talking about? Also, wouldn't it be easier to just extract four partial meshes with your algorithm? You know the face indices, it should be fairly straightforward to create meshes that are the subset of triangle faces - you can most likely even just export them as disjoint triangles. At that point, you would no longer care about how the indices map from Blender/your algorithm to Mitsuba. |
Beta Was this translation helpful? Give feedback.
-
I'm sorry for all the comments and questions, but I am having another issue. I am trying to save the centers of the faces to a JSON file, starting from the index of a face. This is what I do: import mitsuba as mi
import numpy as np
import json
mi.set_variant("llvm_ad_rgb")
mesh = mi.load_dict({
"type": "ply",
"filename": "../scenes/new_dji/meshes/mesh.ply",
})
# Read JSON file
with open("/home/ubuntu/geoloc-rf/2D_3D_mapping/mat_idx.json", 'r') as json_file:
data = json.load(json_file)
breakpoint()
dic = {}
for material, set_of_indexes in data.items():
if material == "car":
centers = np.zeros(shape=(len(set_of_indexes), 3))
vertices = mesh.face_indices(list(set_of_indexes)).numpy()
for i, vert in enumerate(vertices):
centers[i] = np.mean(mesh.vertex_position(vert).numpy(), axis=0)
dic[material] = centers
# Convert NumPy arrays to lists
dic_converted = {material: centers.tolist() for material, centers in dic.items()}
# Save the converted dictionary to a JSON file
with open('car.json', 'w') as json_file:
json.dump(dic_converted, json_file, indent=4)
print("Data saved to material_centers.json") But I get the error: Is this the correct way of doing this operation? |
Beta Was this translation helpful? Give feedback.
-
Summary
I am trying to assign materials to the faces of my mesh, after exporting from Blender.
I can't find a way of assigning the materials directly in Mitsuba, or alternatively without having to find all the centers and then find the corresponding face in Blender again.
Description
As mentioned, from an algorithm that I created, I have a list of indexes of the faces and the corresponding materials:
Now what I would like to do here, is to assign all the materials to the faces. The materials are already present, as I created them in blender and exported them. The resulting files are 4 meshes (because I have 4 materials), and all of them consists of all the faces.
The problem that I am facing is that I couldn't find a way to assign materials directly in Mitsuba, or alternatively to find a map between the indexes of the faces in Mitsuba and in Blender. Therefore the only thing that I had in mind to do was to find in with Mitsuba all the centers, and then iterate over all the faces in blender and find the center that is closest to the value that mitsuba gives me.
This however gives me a big problem. If I have N faces, I would have to do$O(N^2)$ operations, which I would like to avoid since my mesh can be very big.
Do you have any clue on how I could approach this problem in Mitsuba directly?
Beta Was this translation helpful? Give feedback.
All reactions