Created
August 1, 2024 18:00
-
-
Save hernandohhoyos/c363155aaad6939aa03588359e723b82 to your computer and use it in GitHub Desktop.
Crear una malla en Blender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import bmesh | |
import numpy as np | |
def create_mesh(): | |
# Elimina todos los objetos en la escena | |
bpy.ops.object.select_all(action='DESELECT') | |
bpy.ops.object.select_by_type(type='MESH') | |
bpy.ops.object.delete() | |
# Crear una nueva malla y objeto | |
mesh = bpy.data.meshes.new(name="CustomMesh") | |
obj = bpy.data.objects.new(name="CustomMeshObject", object_data=mesh) | |
bpy.context.collection.objects.link(obj) | |
bpy.context.view_layer.objects.active = obj | |
# Definir los contenedores | |
bm = bmesh.new() | |
verts = [] # para almacenar las instancias de BMVert | |
coords = [] #para almacenar las coordenadas de los BMVert | |
# Para el ejemplo se crea un triángulo rectángulo | |
v1 = np.array((0, 0, 0)) | |
v2 = np.array((1, 0, 0)) | |
v3 = np.array((0, 1, 0)) | |
verts.append(bm.verts.new(v1)) | |
coords.append(v1) | |
verts.append(bm.verts.new(v2)) | |
coords.append(v2) | |
verts.append(bm.verts.new(v3)) | |
coords.append(v3) | |
# Crear una cara a partir de 3 BMVert | |
bm.faces.new((verts[0], verts[1], verts[2])) | |
# Actualizar la malla | |
bm.to_mesh(mesh) | |
bm.normal_update() | |
bm.free() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment