_fields_ = [("co",c_float*3),
( "q",c_float*4),
( "s",c_float*3),
+ ("sub_uid",c_uint32), # dont use
("submesh_start",c_uint32),
("submesh_count",c_uint32),
("classtype",c_uint32),
_fields_ = [("identifier",c_uint32),
("version",c_uint32),
("file_length",c_uint32),
+ ("pad0",c_uint32),
+
("vertex_count",c_uint32),
("vertex_offset",c_uint32),
("anim_count",c_uint32),
("anim_offset",c_uint32),
-
+
+ ("strings_length",c_uint32),
("strings_offset",c_uint32),
+
+ ("entdata_length",c_uint32),
("entdata_offset",c_uint32),
- ("animdata_offset",c_uint32)
- ]
+
+ ("keyframe_count",c_uint32),
+ ("keyframe_offset",c_uint32)]
+
class mdl_animation(Structure):
_pack_ = 1
class classtype_achievement_box(Structure):
_pack_ = 1
- _fields_ = [("pstr_name",c_uint32)]
+ _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
# ==============================================================================
header.node_count = 0
header.material_count = 0
header.file_length = 0
+
+ header.strings_length = 0
+ header.entdata_length = 0
+ header.keyframe_count = 0
mesh_cache = {}
string_cache = {}
indice_buffer = []
node_buffer = []
entdata_buffer = []
- entdata_length = 0
anim_buffer = []
- animdata_length = 0
animdata_buffer = []
def emplace_string( s ):
# Process entity data
# ==================================================================
- node.offset = entdata_length
+ node.offset = header.entdata_length
if classtype != 'k_classtype_none':
disptype = classtype
node.classtype = 12
armature = armature_def['obj']
- entdata_length += sizeof( classtype_skin )
+ header.entdata_length += sizeof( classtype_skin )
skin = classtype_skin()
skin.skeleton = armature.cv_data.uid
elif classtype == 'k_classtype_skeleton':
node.classtype = 11
- entdata_length += sizeof( classtype_skeleton )
+ header.entdata_length += sizeof( classtype_skeleton )
skeleton = classtype_skeleton()
armature_def = graph_lookup[obj]
anim = mdl_animation()
anim.pstr_name = emplace_string( NLAStrip.action.name )
anim.rate = 30.0
- anim.offset = animdata_length
+ anim.offset = header.keyframe_count
anim.length = anim_end-anim_start
# Export the fucking keyframes
kf.s[2] = sca[1]
animdata_buffer += [kf]
- animdata_length += sizeof(mdl_keyframe)
+ header.keyframe_count += 1
break
anim_buffer += [anim]
elif classtype == 'k_classtype_bone':
node.classtype = 10
- entdata_length += sizeof( classtype_bone )
+ header.entdata_length += sizeof( classtype_bone )
bone = classtype_bone()
bone.deform = node_def['deform']
elif classtype == 'k_classtype_gate':
node.classtype = 1
- entdata_length += sizeof( classtype_gate )
+ header.entdata_length += sizeof( classtype_gate )
gate = classtype_gate()
gate.target = 0
elif classtype == 'k_classtype_block':
node.classtype = 2
- entdata_length += sizeof( classtype_block )
+ header.entdata_length += sizeof( classtype_block )
source = obj.data.cv_data
elif classtype == 'k_classtype_achievement_box':
node.classtype = 13
- entdata_length += sizeof( classtype_achievement_box )
+ header.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
+
+ header.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
elif classtype == 'k_classtype_car_path':
node.classtype = 5
- entdata_length += sizeof( classtype_car_path )
+ header.entdata_length += sizeof( classtype_car_path )
pn = classtype_car_path()
pn.target = 0
target = obj.instance_collection
node.classtype = 6
- entdata_length += sizeof( classtype_instance )
+ header.entdata_length += sizeof( classtype_instance )
inst = classtype_instance()
inst.pstr_file = emplace_string( F"models/{target.name}.mdl" )
elif classtype == 'k_classtype_route_node':
node.classtype = 8
- entdata_length += sizeof( classtype_route_node )
+ header.entdata_length += sizeof( classtype_route_node )
rn = classtype_route_node()
if obj.cv_data.target != None:
elif classtype == 'k_classtype_route':
node.classtype = 9
- entdata_length += sizeof( classtype_route )
+ header.entdata_length += sizeof( classtype_route )
r = classtype_route()
r.colour[0] = obj.cv_data.colour[0]
r.colour[1] = obj.cv_data.colour[1]
node_buffer += [node]
# Write data arrays
- #
- header.anim_count = len(anim_buffer)
+ # TODO: 8 BYTE ALIGNMENT
print( "Writing data" )
fpos = sizeof(header)
header.material_offset = fpos
fpos += sizeof(mdl_material)*header.material_count
- print( F"Animation count: {header.anim_count}" )
+ print( F"Animation count: {len(anim_buffer)}" )
+ header.anim_count = len(anim_buffer)
header.anim_offset = fpos
fpos += sizeof(mdl_animation)*header.anim_count
- print( F"Entdata length: {entdata_length}" )
+ print( F"Entdata length: {header.entdata_length}" )
header.entdata_offset = fpos
- fpos += entdata_length
+ fpos += header.entdata_length
+
+ print( F"Strings length: {len(strings_buffer)}" )
+ header.strings_offset = fpos
+ header.strings_length = len(strings_buffer)
+ fpos += header.strings_length
+
+ # Optional array things
+ print( F"Keyframe count: {header.keyframe_count}" )
+ header.keyframe_offset = fpos
+ fpos += sizeof(mdl_keyframe)*header.keyframe_count
print( F"Vertex count: {header.vertex_count}" )
header.vertex_offset = fpos
header.indice_offset = fpos
fpos += sizeof(c_uint32)*header.indice_count
- print( F"Keyframe count: {animdata_length}" )
- header.animdata_offset = fpos
- fpos += animdata_length
-
- print( F"Strings length: {len(strings_buffer)}" )
- header.strings_offset = fpos
- fpos += len(strings_buffer)
-
header.file_length = fpos
path = F"/home/harry/Documents/carve/models_src/{collection_name}.mdl"
fp.write( bytearray(a) )
for ed in entdata_buffer:
fp.write( bytearray(ed) )
+
+ fp.write( strings_buffer )
+
+ for kf in animdata_buffer:
+ fp.write( bytearray(kf) )
+
for v in vertex_buffer:
fp.write( bytearray(v) )
for i in indice_buffer:
fp.write( bytearray(i) )
- for kf in animdata_buffer:
- fp.write( bytearray(kf) )
- fp.write( strings_buffer )
fp.close()
print( F"Completed {collection_name}.mdl" )
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
b = obj.data.cv_data.v1
class CV_OBJ_SETTINGS(bpy.types.PropertyGroup):
uid: bpy.props.IntProperty( name="" )
- strp: bpy.props.StringProperty(name="string")
+ 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 )
('k_classtype_SKELETON', "","", 11 ),
('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):
_.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"