2018-05-11 02:43:57 +09:00
bl_info = {
2018-05-11 04:24:47 +09:00
" name " : " Export COL for Super Mario Sunshine " ,
2018-05-11 02:43:57 +09:00
" author " : " Blank " ,
" version " : ( 1 , 0 , 0 ) ,
" blender " : ( 2 , 71 , 0 ) ,
" location " : " File > Export > Collision (.col) " ,
2018-05-11 04:24:47 +09:00
" description " : " This script allows you do export col files directly from blender. Based on Blank ' s obj2col " ,
2018-05-16 05:42:13 +09:00
" warning " : " Runs update function every 0.2 seconds " ,
2018-05-11 02:43:57 +09:00
" category " : " Import-Export "
}
import bpy
2018-05-11 04:24:47 +09:00
import bmesh
2018-05-16 05:42:13 +09:00
import threading
2018-05-14 01:59:54 +09:00
from enum import Enum
2018-05-11 04:24:47 +09:00
from btypes . big_endian import *
2018-05-12 08:32:51 +09:00
from bpy . types import PropertyGroup , Panel , Scene , Operator
from bpy . utils import register_class , unregister_class
2018-05-16 05:42:13 +09:00
from bpy . app . handlers import persistent
2018-05-11 02:43:57 +09:00
from bpy_extras . io_utils import ExportHelper
from bpy . props import ( BoolProperty ,
FloatProperty ,
StringProperty ,
2018-05-12 08:32:51 +09:00
EnumProperty ,
IntProperty ,
PointerProperty ,
2018-05-11 02:43:57 +09:00
)
2018-05-16 05:42:13 +09:00
2018-05-11 02:43:57 +09:00
class Header ( Struct ) :
vertex_count = uint32
vertex_offset = uint32
group_count = uint32
group_offset = uint32
class Vertex ( Struct ) :
x = float32
y = float32
z = float32
def __init__ ( self , x , y , z ) :
self . x = x
self . y = y
self . z = z
class Group ( Struct ) :
2018-05-21 07:30:22 +09:00
CollisionType = uint16 #Properties of collision. e.g. is it water? or what?
2018-05-11 02:43:57 +09:00
triangle_count = uint16
2018-05-21 07:30:22 +09:00
__padding__ = Padding ( 1 , b ' \x00 ' ) #Group flags, set them to 0 here
has_ColParameter = bool8 #Set 0x0001 to 1 if we have ColParameter values so the game doesn't ignore it
__padding__ = Padding ( 2 ) #Actual padding
2018-05-11 02:43:57 +09:00
vertex_index_offset = uint32
2018-05-21 07:30:22 +09:00
TerrainType_offset = uint32 # 0-18,20,21,23,24,27-31
unknown_offset = uint32 # 0-27
ColParameter_offset = uint32 # 0,1,2,3,4,8,255,6000,7500,7800,8000,8400,9000,10000,10300,12000,14000,17000,19000,20000,21000,22000,27500,30300
2018-05-11 02:43:57 +09:00
class Triangle :
def __init__ ( self ) :
self . vertex_indices = None
2018-05-21 07:30:22 +09:00
self . ColType = 0
self . TerrainType = 0
self . unknown = 0
self . ColParameter = None
2018-05-11 02:43:57 +09:00
@property
2018-05-21 07:30:22 +09:00
def has_ColParameter ( self ) :
return self . ColParameter is not None
2018-05-11 02:43:57 +09:00
def pack ( stream , vertices , triangles ) : #pack triangles into col file
groups = [ ]
for triangle in triangles :
for group in groups : #for each triangle add to appropriate group
2018-05-21 07:30:22 +09:00
if triangle . ColType != group . CollisionType : continue #break out of loop to next cycle
2018-05-11 02:43:57 +09:00
group . triangles . append ( triangle )
break
else : #if no group has been found
group = Group ( ) #create a new group
2018-05-21 07:30:22 +09:00
group . CollisionType = triangle . ColType
group . has_ColParameter = triangle . has_ColParameter
2018-05-11 02:43:57 +09:00
group . triangles = [ triangle ]
groups . append ( group ) #add to list of groups
header = Header ( )
header . vertex_count = len ( vertices )
header . vertex_offset = Header . sizeof ( ) + Group . sizeof ( ) * len ( groups )
header . group_count = len ( groups )
header . group_offset = Header . sizeof ( )
Header . pack ( stream , header )
stream . write ( b ' \x00 ' * Group . sizeof ( ) * len ( groups ) )
for vertex in vertices :
Vertex . pack ( stream , vertex )
for group in groups :
group . triangle_count = len ( group . triangles )
group . vertex_index_offset = stream . tell ( )
for triangle in group . triangles :
uint16 . pack ( stream , triangle . vertex_indices [ 0 ] )
uint16 . pack ( stream , triangle . vertex_indices [ 1 ] )
uint16 . pack ( stream , triangle . vertex_indices [ 2 ] )
for group in groups :
2018-05-21 07:30:22 +09:00
group . TerrainType_offset = stream . tell ( )
2018-05-11 02:43:57 +09:00
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
uint8 . pack ( stream , triangle . TerrainType )
2018-05-11 02:43:57 +09:00
for group in groups :
2018-05-21 07:30:22 +09:00
group . unknown_offset = stream . tell ( )
2018-05-11 02:43:57 +09:00
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
uint8 . pack ( stream , triangle . unknown )
2018-05-11 02:43:57 +09:00
for group in groups :
2018-05-21 07:30:22 +09:00
if not group . has_ColParameter :
group . ColParameter_offset = 0
2018-05-11 02:43:57 +09:00
else :
2018-05-21 07:30:22 +09:00
group . ColParameter_offset = stream . tell ( )
2018-05-11 02:43:57 +09:00
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
uint16 . pack ( stream , triangle . ColParameter )
2018-05-11 02:43:57 +09:00
stream . seek ( header . group_offset )
for group in groups :
Group . pack ( stream , group )
def unpack ( stream ) :
header = Header . unpack ( stream )
stream . seek ( header . group_offset )
groups = [ Group . unpack ( stream ) for _ in range ( header . group_count ) ]
stream . seek ( header . vertex_offset )
vertices = [ Vertex . unpack ( stream ) for _ in range ( header . vertex_count ) ]
for group in groups :
group . triangles = [ Triangle ( ) for _ in range ( group . triangle_count ) ]
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
triangle . ColType = group . CollisionType
2018-05-11 02:43:57 +09:00
for group in groups :
stream . seek ( group . vertex_index_offset )
for triangle in group . triangles :
triangle . vertex_indices = [ uint16 . unpack ( stream ) for _ in range ( 3 ) ]
for group in groups :
2018-05-21 07:30:22 +09:00
stream . seek ( group . TerrainType_offset )
2018-05-11 02:43:57 +09:00
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
triangle . TerrainType = uint8 . unpack ( stream )
2018-05-11 02:43:57 +09:00
for group in groups :
2018-05-21 07:30:22 +09:00
stream . seek ( group . unknown_offset )
2018-05-11 02:43:57 +09:00
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
triangle . unknown = uint8 . unpack ( stream )
2018-05-11 02:43:57 +09:00
for group in groups :
2018-05-21 07:30:22 +09:00
if not group . has_ColParameter : continue
stream . seek ( group . ColParameter_offset )
2018-05-11 02:43:57 +09:00
for triangle in group . triangles :
2018-05-21 07:30:22 +09:00
triangle . ColParameter = uint16 . unpack ( stream )
2018-05-11 02:43:57 +09:00
triangles = sum ( ( group . triangles for group in groups ) , [ ] )
return vertices , triangles
2018-05-21 07:30:22 +09:00
2018-05-14 08:11:14 +09:00
class ImportCOL ( Operator , ExportHelper ) : #Operator that exports the collision model into .col file
""" Import a COL file """
bl_idname = " import_mesh.col "
bl_label = " Import COL "
filter_glob = StringProperty (
default = " *.col " ,
options = { ' HIDDEN ' } ,
) #This property filters what you see in the file browser to just .col files
check_extension = True
filename_ext = " .col " #This is the extension that the model will have
def execute ( self , context ) :
ColStream = open ( self . filepath , ' rb ' )
CollisionVertexList = [ ] #Store a list of verticies
Triangles = [ ] #List of triangles, each containing indicies of verticies
CollisionVertexList , Triangles = unpack ( ColStream )
2018-05-15 03:31:31 +09:00
2018-05-14 08:11:14 +09:00
mesh = bpy . data . meshes . new ( " mesh " ) # add a new mesh
obj = bpy . data . objects . new ( " MyObject " , mesh ) # add a new object using the mesh
scene = bpy . context . scene
scene . objects . link ( obj ) # put the object into the scene (link)
scene . objects . active = obj # set as the active object in the scene
obj . select = True # select object
mesh = bpy . context . object . data
bm = bmesh . new ( )
2018-05-21 07:30:22 +09:00
ColTypeLayer = bm . faces . layers . int . new ( CollisionLayer . ColType . value ) #Create new data layers
TerrainTypeLayer = bm . faces . layers . int . new ( CollisionLayer . TerrainType . value )
UnknownFieldLayer = bm . faces . layers . int . new ( CollisionLayer . Unknown . value )
HasColParameterFieldLayer = bm . faces . layers . int . new ( CollisionLayer . HasColParameter . value )
ColParameterFieldLayer = bm . faces . layers . int . new ( CollisionLayer . ColParameter . value )
2018-05-15 03:31:31 +09:00
2018-05-14 08:11:14 +09:00
BMeshVertexList = [ ]
2018-05-15 03:31:31 +09:00
for v in CollisionVertexList :
BMeshVertexList . append ( bm . verts . new ( ( v . x , - v . z , v . y ) ) ) # add a new vert
2018-05-14 08:11:14 +09:00
for f in Triangles :
2018-05-15 03:31:31 +09:00
try : #Try and catch to avoid exception on duplicate triangles. Dodgy...
MyFace = bm . faces . new ( ( BMeshVertexList [ f . vertex_indices [ 0 ] ] , BMeshVertexList [ f . vertex_indices [ 1 ] ] , BMeshVertexList [ f . vertex_indices [ 2 ] ] ) )
2018-05-21 07:30:22 +09:00
MyFace [ ColTypeLayer ] = f . ColType
MyFace [ TerrainTypeLayer ] = f . TerrainType
MyFace [ UnknownFieldLayer ] = f . Unknown
MyFace [ ColParameterFieldLayer ] = f . ColParameter
if MyFace [ ColParameterFieldLayer ] is not None :
MyFace [ HasColParameterFieldLayer ] = True
2018-05-15 03:31:31 +09:00
except :
continue
2018-05-14 08:11:14 +09:00
bm . to_mesh ( mesh )
mesh . update ( )
bm . free ( )
return { ' FINISHED ' }
2018-05-14 02:17:38 +09:00
class ExportCOL ( Operator , ExportHelper ) : #Operator that exports the collision model into .col file
2018-05-11 02:43:57 +09:00
""" Save a COL file """
bl_idname = " export_mesh.col "
bl_label = " Export COL "
2018-05-14 02:17:38 +09:00
filter_glob = StringProperty (
2018-05-11 02:43:57 +09:00
default = " *.col " ,
options = { ' HIDDEN ' } ,
2018-05-14 02:17:38 +09:00
) #This property filters what you see in the file browser to just .col files
2018-05-11 02:43:57 +09:00
check_extension = True
2018-05-14 02:17:38 +09:00
filename_ext = " .col " #This is the extension that the model will have
2018-05-11 02:43:57 +09:00
#To do: add material presets
2018-05-15 04:16:47 +09:00
2018-05-15 04:36:36 +09:00
Scale = FloatProperty (
2018-05-15 04:16:47 +09:00
name = " Scale factor " ,
description = " Scale the col file by this amount " ,
default = 1 ,
)
2018-05-11 02:43:57 +09:00
def execute ( self , context ) : # execute() is called by blender when running the operator.
2018-05-14 02:17:38 +09:00
bpy . ops . object . mode_set ( mode = ' OBJECT ' ) #Set mode to be object mode
VertexList = [ ] #Store a list of verticies
Triangles = [ ] #List of triangles, each containing indicies of verticies
bm = bmesh . new ( ) #Define new bmesh
2018-05-11 04:24:47 +09:00
for Obj in bpy . context . scene . objects : #join all objects
MyMesh = Obj . to_mesh ( context . scene , True , ' PREVIEW ' ) #make a copy of the object we can modify freely
2018-05-14 02:17:38 +09:00
bm . from_mesh ( MyMesh ) #Add the above copy into the bmesh
2018-05-11 04:24:47 +09:00
bmesh . ops . triangulate ( bm , faces = bm . faces [ : ] , quad_method = 0 , ngon_method = 0 ) #triangulate bmesh
#triangulate_mesh(Mesh)
2018-05-21 07:30:22 +09:00
ColTypeLayer = bm . faces . layers . int . get ( CollisionLayer . ColType . value )
TerrainTypeLayer = bm . faces . layers . int . get ( CollisionLayer . TerrainType . value )
UnknownFieldLayer = bm . faces . layers . int . get ( CollisionLayer . Unknown . value )
HasColParameterFieldLayer = bm . faces . layers . int . get ( CollisionLayer . HasColParameter . value )
ColParameterFieldLayer = bm . faces . layers . int . get ( CollisionLayer . ColParameter . value )
2018-05-14 04:24:43 +09:00
2018-05-11 04:24:47 +09:00
2018-05-14 04:24:43 +09:00
for Vert in bm . verts :
2018-05-15 04:16:47 +09:00
VertexList . append ( Vertex ( Vert . co . x * self . Scale , Vert . co . z * self . Scale , - Vert . co . y * self . Scale ) ) #add in verts, make sure y is up
2018-05-11 02:43:57 +09:00
2018-05-14 04:24:43 +09:00
for Face in bm . faces :
2018-05-11 02:43:57 +09:00
MyTriangle = Triangle ( )
2018-05-14 04:24:43 +09:00
MyTriangle . vertex_indices = [ Face . verts [ 0 ] . index , Face . verts [ 1 ] . index , Face . verts [ 2 ] . index ] #add three vertex indicies
2018-05-21 07:30:22 +09:00
if ColTypeLayer is not None :
MyTriangle . ColType = Face [ ColTypeLayer ]
MyTriangle . TerrainType = Face [ TerrainTypeLayer ]
MyTriangle . Unknown = Face [ UnknownFieldLayer ]
if Face [ HasColParameterFieldLayer ] != 0 :
MyTriangle . ColParameter = Face [ ColParameterFieldLayer ]
2018-05-11 02:43:57 +09:00
Triangles . append ( MyTriangle ) #add triangles
ColStream = open ( self . filepath , ' wb ' )
pack ( ColStream , VertexList , Triangles )
return { ' FINISHED ' } # this lets blender know the operator finished successfully.
2018-05-12 08:32:51 +09:00
2018-05-14 02:17:38 +09:00
class CollisionLayer ( Enum ) : #This stores the data layer names that each Unknown will be on.
2018-05-21 07:30:22 +09:00
ColType = " CollisionEditorColType "
TerrainType = " CollisionEditorTerrainType " #For example TerrainType is stored on a data layer called "CollisionEditorTerrainType"
Unknown = " CollisionEditorUnknown "
HasColParameter = " CollisionEditorHasColParameter " #This layer is an integer because boolean layers don't exist
ColParameter = " CollisionEditorColParameter "
2018-05-14 01:59:54 +09:00
2018-05-21 07:30:22 +09:00
def ColTypeUpdate ( self , context ) : #These functions are called when the UI elements change
ChangeValuesOfSelection ( CollisionLayer . ColType . value , bpy . context . scene . ColEditor . ColType )
2018-05-14 01:59:54 +09:00
return
2018-05-11 02:43:57 +09:00
2018-05-21 07:30:22 +09:00
def TerrainTypeUpdate ( self , context ) :
ChangeValuesOfSelection ( CollisionLayer . TerrainType . value , bpy . context . scene . ColEditor . TerrainType )
2018-05-14 01:59:54 +09:00
return
2018-05-21 07:30:22 +09:00
def UnknownFieldUpdate ( self , context ) :
ChangeValuesOfSelection ( CollisionLayer . Unknown . value , bpy . context . scene . ColEditor . UnknownField )
2018-05-14 01:59:54 +09:00
return
2018-05-21 07:30:22 +09:00
def HasColParameterFieldUpdate ( self , context ) :
ToSet = 1 if bpy . context . scene . ColEditor . HasColParameterField else 0 #In this case a TRUE value is represented by a 1 and FALSE by 0
ChangeValuesOfSelection ( CollisionLayer . HasColParameter . value , ToSet )
2018-05-14 01:59:54 +09:00
return
2018-05-21 07:30:22 +09:00
def ColParameterFieldUpdate ( self , context ) :
ChangeValuesOfSelection ( CollisionLayer . ColParameter . value , bpy . context . scene . ColEditor . ColParameterField )
2018-05-12 08:32:51 +09:00
return
2018-05-16 05:42:13 +09:00
2018-05-12 08:32:51 +09:00
class CollisionProperties ( PropertyGroup ) : #This defines the UI elements
2018-05-21 07:30:22 +09:00
ColType = IntProperty ( name = " Collision type " , default = 0 , min = 0 , max = 65535 , update = ColTypeUpdate ) #Here we put parameters for the UI elements and point to the Update functions
TerrainType = IntProperty ( name = " Sound " , default = 0 , min = 0 , max = 255 , update = TerrainTypeUpdate )
UnknownField = IntProperty ( name = " Unknown " , default = 0 , min = 0 , max = 255 , update = UnknownFieldUpdate ) #I probably should have made these an array
HasColParameterField = BoolProperty ( name = " Has Parameter " , default = False , update = HasColParameterFieldUpdate )
ColParameterField = IntProperty ( name = " Parameter " , default = 0 , min = 0 , max = 65535 , update = ColParameterFieldUpdate )
2018-05-12 08:32:51 +09:00
class CollisionPanel ( Panel ) : #This panel houses the UI elements defined in the CollisionProperties
2018-05-14 01:59:54 +09:00
bl_label = " Edit Collision Values "
2018-05-11 20:38:36 +09:00
bl_space_type = " PROPERTIES "
bl_region_type = " WINDOW "
bl_context = " object "
2018-05-16 05:42:13 +09:00
@classmethod
def poll ( cls , context ) :
# Only allow in edit mode for a selected mesh.
return context . mode == " EDIT_MESH " and context . object is not None and context . object . type == " MESH "
2018-05-11 20:38:36 +09:00
def draw ( self , context ) :
2018-05-14 01:59:54 +09:00
EnableColumns = False #Boolean is true means we will enable the columns
if ( bpy . context . object . mode == ' EDIT ' ) :
obj = bpy . context . scene . objects . active #This method might be quite taxing
bm = bmesh . from_edit_mesh ( obj . data )
2018-05-21 07:30:22 +09:00
ColTypeLayer = bm . faces . layers . int . get ( CollisionLayer . ColType . value ) #Check if this layer exists
if ColTypeLayer is not None : #If the model has collision values
2018-05-14 02:17:38 +09:00
EnableColumns = True #Then we enabled editing the values
2018-05-14 01:59:54 +09:00
del bm
del obj
row = self . layout . row ( align = True )
row . alignment = ' EXPAND '
2018-05-14 02:17:38 +09:00
row . operator ( " init.colvalues " , text = ' Initialise values ' ) #Here we put the UI elements defined in CollisionProperties into rows and columns
2018-05-14 01:59:54 +09:00
2018-05-12 08:32:51 +09:00
column1 = self . layout . column ( align = True )
2018-05-21 07:30:22 +09:00
column1 . prop ( bpy . context . scene . ColEditor , " ColType " )
column1 . prop ( bpy . context . scene . ColEditor , " TerrainType " )
column1 . prop ( bpy . context . scene . ColEditor , " UnknownField " )
2018-05-14 01:59:54 +09:00
column1 . enabled = EnableColumns
2018-05-12 08:32:51 +09:00
2018-05-21 07:30:22 +09:00
column1 . prop ( bpy . context . scene . ColEditor , " HasColParameterField " )
2018-05-12 08:32:51 +09:00
column2 = self . layout . column ( align = True )
2018-05-21 07:30:22 +09:00
column2 . prop ( bpy . context . scene . ColEditor , " ColParameterField " )
column2 . enabled = bpy . context . scene . ColEditor . HasColParameterField and EnableColumns #Collision values must exist AND we must have "Has ColParameter" checked
2018-05-12 08:32:51 +09:00
2018-05-14 02:17:38 +09:00
class InitialValues ( Operator ) : #This creates the data layers that store the collision values
2018-05-12 08:32:51 +09:00
bl_idname = " init.colvalues "
2018-05-14 01:59:54 +09:00
bl_label = " Initialise Collision Values "
2018-05-12 08:32:51 +09:00
def execute ( self , context ) :
2018-05-14 01:59:54 +09:00
obj = bpy . context . scene . objects . active
bm = bmesh . from_edit_mesh ( obj . data )
2018-05-21 07:30:22 +09:00
bm . faces . layers . int . new ( CollisionLayer . ColType . value ) #Uses Enum to get names
bm . faces . layers . int . new ( CollisionLayer . TerrainType . value )
bm . faces . layers . int . new ( CollisionLayer . Unknown . value )
bm . faces . layers . int . new ( CollisionLayer . HasColParameter . value )
bm . faces . layers . int . new ( CollisionLayer . ColParameter . value )
2018-05-12 08:32:51 +09:00
return { ' FINISHED ' }
2018-05-15 03:31:31 +09:00
2018-05-14 02:17:38 +09:00
def ChangeValuesOfSelection ( ValueToChange , ValueToSet ) :
2018-05-14 01:59:54 +09:00
obj = bpy . context . scene . objects . active
bm = bmesh . from_edit_mesh ( obj . data )
2018-05-14 02:17:38 +09:00
selected_faces = [ f for f in bm . faces if f . select ] #This gets an array of selected faces
2018-05-14 01:59:54 +09:00
#get the custom data layer by its name
my_id = bm . faces . layers . int [ ValueToChange ]
for face in bm . faces :
if ( face . select == True ) :
face [ my_id ] = ValueToSet
2018-05-21 07:30:22 +09:00
if ValueToChange == CollisionLayer . ColParameter . value : #If you somehow edit ColParameter when HasColParameter is off, like with a group selection, make sure to turn it on
HasColParameterFieldLayer = bm . faces . layers . int . get ( CollisionLayer . HasColParameter . value )
face [ HasColParameterFieldLayer ] = 1
2018-05-14 04:24:43 +09:00
2018-05-14 01:59:54 +09:00
2018-05-14 02:17:38 +09:00
bmesh . update_edit_mesh ( obj . data , False , False ) #Update mesh with new values
2018-05-14 01:59:54 +09:00
2018-05-16 05:42:13 +09:00
@persistent
def UpdateUI ( scene ) :
obj = scene . objects . active
if ( obj . mode == ' EDIT ' and obj . type == ' MESH ' ) :
2018-05-14 01:59:54 +09:00
bm = bmesh . from_edit_mesh ( obj . data )
2018-05-21 07:30:22 +09:00
ColTypeLayer = bm . faces . layers . int . get ( CollisionLayer . ColType . value ) #Check if this layer exists
if ColTypeLayer is not None : #If the model has collision values
2018-05-16 05:42:13 +09:00
face = bm . faces . active
if face is not None :
2018-05-21 07:30:22 +09:00
bpy . context . scene . ColEditor [ " ColType " ] = face [ ColTypeLayer ] #This is why they should have been an array
2018-05-14 04:24:43 +09:00
2018-05-21 07:30:22 +09:00
TerrainTypeLayer = bm . faces . layers . int . get ( CollisionLayer . TerrainType . value )
bpy . context . scene . ColEditor [ " TerrainType " ] = face [ TerrainTypeLayer ] #We call it like this so that we don't call the update function. Otherwise selecting multiple faces would set them all equal
2018-05-14 04:24:43 +09:00
2018-05-21 07:30:22 +09:00
UnknownFieldLayer = bm . faces . layers . int . get ( CollisionLayer . Unknown . value )
bpy . context . scene . ColEditor [ " UnknownField " ] = face [ UnknownFieldLayer ] #We choose index 0 but it doesn't really matter. Unfortunetly you can't get int properties to display "--" used, for example, when there are different ColType values across the selected faces
2018-05-14 04:24:43 +09:00
2018-05-21 07:30:22 +09:00
HasColParameterFieldLayer = bm . faces . layers . int . get ( CollisionLayer . HasColParameter . value )
bpy . context . scene . ColEditor [ " HasColParameterField " ] = False if face [ HasColParameterFieldLayer ] == 0 else True
2018-05-14 04:24:43 +09:00
2018-05-21 07:30:22 +09:00
ColParameterFieldLayer = bm . faces . layers . int . get ( CollisionLayer . ColParameter . value )
bpy . context . scene . ColEditor [ " ColParameterField " ] = face [ ColParameterFieldLayer ]
2018-05-16 05:42:13 +09:00
return None
2018-05-15 06:01:15 +09:00
2018-05-16 05:42:13 +09:00
classes = ( ExportCOL , ImportCOL , CollisionPanel , InitialValues , CollisionProperties ) #list of classes to register/unregister
2018-05-11 02:43:57 +09:00
def register ( ) :
2018-05-12 08:32:51 +09:00
for i in classes :
register_class ( i )
Scene . ColEditor = PointerProperty ( type = CollisionProperties ) #store in the scene
2018-05-16 05:42:13 +09:00
bpy . app . handlers . scene_update_post . append ( UpdateUI )
2018-05-14 08:11:14 +09:00
bpy . types . INFO_MT_file_export . append ( menu_export ) #Add to export menu
bpy . types . INFO_MT_file_import . append ( menu_import ) #Add to export menu
2018-05-12 08:32:51 +09:00
2018-05-11 02:43:57 +09:00
2018-05-14 08:11:14 +09:00
def menu_export ( self , context ) :
2018-05-11 02:43:57 +09:00
self . layout . operator ( ExportCOL . bl_idname , text = " Collision (.col) " )
2018-05-14 08:11:14 +09:00
def menu_import ( self , context ) :
self . layout . operator ( ImportCOL . bl_idname , text = " Collision (.col) " )
2018-05-11 02:43:57 +09:00
def unregister ( ) :
2018-05-12 08:32:51 +09:00
for i in classes :
unregister_class ( i )
2018-05-14 08:11:14 +09:00
bpy . types . INFO_MT_file_export . remove ( menu_export )
bpy . types . INFO_MT_file_import . remove ( menu_import )
2018-05-16 05:42:13 +09:00
if UpdateUI in bpy . app . handlers . render_post :
bpy . app . handlers . render_complete . remove ( UpdateUI ) #remove handlers
2018-05-11 02:43:57 +09:00
2018-05-16 05:42:13 +09:00
2018-05-11 02:43:57 +09:00
# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == " __main__ " :
register ( )