vanilladocs
vanillapunch.com
API / effect/trailrenderer

effect/trailrenderer

트레일 렌더러 컴포넌트.

  • 원본 effect/trailrenderer.js 를 옮긴 것이다. 노드가 지나간 자리를 점으로 기록해 굵기 / 색이 잦아드는 띠로 그린다. (유니티 TrailRenderer 의 2D 대응)
  • 점은 노드의 로컬 위치(부모 좌표)로 기록하고, 그릴 때는 노드 원점 기준 상대 좌표로 바꿔 노드 트랜스폼 아래에서 그린다. (원본과 같다)
  • 세그먼트마다 draw_line 한 번이라 묶어 그리기로 한 드로우 콜에 모인다. (더하기 합성이면 블렌드가 바뀌는 앞뒤로 끊긴다)
  • 사용:
let trail = node.add_component(TrailRenderer::new());
trail.set_time(0.5);
trail.set_width(14.0, 0.0);
trail.set_colors(Color::create(0.4, 0.8, 1.0, 0.9), Color::create(0.4, 0.8, 1.0, 0.0));
  • 원본과 다른 점: 원본은 색을 "rgba(r, g, b, a)" 문자열로 넘겨 RGB 가 0 ~ 255 정수로 반올림된다. 러스트 판도 같은 반올림을 해서 Color 로 넘긴다.

Trail renderer component.

  • A port of the original effect/trailrenderer.js. Records the places a node passed as points and draws them as a band whose width / color fades out. (the 2D counterpart of Unity's TrailRenderer)
  • Points are recorded in the node's local position (parent coordinates), and when drawing they are converted to coordinates relative to the node origin and drawn under the node transform. (same as the original)
  • One draw_line per segment, so batching gathers them into one draw call. (with additive blending it breaks before and after the blend change)
  • Usage:
let trail = node.add_component(TrailRenderer::new());
trail.set_time(0.5);
trail.set_width(14.0, 0.0);
trail.set_colors(Color::create(0.4, 0.8, 1.0, 0.9), Color::create(0.4, 0.8, 1.0, 0.0));
  • Differences from the original: the original passes colors as "rgba(r, g, b, a)" strings, so RGB is rounded to 0 ~ 255 integers. The Rust version does the same rounding and passes a Color.

TrailRendererstruct traits Default, Component

짝Counterpart: vanilla.js TrailRenderer소스source

트레일 렌더러 컴포넌트.

  • tick 마다 노드 로컬 위치를 점으로 찍고, 수명이 지난 점은 지운다. 점이 둘 이상이면 새 점 쪽에서 오래된 점 쪽으로 굵기와 색이 잦아드는 띠를 그린다.

Trail renderer component.

  • Every tick it marks the node local position as a point and removes points past their lifetime. With two or more points, it draws a band whose width and color fade from the new point side to the old point side.
예제Example혜성 노드를 옮기며 점 쌓기Move a comet node and pile up points
use vanilla::{Color, Engine, EngineConfiguration, NodeTree, TrailRenderer, Vector2};

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let comet_id = node_tree.create_child(root_id, "Comet");
let trail = node_tree[comet_id].add_component(TrailRenderer::new());
trail.set_time(0.5);
trail.set_width(14.0, 0.0);
trail.set_colors(Color::create(0.4, 0.8, 1.0, 0.9), Color::create(0.4, 0.8, 1.0, 0.0));
for step in 0..5 {
	node_tree[comet_id].set_local_position(Vector2::create(step as f64 * 20.0, 0.0));
	node_tree.tick(&engine, 0.1);
}
assert_eq!(node_tree[comet_id].get_component::<TrailRenderer>().map(|trail| trail.get_point_count()), Some(5));
Move a comet node and pile up points
생성자constructorpub fn new() -> TrailRenderer#0.3.2 부터since 0.3.2소스source

생성.

Constructor.

반환ReturnsTrailRenderer 점이 없고 수명 0.5 초, 최소 거리 3, 굵기 10 → 0, 흰색 알파 0.9 → 0, 보통 합성, 점 찍기를 켠 트레일.A trail with no points, lifetime 0.5 seconds, minimum distance 3, width 10 → 0, white alpha 0.9 → 0, normal blending, and point marking on.

짝Counterpart: vanilla.js TrailRenderer.constructor

메서드methodpub fn clear(&mut self)#0.3.2 부터since 0.3.2소스source

흔적 지우기.

Clears the trail.

짝Counterpart: vanilla.js TrailRenderer.clear

메서드methodpub fn set_time(&mut self, point_lifetime: f64)#0.3.2 부터since 0.3.2소스source

점이 남는 시간 설정. (초)

Sets how long points remain. (seconds)

point_lifetimef64
점이 남는 시간. (초, 기본 0.5) 나이가 이만큼 된 점은 tick 에서 지운다.How long points remain. (seconds, default 0.5) Points this old are removed in tick.

짝Counterpart: vanilla.js TrailRenderer.setTime

메서드methodpub fn set_min_vertex_distance(&mut self, min_vertex_distance: f64)#0.3.2 부터since 0.3.2소스source

점 사이 최소 거리 설정.

Sets the minimum distance between points.

min_vertex_distancef64
새 점을 찍을 가장 짧은 거리. (부모 좌표, 기본 3) 마지막 점에서 이보다 덜 움직였으면 점을 찍지 않는다.Shortest distance to mark a new point. (parent coordinates, default 3) No point is marked if it moved less than this from the last point.

짝Counterpart: vanilla.js TrailRenderer.setMinVertexDistance

메서드methodpub fn set_width(&mut self, start_width: f64, end_width: f64)#0.3.2 부터since 0.3.2소스source

굵기 설정. (새 점 쪽, 오래된 점 쪽)

Sets the width. (new point side, old point side)

start_widthf64
새 점 쪽 굵기. (노드 좌표, 기본 10)Width on the new point side. (node coordinates, default 10)
end_widthf64
오래된 점 쪽 굵기. (노드 좌표, 기본 0. 그릴 때 0.1 보다 가늘게 하지 않는다)Width on the old point side. (node coordinates, default 0. Never thinner than 0.1 when drawing)

짝Counterpart: vanilla.js TrailRenderer.setWidth

메서드methodpub fn set_colors(&mut self, start_color: impl Into<Color>, end_color: impl Into<Color>)#0.3.2 부터since 0.3.2소스source

색 설정. (새 점 쪽, 오래된 점 쪽)

  • 그릴 때 RGB 는 원본처럼 0 ~ 255 정수로 반올림하고 알파는 그대로 보간한다.

Sets the colors. (new point side, old point side)

  • When drawing, RGB is rounded to 0 ~ 255 integers as in the original, and alpha is interpolated as is.
start_colorimpl Into<Color>
새 점 쪽 색. (Color 나 "#rrggbb" 같은 글, 기본 흰색 알파 0.9)Color on the new point side. (a Color or text like "#rrggbb", default white alpha 0.9)
end_colorimpl Into<Color>
오래된 점 쪽 색. (기본 흰색 알파 0)Color on the old point side. (default white alpha 0)

짝Counterpart: vanilla.js TrailRenderer.setColors

메서드methodpub fn set_additive(&mut self, is_additive: bool)#0.3.2 부터since 0.3.2소스source

더하기 합성 여부 설정. (켜면 lighter)

Sets whether to use additive blending. (lighter when on)

is_additivebool
참이면 띠를 더하기 합성으로 그리고 끝나면 보통 합성으로 되돌린다. (기본 거짓)If true, draws the band with additive blending and restores normal blending afterward. (default false)

짝Counterpart: vanilla.js TrailRenderer.setAdditive

메서드methodpub fn set_emitting(&mut self, is_emitting: bool)#0.3.2 부터since 0.3.2소스source

점 만들기 여부 설정. (거짓이면 새 점을 만들지 않는다. 남은 띠는 잦아든다)

Sets whether to make points. (if false, no new points are made. The remaining band fades out)

is_emittingbool
참이면 tick 마다 점을 찍는다. (기본 참)If true, marks a point every tick. (default true)

짝Counterpart: vanilla.js TrailRenderer.setEmitting

메서드methodpub fn get_point_count(&self) -> usize#0.3.2 부터since 0.3.2소스source

남아 있는 점 수 반환.

Returns the number of remaining points.

반환Returnsusize 수명이 남은 점 수. (둘 이상이어야 띠가 그려진다)Number of points with lifetime left. (at least two are needed to draw the band)

짝Counterpart: vanilla.js TrailRenderer.getPointCount