@@ -462,6 +462,26 @@ function parser_material_parse_vector_input(inp: ui_node_socket_t): string {
462462 }
463463}
464464
465+ function _parser_material_cache_tex_text_node ( file : string , text : string ) {
466+ if ( map_get ( data_cached_images , file ) == null ) {
467+ app_notify_on_init ( function ( text : string ) {
468+ let _text_tool_text : string = context_raw . text_tool_text ;
469+ let _text_tool_image : image_t = context_raw . text_tool_image ;
470+ context_raw . text_tool_text = text ;
471+ context_raw . text_tool_image = null ;
472+
473+ util_render_make_text_preview ( ) ;
474+ let file : string = "tex_text_" + text ;
475+
476+ // TODO: remove old cache
477+ map_set ( data_cached_images , file , context_raw . text_tool_image ) ;
478+
479+ context_raw . text_tool_text = _text_tool_text ;
480+ context_raw . text_tool_image = _text_tool_image ;
481+ } , text ) ;
482+ }
483+ }
484+
465485function parser_material_parse_vector ( node : ui_node_t , socket : ui_node_socket_t ) : string {
466486 if ( node . type == "GROUP" ) {
467487 return parser_material_parse_group ( node , socket ) ;
@@ -544,6 +564,16 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
544564 return tex_store + ".rgb" ;
545565 }
546566 }
567+ else if ( node . type == "TEX_TEXT" ) {
568+ let tex_name : string = parser_material_node_name ( node ) ;
569+ let text_buffer : buffer_t = node . buttons [ 0 ] . default_value ;
570+ let text : string = sys_buffer_to_string ( text_buffer ) ;
571+ let file : string = "tex_text_" + text ;
572+ _parser_material_cache_tex_text_node ( file , text ) ;
573+ let tex : bind_tex_t = parser_material_make_bind_tex ( tex_name , file ) ;
574+ let texstore : string = parser_material_texture_store ( node , tex , tex_name , color_space_t . AUTO ) ;
575+ return texstore + ".rrr" ;
576+ }
547577 else if ( node . type == "TEX_MAGIC" ) {
548578 node_shader_add_function ( parser_material_curshader , str_tex_magic ) ;
549579 let co : string = parser_material_get_coord ( node ) ;
@@ -1422,6 +1452,16 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t):
14221452 return texstore + ".a" ;
14231453 }
14241454 }
1455+ else if ( node . type == "TEX_TEXT" ) {
1456+ let tex_name : string = parser_material_node_name ( node ) ;
1457+ let text_buffer : buffer_t = node . buttons [ 0 ] . default_value ;
1458+ let text : string = sys_buffer_to_string ( text_buffer ) ;
1459+ let file : string = "tex_text_" + text ;
1460+ _parser_material_cache_tex_text_node ( file , text ) ;
1461+ let tex : bind_tex_t = parser_material_make_bind_tex ( tex_name , file ) ;
1462+ let texstore : string = parser_material_texture_store ( node , tex , tex_name , color_space_t . AUTO ) ;
1463+ return texstore + ".r" ;
1464+ }
14251465 else if ( node . type == "TEX_MAGIC" ) {
14261466 node_shader_add_function ( parser_material_curshader , str_tex_magic ) ;
14271467 let co : string = parser_material_get_coord ( node ) ;
@@ -1980,16 +2020,10 @@ function parser_material_enum_data(s: string): string {
19802020 return "" ;
19812021}
19822022
1983- function parser_material_make_texture ( image_node : ui_node_t , tex_name : string , matname : string = null ) : bind_tex_t {
1984- let i : i32 = image_node . buttons [ 0 ] . default_value [ 0 ] ;
1985- let filepath : string = parser_material_enum_data ( base_enum_texts ( image_node . type ) [ i ] ) ;
1986- if ( filepath == "" || string_index_of ( filepath , "." ) == - 1 ) {
1987- return null ;
1988- }
1989-
2023+ function parser_material_make_bind_tex ( tex_name : string , file : string ) : bind_tex_t {
19902024 let tex : bind_tex_t = {
19912025 name : tex_name ,
1992- file : filepath
2026+ file : file
19932027 } ;
19942028
19952029 if ( context_raw . texture_filter ) {
@@ -2009,6 +2043,16 @@ function parser_material_make_texture(image_node: ui_node_t, tex_name: string, m
20092043 return tex ;
20102044}
20112045
2046+ function parser_material_make_texture ( image_node : ui_node_t , tex_name : string ) : bind_tex_t {
2047+ let i : i32 = image_node . buttons [ 0 ] . default_value [ 0 ] ;
2048+ let filepath : string = parser_material_enum_data ( base_enum_texts ( image_node . type ) [ i ] ) ;
2049+ if ( filepath == "" || string_index_of ( filepath , "." ) == - 1 ) {
2050+ return null ;
2051+ }
2052+
2053+ return parser_material_make_bind_tex ( tex_name , filepath ) ;
2054+ }
2055+
20122056function parser_material_is_pow ( num : i32 ) : bool {
20132057 return ( ( num & ( num - 1 ) ) == 0 ) && num != 0 ;
20142058}
0 commit comments