Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | b.add_input<decl::Float>(N_("Text Box Height")) | ||||
| .subtype(PROP_DISTANCE) | .subtype(PROP_DISTANCE) | ||||
| .make_available([](bNode &node) { | .make_available([](bNode &node) { | ||||
| node_storage(node).overflow = GEO_NODE_STRING_TO_CURVES_MODE_SCALE_TO_FIT; | node_storage(node).overflow = GEO_NODE_STRING_TO_CURVES_MODE_SCALE_TO_FIT; | ||||
| }); | }); | ||||
| b.add_output<decl::Geometry>(N_("Curve Instances")); | b.add_output<decl::Geometry>(N_("Curve Instances")); | ||||
| b.add_output<decl::String>(N_("Remainder")).make_available([](bNode &node) { | b.add_output<decl::String>(N_("Remainder")).make_available([](bNode &node) { | ||||
| node_storage(node).overflow = GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE; | node_storage(node).overflow = GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE; | ||||
| }); | }); | ||||
| b.add_output<decl::Int>(N_("Line")).field_source(); | b.add_output<decl::Int>(N_("Line")).field_on_auto(); | ||||
| b.add_output<decl::Vector>(N_("Pivot Point")).field_source(); | b.add_output<decl::Vector>(N_("Pivot Point")).field_on_auto(); | ||||
| } | } | ||||
| static void node_layout(uiLayout *layout, struct bContext *C, PointerRNA *ptr) | static void node_layout(uiLayout *layout, struct bContext *C, PointerRNA *ptr) | ||||
| { | { | ||||
| uiLayoutSetPropSep(layout, true); | uiLayoutSetPropSep(layout, true); | ||||
| uiLayoutSetPropDecorate(layout, false); | uiLayoutSetPropDecorate(layout, false); | ||||
| uiTemplateID(layout, | uiTemplateID(layout, | ||||
| C, | C, | ||||
| ▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | for (const int i : IndexRange(text_len)) { | ||||
| if ((info[i].flag & CU_CHINFO_OVERFLOW) && (cu.overflow == CU_OVERFLOW_TRUNCATE)) { | if ((info[i].flag & CU_CHINFO_OVERFLOW) && (cu.overflow == CU_OVERFLOW_TRUNCATE)) { | ||||
| const int offset = BLI_str_utf8_offset_from_index(layout.text.c_str(), i + 1); | const int offset = BLI_str_utf8_offset_from_index(layout.text.c_str(), i + 1); | ||||
| layout.truncated_text = layout.text.substr(offset); | layout.truncated_text = layout.text.substr(offset); | ||||
| layout.text = layout.text.substr(0, offset); | layout.text = layout.text.substr(0, offset); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (params.output_is_required("Line")) { | if (params.add_data_referenced_by_output("Line")) { | ||||
| layout.line_numbers.reinitialize(layout.positions.size()); | layout.line_numbers.reinitialize(layout.positions.size()); | ||||
| for (const int i : layout.positions.index_range()) { | for (const int i : layout.positions.index_range()) { | ||||
| CharTrans &ct = chartransdata[i]; | CharTrans &ct = chartransdata[i]; | ||||
| layout.line_numbers[i] = ct.linenr; | layout.line_numbers[i] = ct.linenr; | ||||
| } | } | ||||
| } | } | ||||
| /* Convert UTF-8 encoded string to UTF-32. */ | /* Convert UTF-8 encoded string to UTF-32. */ | ||||
| Show All 12 Lines | |||||
| /* Returns a mapping of UTF-32 character code to instance handle. */ | /* Returns a mapping of UTF-32 character code to instance handle. */ | ||||
| static Map<int, int> create_curve_instances(GeoNodeExecParams ¶ms, | static Map<int, int> create_curve_instances(GeoNodeExecParams ¶ms, | ||||
| TextLayout &layout, | TextLayout &layout, | ||||
| bke::Instances &instances) | bke::Instances &instances) | ||||
| { | { | ||||
| VFont *vfont = reinterpret_cast<VFont *>(params.node().id); | VFont *vfont = reinterpret_cast<VFont *>(params.node().id); | ||||
| Map<int, int> handles; | Map<int, int> handles; | ||||
| bool pivot_required = params.output_is_required("Pivot Point"); | bool pivot_required = params.add_data_referenced_by_output("Pivot Point"); | ||||
| for (int i : layout.char_codes.index_range()) { | for (int i : layout.char_codes.index_range()) { | ||||
| if (handles.contains(layout.char_codes[i])) { | if (handles.contains(layout.char_codes[i])) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| Curve cu = dna::shallow_zero_initialize(); | Curve cu = dna::shallow_zero_initialize(); | ||||
| cu.type = OB_FONT; | cu.type = OB_FONT; | ||||
| cu.resolu = 12; | cu.resolu = 12; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void create_attributes(GeoNodeExecParams ¶ms, | static void create_attributes(GeoNodeExecParams ¶ms, | ||||
| const TextLayout &layout, | const TextLayout &layout, | ||||
| bke::Instances &instances) | bke::Instances &instances) | ||||
| { | { | ||||
| MutableAttributeAccessor attributes = instances.attributes_for_write(); | MutableAttributeAccessor attributes = instances.attributes_for_write(); | ||||
| if (params.output_is_required("Line")) { | if (AutoAnonymousAttributeID line_id = params.get_output_anonymous_attribute_id_if_needed( | ||||
| StrongAnonymousAttributeID line_id = StrongAnonymousAttributeID("Line"); | "Line")) { | ||||
| SpanAttributeWriter<int> line_attribute = attributes.lookup_or_add_for_write_only_span<int>( | SpanAttributeWriter<int> line_attribute = attributes.lookup_or_add_for_write_only_span<int>( | ||||
| line_id.get(), ATTR_DOMAIN_INSTANCE); | *line_id, ATTR_DOMAIN_INSTANCE); | ||||
| line_attribute.span.copy_from(layout.line_numbers); | line_attribute.span.copy_from(layout.line_numbers); | ||||
| line_attribute.finish(); | line_attribute.finish(); | ||||
| params.set_output("Line", | params.set_output("Line", | ||||
| AnonymousAttributeFieldInput::Create<int>(std::move(line_id), | AnonymousAttributeFieldInput::Create<int>(std::move(line_id), | ||||
| params.attribute_producer_name())); | params.attribute_producer_name())); | ||||
| } | } | ||||
| if (params.output_is_required("Pivot Point")) { | if (AutoAnonymousAttributeID pivot_id = params.get_output_anonymous_attribute_id_if_needed( | ||||
| StrongAnonymousAttributeID pivot_id = StrongAnonymousAttributeID("Pivot"); | "Pivot Point")) { | ||||
| SpanAttributeWriter<float3> pivot_attribute = | SpanAttributeWriter<float3> pivot_attribute = | ||||
| attributes.lookup_or_add_for_write_only_span<float3>(pivot_id.get(), ATTR_DOMAIN_INSTANCE); | attributes.lookup_or_add_for_write_only_span<float3>(*pivot_id, ATTR_DOMAIN_INSTANCE); | ||||
| for (const int i : layout.char_codes.index_range()) { | for (const int i : layout.char_codes.index_range()) { | ||||
| pivot_attribute.span[i] = layout.pivot_points.lookup(layout.char_codes[i]); | pivot_attribute.span[i] = layout.pivot_points.lookup(layout.char_codes[i]); | ||||
| } | } | ||||
| pivot_attribute.finish(); | pivot_attribute.finish(); | ||||
| params.set_output("Pivot Point", | params.set_output("Pivot Point", | ||||
| AnonymousAttributeFieldInput::Create<float3>( | AnonymousAttributeFieldInput::Create<float3>( | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||