Skip to content

Commit

Permalink
v0.3. It support BEngine for Unity V0.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
mifth committed Jan 4, 2023
1 parent edf3099 commit 715f22d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion BEngine-Py/BEVersion.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = 0.2
VERSION = 0.3
47 changes: 42 additions & 5 deletions BEngine-Py/Utils/BEUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from math import degrees
from mathutils import Color, Vector, Euler

import bmesh
import mathutils


UV_NAMES = {"uv_map", "uv_map2", "uv_map3", "uv_map4", "uv_map5",
"uv_map6", "uv_map7", "uv_map8", "uv_map9", "uv_map10"}

Expand Down Expand Up @@ -482,10 +486,7 @@ def ParseObjectFromJSON(context, js_obj_val, engine_type: str, isCollection: boo
for i, js_obj in enumerate(js_obj_val):
be_mesh_obj = None
be_curves_obj = None

# # pass 0 index if it's Collection
# if isCollection and i == 0:
# continue
be_terr_obj = None

# Import Mesh
if "Mesh" in js_obj:
Expand All @@ -501,7 +502,12 @@ def ParseObjectFromJSON(context, js_obj_val, engine_type: str, isCollection: boo

be_objs.append(be_curves_obj)

if be_mesh_obj is None and be_curves_obj is None:
# Import Terrain
if "Terrain" in js_obj:
be_terr_obj = ImportTerrainFromJSON(context, js_obj, engine_type)
be_objs.append(be_terr_obj)

if be_mesh_obj is None and be_curves_obj is None and be_terr_obj is None:
if isCollection:
# Add Empty
empty_obj = bpy.data.objects.new(js_obj["Name"], None )
Expand Down Expand Up @@ -662,6 +668,37 @@ def ImportCurvesFromJSON(context, js_obj, engine_type: str, import_as_curve: boo
return be_curve_obj


def ImportTerrainFromJSON(context, js_obj, engine_type: str):
js_terr = js_obj["Terrain"]

if "Verts" in js_terr and js_terr["Verts"]:
verts_len = len(js_terr["Verts"])

bm = bmesh.new()
bmesh.ops.create_grid(bm, x_segments=js_terr["NumberSegmentsX"], y_segments=js_terr["NumberSegmentsY"], calc_uvs=False)

verts_len = len(js_terr["Verts"])

np_verts = np.asarray(js_terr["Verts"], dtype=np.float32)
np_verts.shape = len(np_verts) * 3

# bm.verts.foreach_set('co', np_verts)

new_mesh = bpy.data.meshes.new("BESubMesh")
bm.to_mesh(new_mesh)
bm.free()

print(verts_len, len(np_verts), len(new_mesh.vertices))

new_mesh.vertices.foreach_set('co', np_verts)

new_mesh.update()

be_mesh_obj = bpy.data.objects.new(js_obj["Name"], new_mesh)

return be_mesh_obj


# Create Mesh
def CreateMesh(verts_len, polys_len, np_verts, np_poly_indices, np_normals):
mesh = bpy.data.meshes.new('BESubMesh')
Expand Down

0 comments on commit 715f22d

Please sign in to comment.