-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into #392-keep-original-name-for-conver-to
- Loading branch information
Showing
20 changed files
with
666 additions
and
175 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import bmesh | ||
import bpy | ||
|
||
from bpy_extras.object_utils import object_data_add | ||
|
||
|
||
tmp_name = 'box_collider' | ||
|
||
# vertex indizes defining the faces of the cube | ||
face_order = [ | ||
(0, 1, 2, 3), | ||
(4, 7, 6, 5), | ||
(0, 4, 5, 1), | ||
(1, 5, 6, 2), | ||
(2, 6, 7, 3), | ||
(4, 0, 3, 7), | ||
] | ||
|
||
|
||
def add_box_object(context, vertices): | ||
"""Generate a new object from the given vertices""" | ||
|
||
global tmp_name | ||
|
||
verts = vertices | ||
edges = [] | ||
faces = [[0, 1, 2, 3], [7, 6, 5, 4], [5, 6, 2, 1], [0, 3, 7, 4], [3, 2, 6, 7], [4, 5, 1, 0]] | ||
|
||
mesh = bpy.data.meshes.new(name=tmp_name) | ||
mesh.from_pydata(verts, edges, faces) | ||
|
||
return object_data_add(context, mesh, operator=None, name=None) | ||
|
||
|
||
def verts_faces_to_bbox_collider(self, context, verts_loc): | ||
"""Create box collider for selected mesh area in edit mode""" | ||
|
||
global tmp_name | ||
|
||
# add new mesh | ||
mesh = bpy.data.meshes.new(tmp_name) | ||
bm = bmesh.new() | ||
|
||
# create mesh vertices | ||
for v_co in verts_loc: | ||
bm.verts.new(v_co) | ||
|
||
# connect vertices to faces | ||
bm.verts.ensure_lookup_table() | ||
for f_idx in face_order: | ||
bm.faces.new([bm.verts[i] for i in f_idx]) | ||
|
||
# update bmesh to draw properly in viewport | ||
bm.to_mesh(mesh) | ||
mesh.update() | ||
|
||
# create new object from mesh and link it to collection | ||
new_collider = bpy.data.objects.new(tmp_name, mesh) | ||
|
||
root_collection = context.scene.collection | ||
root_collection.objects.link(new_collider) | ||
|
||
return new_collider |
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import bpy, bmesh | ||
|
||
def bmesh_join(list_of_bmeshes, list_of_matrices, normal_update=False): | ||
# sourcery skip: use-contextlib-suppress | ||
""" takes as input a list of bm references and outputs a single merged bmesh | ||
allows an additional 'normal_update=True' to force _normal_ calculations. | ||
""" | ||
bm = bmesh.new() | ||
add_vert = bm.verts.new | ||
add_face = bm.faces.new | ||
add_edge = bm.edges.new | ||
|
||
for bm_to_add, matrix in zip(list_of_bmeshes, list_of_matrices): | ||
bm_to_add.transform(matrix) | ||
|
||
for bm_to_add in list_of_bmeshes: | ||
offset = len(bm.verts) | ||
|
||
for v in bm_to_add.verts: | ||
add_vert(v.co) | ||
|
||
bm.verts.index_update() | ||
bm.verts.ensure_lookup_table() | ||
|
||
if bm_to_add.faces: | ||
for face in bm_to_add.faces: | ||
add_face(tuple(bm.verts[i.index + offset] for i in face.verts)) | ||
bm.faces.index_update() | ||
|
||
if bm_to_add.edges: | ||
for edge in bm_to_add.edges: | ||
edge_seq = tuple(bm.verts[i.index + offset] | ||
for i in edge.verts) | ||
try: | ||
add_edge(edge_seq) | ||
except ValueError: | ||
# edge exists! | ||
pass | ||
bm.edges.index_update() | ||
|
||
if normal_update: | ||
bm.normal_update() | ||
|
||
me = bpy.data.meshes.new("joined_mesh") | ||
bm.to_mesh(me) | ||
|
||
return me |
This file contains 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
Oops, something went wrong.