c599936aaceecffa4417df752ad20864e256eaa9
3 def material_tex_image(v
):
15 # Default shader setup
22 "image": "tex_diffuse"
26 "A": material_tex_image("tex_diffuse"),
27 "B": material_tex_image("tex_decal")
34 "Color": material_tex_image("tex_normal")
40 "Color": material_tex_image("tex_diffuse")
44 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
46 def material_info(mat
):
50 # Using the cxr_graph_mapping as a reference, go through the shader
51 # graph and gather all $props from it.
53 def _graph_read( node_def
, node
=None, depth
=0 ):
62 _graph_read
.extracted
= []
65 for node_idname
in node_def
:
67 for n
in mat
.node_tree
.nodes
:
69 if n
.name
== node_idname
:
71 node_def
= node_def
[node_idname
]
83 link_def
= node_def
[link
]
85 if isinstance( link_def
, dict ):
90 if isinstance( x
, bpy
.types
.NodeSocketColor
):
100 if node_link
and node_link
.is_linked
:
102 # look for definitions for the connected node type
104 from_node
= node_link
.links
[0].from_node
106 node_name
= from_node
.name
.split('.')[0]
107 if node_name
in link_def
:
109 from_node_def
= link_def
[ node_name
]
111 _graph_read( from_node_def
, from_node
, depth
+1 )
116 if "default" in link_def
:
118 prop
= link_def
['default']
119 info
[prop
] = node_link
.default_value
126 info
[prop
] = getattr( node
, link
)
131 _graph_read( cxr_graph_mapping
)
135 def sr_compile_material( mat
):
139 if mat
.name
in sr_compile
.material_cache
:
140 return sr_compile
.material_cache
[mat
.name
]
142 print( F
'[SR] Compiling material {mat.name}' )
144 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
145 sr_compile
.material_cache
[mat
.name
] = index
148 m
.pstr_name
= sr_compile_string( mat
.name
)
151 if mat
.SR_data
.collision
:
153 flags |
= 0x2 # collision flag
154 if (mat
.SR_data
.shader
!= 'invisible') and \
155 (mat
.SR_data
.shader
!= 'boundary'):
157 if mat
.SR_data
.skate_surface
: flags |
= 0x1
158 if mat
.SR_data
.grow_grass
: flags |
= 0x4
159 if mat
.SR_data
.grind_surface
: flags |
= 0x8
160 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
162 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
163 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
164 if mat
.SR_data
.shader
== 'walking': flags |
= (0x10|
0x80)
168 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
169 inf
= material_info( mat
)
172 buf
= (c_uint8
* 512)()
173 sr_lib
.vg_msg_init( pointer(msg
), buf
, 512 )
175 if mat
.SR_data
.tex_diffuse_rt
>= 0:
177 value
= 0x80000000 | mat
.SR_data
.tex_diffuse_rt
178 shader_prop_u32( msg
, 'tex_diffuse', value
)
182 if 'tex_diffuse' in inf
:
184 shader_prop_texture( msg
, 'tex_diffuse', inf
['tex_diffuse'] )
188 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
189 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
190 if mat
.SR_data
.shader
== 'foliage': m
.shader
= 10
191 if mat
.SR_data
.shader
== 'terrain_blend':
194 shader_prop_rgba( msg
, "sand_colour", mat
.SR_data
.sand_colour
)
195 shader_prop_f32( msg
, "blend_offset", 2, mat
.SR_data
.blend_offset
)
197 if mat
.SR_data
.shader
== 'vertex_blend':
200 shader_prop_f32( msg
, "blend_offset", 2, mat
.SR_data
.blend_offset
)
202 if mat
.SR_data
.shader
== 'water':
205 shader_prop_rgba( msg
, 'shore_colour', mat
.SR_data
.shore_colour
)
206 shader_prop_rgba( msg
, 'deep_colour', mat
.SR_data
.ocean_colour
)
207 shader_prop_f32( msg
, 'fog_scale', 1, (mat
.SR_data
.water_fog
,) )
208 shader_prop_f32( msg
, 'fresnel', 1, (mat
.SR_data
.water_fresnel
,) )
209 shader_prop_f32( msg
, 'water_scale', 1, (mat
.SR_data
.water_scale
,) )
210 shader_prop_f32( msg
, 'wave_speed', 4, mat
.SR_data
.water_rate
)
212 if mat
.SR_data
.shader
== 'invisible':
216 if mat
.SR_data
.shader
== 'boundary':
220 if mat
.SR_data
.shader
== 'fxglow':
224 if mat
.SR_data
.shader
== 'cubemap':
228 shader_prop_u32( msg
, 'cubemap', sr_entity_id( mat
.SR_data
.cubemap
) )
229 shader_prop_rgba( msg
, 'tint', mat
.SR_data
.tint
)
231 if mat
.SR_data
.shader
== 'walking':
236 # sr_lib.vg_msg_print( byref(msg), msg.cur.co )
238 m
.props
.kvs
.offset
= len( sr_compile
.shader_data
)
239 m
.props
.kvs
.size
= msg
.cur
.co
241 sr_compile
.shader_data
.extend( bytearray(buf
[:msg
.cur
.co
]) )
242 sr_compile
.material_data
.extend( bytearray(m
) )