Skip to content

Commit 715f22d

Browse files
committed
v0.3. It support BEngine for Unity V0.6.
1 parent edf3099 commit 715f22d

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

BEngine-Py/BEVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = 0.2
1+
VERSION = 0.3

BEngine-Py/Utils/BEUtils.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from math import degrees
1212
from mathutils import Color, Vector, Euler
1313

14+
import bmesh
15+
import mathutils
16+
17+
1418
UV_NAMES = {"uv_map", "uv_map2", "uv_map3", "uv_map4", "uv_map5",
1519
"uv_map6", "uv_map7", "uv_map8", "uv_map9", "uv_map10"}
1620

@@ -482,10 +486,7 @@ def ParseObjectFromJSON(context, js_obj_val, engine_type: str, isCollection: boo
482486
for i, js_obj in enumerate(js_obj_val):
483487
be_mesh_obj = None
484488
be_curves_obj = None
485-
486-
# # pass 0 index if it's Collection
487-
# if isCollection and i == 0:
488-
# continue
489+
be_terr_obj = None
489490

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

502503
be_objs.append(be_curves_obj)
503504

504-
if be_mesh_obj is None and be_curves_obj is None:
505+
# Import Terrain
506+
if "Terrain" in js_obj:
507+
be_terr_obj = ImportTerrainFromJSON(context, js_obj, engine_type)
508+
be_objs.append(be_terr_obj)
509+
510+
if be_mesh_obj is None and be_curves_obj is None and be_terr_obj is None:
505511
if isCollection:
506512
# Add Empty
507513
empty_obj = bpy.data.objects.new(js_obj["Name"], None )
@@ -662,6 +668,37 @@ def ImportCurvesFromJSON(context, js_obj, engine_type: str, import_as_curve: boo
662668
return be_curve_obj
663669

664670

671+
def ImportTerrainFromJSON(context, js_obj, engine_type: str):
672+
js_terr = js_obj["Terrain"]
673+
674+
if "Verts" in js_terr and js_terr["Verts"]:
675+
verts_len = len(js_terr["Verts"])
676+
677+
bm = bmesh.new()
678+
bmesh.ops.create_grid(bm, x_segments=js_terr["NumberSegmentsX"], y_segments=js_terr["NumberSegmentsY"], calc_uvs=False)
679+
680+
verts_len = len(js_terr["Verts"])
681+
682+
np_verts = np.asarray(js_terr["Verts"], dtype=np.float32)
683+
np_verts.shape = len(np_verts) * 3
684+
685+
# bm.verts.foreach_set('co', np_verts)
686+
687+
new_mesh = bpy.data.meshes.new("BESubMesh")
688+
bm.to_mesh(new_mesh)
689+
bm.free()
690+
691+
print(verts_len, len(np_verts), len(new_mesh.vertices))
692+
693+
new_mesh.vertices.foreach_set('co', np_verts)
694+
695+
new_mesh.update()
696+
697+
be_mesh_obj = bpy.data.objects.new(js_obj["Name"], new_mesh)
698+
699+
return be_mesh_obj
700+
701+
665702
# Create Mesh
666703
def CreateMesh(verts_len, polys_len, np_verts, np_poly_indices, np_normals):
667704
mesh = bpy.data.meshes.new('BESubMesh')

0 commit comments

Comments
 (0)