Skip to content

Commit 869effd

Browse files
committed
Add text texture node
1 parent 257ba3d commit 869effd

File tree

2 files changed

+114
-8
lines changed

2 files changed

+114
-8
lines changed

base/sources/nodes_material.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,68 @@ let nodes_material_texture: ui_node_t[] = [
17381738
],
17391739
width: 0
17401740
},
1741+
{
1742+
id: 0,
1743+
name: _tr("Text Texture"),
1744+
type: "TEX_TEXT", // extension
1745+
x: 0,
1746+
y: 0,
1747+
color: 0xff4982a0,
1748+
inputs: [
1749+
{
1750+
id: 0,
1751+
node_id: 0,
1752+
name: _tr("Vector"),
1753+
type: "VECTOR",
1754+
color: 0xff6363c7,
1755+
default_value: f32_array_create_xyz(0.0, 0.0, 0.0),
1756+
min: 0.0,
1757+
max: 1.0,
1758+
precision: 100,
1759+
display: 0
1760+
}
1761+
],
1762+
outputs: [
1763+
{
1764+
id: 0,
1765+
node_id: 0,
1766+
name: _tr("Color"),
1767+
type: "RGBA",
1768+
color: 0xffc7c729,
1769+
default_value: f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
1770+
min: 0.0,
1771+
max: 1.0,
1772+
precision: 100,
1773+
display: 0
1774+
},
1775+
{
1776+
id: 0,
1777+
node_id: 0,
1778+
name: _tr("Alpha"),
1779+
type: "VALUE",
1780+
color: 0xffa1a1a1,
1781+
default_value: f32_array_create_x(1.0),
1782+
min: 0.0,
1783+
max: 1.0,
1784+
precision: 100,
1785+
display: 0
1786+
}
1787+
],
1788+
buttons: [
1789+
{
1790+
name: "text",
1791+
type: "STRING",
1792+
output: -1,
1793+
default_value: f32_array_create_x(0), // "",
1794+
data: null,
1795+
min: 0.0,
1796+
max: 1.0,
1797+
precision: 100,
1798+
height: 0
1799+
}
1800+
],
1801+
width: 0
1802+
},
17411803
{
17421804
id: 0,
17431805
name: _tr("Magic Texture"),

base/sources/parser_material.ts

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
465485
function 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+
20122056
function parser_material_is_pow(num: i32): bool {
20132057
return ((num & (num - 1)) == 0) && num != 0;
20142058
}

0 commit comments

Comments
 (0)