instance support
[carveJwlIkooP6JGAAIwe30JlM.git] / blender_export.py
index 05f687a42530d0b9b670fcc6b54621b10f32bcb1..8424753135935754e843bddc6d6f53b79329069c 100644 (file)
@@ -96,14 +96,16 @@ class classtype_car_path(Structure):
    _fields_ = [("target",c_uint32),
                ("target1",c_uint32)]
 
+class classtype_instance(Structure):
+   _pack_ = 1
+   _fields_ = [("pstr_file",c_uint32)]
+
 # Exporter
 # ==============================================================================
 
 def write_model(name):
    print( F"Create mode {name}" )
 
-   collection = bpy.data.collections[name]
-   
    header = mdl_header()
    header.identifier = 0xABCD0000
    header.version = 0
@@ -179,6 +181,8 @@ def write_model(name):
    # Do exporting
    #
    print( "  assigning ids" )
+   collection = bpy.data.collections[name]
+   
    header.node_count = 1
    for obj in collection.all_objects:
       obj.cv_data.uid = header.node_count
@@ -210,11 +214,7 @@ def write_model(name):
       node.offset = entdata_length
       classtype = obj.cv_data.classtype
 
-      if classtype == 'k_classtype_none':
-         node.classtype = 0
-         node.offset = 0
-
-      elif classtype == 'k_classtype_gate':
+      if classtype == 'k_classtype_gate':
          node.classtype = 1
          entdata_length += sizeof( classtype_gate )
 
@@ -260,6 +260,20 @@ def write_model(name):
             pn.target1 = obj.cv_data.target1.cv_data.uid
 
          entdata_buffer += [pn]
+      elif obj.is_instancer:
+         target = obj.instance_collection
+
+         node.classtype = 6
+         entdata_length += sizeof( classtype_instance )
+
+         inst = classtype_instance()
+         inst.pstr_file = emplace_string( F"models/{target.name}.mdl" )
+         entdata_buffer += [inst]
+
+      # classtype == 'k_classtype_none':
+      else:
+         node.classtype = 0
+         node.offset = 0
 
       # Process meshes
       #