X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=blender_export.py;h=c069d7f925fa5412562eadee4e9bc5e27dd1e38e;hb=bceb3a28f8127fa27a17f480bd21fa20a340e848;hp=acd28ec3bcfcadbd96bc17cc539bd1508a78f86d;hpb=4a883ac1b2506032f9dddab342712de46f2ca734;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/blender_export.py b/blender_export.py index acd28ec..c069d7f 100644 --- a/blender_export.py +++ b/blender_export.py @@ -1,3 +1,7 @@ +# +# Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved +# + import bpy, math, gpu import cProfile from ctypes import * @@ -132,8 +136,7 @@ class classtype_route_node(Structure): class classtype_route(Structure): _pack_ = 1 - _fields_ = [("pstr_name",c_uint32), - ("id_start",c_uint32), + _fields_ = [("id_start",c_uint32), ("colour",c_float*3)] class classtype_skin(Structure): @@ -158,6 +161,17 @@ class classtype_bone(Structure): ("angle_limits",(c_float*3)*2), ("hitbox",(c_float*3)*2)] +class classtype_achievement_box(Structure): + _pack_ = 1 + _fields_ = [("pstr_name",c_uint32), + ("trigger",c_uint32)] + +class classtype_audio(Structure): + _pack_ = 1 + _fields_ = [("pstr_file",c_uint32), + ("flags",c_uint32), + ("volume",c_float)] + # Exporter # ============================================================================== @@ -318,7 +332,11 @@ def write_model(collection_name): _extendb( tree, b, d+1 ) for obj1 in n.children: - _extend( tree, obj1, d+1 ) + nonlocal collection + for c1 in obj1.users_collection: + if c1 == collection: + _extend( tree, obj1, d+1 ) + break p["children"] += [tree] graph_lookup[n] = tree @@ -805,6 +823,30 @@ def write_model(collection_name): block.bbx[1][2] = -source.v0[1] entdata_buffer += [block] + elif classtype == 'k_classtype_achievement_box': + node.classtype = 13 + + entdata_length += sizeof( classtype_achievement_box ) + ach = classtype_achievement_box() + ach.pstr_name = emplace_string( obj.cv_data.strp ) + ach.trigger = 0 + + if obj.cv_data.target != None: + ach.trigger = obj.cv_data.target.cv_data.uid + + entdata_buffer += [ach] + + elif classtype == 'k_classtype_audio': + node.classtype = 14 + + entdata_length += sizeof( classtype_audio ) + aud = classtype_audio() + aud.pstr_file = emplace_string( obj.cv_data.strp ) + aud.flags = obj.cv_data.intp + aud.volume = obj.cv_data.fltp + + entdata_buffer += [aud] + elif classtype == 'k_classtype_spawn': node.classtype = 3 @@ -855,7 +897,6 @@ def write_model(collection_name): node.classtype = 9 entdata_length += sizeof( classtype_route ) r = classtype_route() - r.pstr_name = emplace_string("not-implemented") r.colour[0] = obj.cv_data.colour[0] r.colour[1] = obj.cv_data.colour[1] r.colour[2] = obj.cv_data.colour[2] @@ -1149,6 +1190,42 @@ def cv_draw(): obj.matrix_world.to_quaternion() @ Vector((0,0,-6+1.5)) drawbline( obj.location, p1, sw,sw2 ) + elif obj.cv_data.classtype == 'k_classtype_achievement_box': + a = Vector((-1,-1,-1)) + b = Vector((1,1,1)) + + vs = [None]*8 + vs[0] = obj.matrix_world @ Vector((a[0], a[1], a[2])) + vs[1] = obj.matrix_world @ Vector((a[0], b[1], a[2])) + vs[2] = obj.matrix_world @ Vector((b[0], b[1], a[2])) + vs[3] = obj.matrix_world @ Vector((b[0], a[1], a[2])) + vs[4] = obj.matrix_world @ Vector((a[0], a[1], b[2])) + vs[5] = obj.matrix_world @ Vector((a[0], b[1], b[2])) + vs[6] = obj.matrix_world @ Vector((b[0], b[1], b[2])) + vs[7] = obj.matrix_world @ Vector((b[0], a[1], b[2])) + + indices = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\ + (0,4),(1,5),(2,6),(3,7)] + + for l in indices: + v0 = vs[l[0]] + v1 = vs[l[1]] + verts += [(v0[0],v0[1],v0[2])] + verts += [(v1[0],v1[1],v1[2])] + colours += [(0,1,0,1),(0,1,0,1)] + + if obj.cv_data.target != None: + vs = [None]*2 + vs[0] = obj.location + vs[1] = obj.cv_data.target.location + indices = [(0,1)] + for l in indices: + v0 = vs[l[0]] + v1 = vs[l[1]] + verts += [(v0[0],v0[1],v0[2])] + verts += [(v1[0],v1[1],v1[2])] + colours += [(0,1,1,1),(0,1,1,1)] + elif obj.cv_data.classtype == 'k_classtype_block': a = obj.data.cv_data.v0 @@ -1327,6 +1404,10 @@ class CV_MESH_SETTINGS(bpy.types.PropertyGroup): class CV_OBJ_SETTINGS(bpy.types.PropertyGroup): uid: bpy.props.IntProperty( name="" ) + strp: bpy.props.StringProperty( name="strp" ) + intp: bpy.props.IntProperty( name="intp" ) + fltp: bpy.props.FloatProperty( name="fltp" ) + target: bpy.props.PointerProperty( type=bpy.types.Object, name="target", \ poll=cv_poll_target ) target1: bpy.props.PointerProperty( type=bpy.types.Object, name="target1", \ @@ -1350,7 +1431,9 @@ class CV_OBJ_SETTINGS(bpy.types.PropertyGroup): ('k_classtype_route', "k_classtype_route", "", 9 ), ('k_classtype_bone',"k_classtype_bone","",10), ('k_classtype_SKELETON', "","", 11 ), - ('k_classtype_SKIN',"","",12) + ('k_classtype_SKIN',"","",12), + ('k_classtype_achievement_box',"k_classtype_achievement_box","",13), + ('k_classtype_audio',"k_classtype_audio","",14), ]) class CV_BONE_SETTINGS(bpy.types.PropertyGroup): @@ -1428,6 +1511,13 @@ class CV_OBJ_PANEL(bpy.types.Panel): mesh = active_object.data _.layout.label( text=F"(i) Data is stored in {mesh.name}" ) _.layout.prop( mesh.cv_data, "v0" ) + elif active_object.cv_data.classtype == 'k_classtype_achievement_box': + _.layout.prop( active_object.cv_data, "strp" ) + _.layout.prop( active_object.cv_data, "target" ) + elif active_object.cv_data.classtype == 'k_classtype_audio': + _.layout.prop( active_object.cv_data, "strp" ) + _.layout.prop( active_object.cv_data, "intp" ) + _.layout.prop( active_object.cv_data, "fltp" ) class CV_INTERFACE(bpy.types.Panel): bl_idname = "VIEW3D_PT_carve"