core/node/transformnode
계층적 TRS 객체.
Hierarchical TRS object.
TransformNodeextends ComponentNode
계층적 TRS 객체.
- Transform 기능.
- 렌더링 기능. (컴포넌트 포함)
Hierarchical TRS object.
- Transform features.
- Rendering features. (including components)
import { TransformNode, Vector2 } from "./build/vanilla.js";
const parent = new TransformNode();
parent.setLocalPosition(Vector2.create(100, 50));
parent.setLocalRotation(90);
parent.setLocalScale(Vector2.create(2, 2));
const child = new TransformNode();
child.setLocalPositionXY(10, 0);
child.setLocalOpacity(0.5);
parent.addChild(child);
const position = child.getPosition();
const rotation = child.getRotation();
const scale = child.getScale();
const opacity = child.getOpacity();
console.log(position.x, position.y, rotation, scale.x, opacity);생성.
Constructor.
출력 상태 시작.
Begins the draw state.
- graphicGraphic
- 변환을 걸 그래픽.Graphic to apply the transform to.
로컬 위치, 회전, 크기를 graphic 의 변환에 건다.
- 위치와 크기를 복제하지 않고 읽는다. getLocalPosition() / getLocalScale() 을 덮어쓴 하위 클래스면 그 함수로 읽는다.
Applies the local position, rotation and scale to graphic's transform.
- Reads position and scale without cloning. Subclasses that override getLocalPosition() / getLocalScale() are read through those functions.
- graphicGraphic
- 변환을 걸 그래픽.Graphic to apply the transform to.
자식 목록 출력. (자식 차례대로 Graphic.drawNode, draw 가 부른다)
- 하위 트리 거르기가 켜졌으면 부모 좌표의 보이는 사각형(Graphic.readLocalVisibleBounds)으로 보이는 자식 범위를 이분 찾기로 좁혀 그 앞뒤 자식은 부르지 않는다. 범위는 하위 트리 경계를 셀 때 적어 둔 자식 경계(앞에서부터 모은 가장 큰 아래와 오른쪽, 뒤에서부터 모은 가장 작은 위와 왼쪽)로 찾으므로 자식이 어떤 차례로 놓여도 맞고, 줄처럼 차례대로 놓이면 보이는 줄만 남는다. 경계를 모르는 자식이 있으면 그 자식을 넘어 좁히지 않는다. 그리기 차례는 그대로다.
- 그리는 동안 이 노드의 경계가 바뀌면(자식이 형제를 옮김 같은) 남은 자식을 모두 부른다.
- 이 노드가 보이는 사각형 안에 다 든 하위 트리를 그리는 중이면(Graphic.isInsideVisibleBounds) 좁히지 않고 모두 부른다. (자식도 모두 보이는 사각형 안이다)
Draws the children. (Graphic.drawNode for each child in order; called by draw)
- While subtree culling is on, the visible range of children is narrowed by binary search against the visible rectangle in parent coordinates (Graphic.readLocalVisibleBounds), and the children before and after it are not called. The range is found from the children's bounds written when the subtree bounds were calculated (the largest bottom and right gathered from the front, the smallest top and left gathered from the back), so it is correct in any child order, and when children are laid out in order like rows only the visible rows remain. A child with unknown bounds stops the narrowing past it. Drawing order is unchanged.
- If this node's bounds change while drawing (such as a child moving a sibling), all remaining children are called.
- While this node is drawing a subtree that lies fully inside the visible rectangle (Graphic.isInsideVisibleBounds), the range is not narrowed and all children are called. (The children are all inside the visible rectangle too)
- graphicGraphic
- 그릴 그래픽.Graphic to draw with.
짝Counterpart: vanilla-engine NodeTree.draw_children
import { Engine, EngineConfiguration, Scene, WorldNode, Paint, Colors, Rect, Vector2, Pivot } from "./build/vanilla.js";
class FrameNode extends WorldNode {
draw(graphic) {
graphic.setFillColor(Colors.white);
graphic.drawRect(Rect.create(0, 0, 20, 20));
this.drawChildren(graphic);
}
calculateDrawnRect(rect) {
rect.position.set(0, 0);
rect.size.set(20, 20);
return true;
}
}
class MainScene extends Scene {
initialize(engine) {
super.initialize(engine);
const frameNode = new FrameNode();
frameNode.setPivot(Pivot.topLeft);
this.getRoot().addChild(frameNode);
const childNode = new WorldNode();
childNode.setPivot(Pivot.topLeft);
childNode.setRect(30, 0, 20, 20);
childNode.addComponent(Paint);
frameNode.addChild(childNode);
}
draw(graphic) {
super.draw(graphic);
console.log(graphic.getLastFrameCulledSubtreeCount());
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());출력 상태 종료.
Ends the draw state.
- graphicGraphic
- 상태를 되돌릴 그래픽.Graphic whose state is restored.
짝Counterpart: vanilla-engine WorldNode.pop_transform
글로벌 위치 설정.
Sets the global position.
- positionVector2
- 부모들을 거친 월드 자리. (부모의 위치, 회전, 크기를 거꾸로 걸어 로컬 위치로 바꾼다)World position through the parents. (converted to the local position by reversing the parents' position, rotation and scale)
글로벌 위치 반환.
Returns the global position.
반환ReturnsVector2 부모들을 거친 월드 자리. (부모가 없으면 로컬 위치)World position through the parents. (the local position if there is no parent)
글로벌 위치를 주어진 벡터에 쓰기. (getPosition 과 같은 값, 새 벡터를 짓지 않는다)
- getPosition 이나 부모의 위치, 회전, 크기 읽기를 덮어쓴 하위 클래스면 그 함수로 읽는다. (그때는 그 함수가 짓는 만큼 할당한다)
Writes the global position into a given vector. (Same value as getPosition, no new vector)
- Subclasses that override getPosition or the parent's position, rotation or scale readers are read through those functions. (Then it allocates as much as they do)
- outVector2
- 쓸 벡터.Vector to write.
반환ReturnsVector2 out.
import { TransformNode, Vector2 } from "./vanilla.js";
const parentNode = new TransformNode();
parentNode.setLocalPosition(Vector2.create(10, 20));
const childNode = new TransformNode();
childNode.setParent(parentNode);
childNode.setLocalPosition(Vector2.create(5, 0));
const position = Vector2.create(0, 0);
childNode.readPosition(position);
if (position.x !== 15 || position.y !== 20) {
throw new Error("position failed");
}글로벌 크기를 주어진 벡터에 쓰기. (getScale 과 같은 값, 새 벡터를 짓지 않는다)
- getScale 이나 getLocalScale 을 덮어쓴 하위 클래스면 그 함수로 읽는다.
Writes the global scale into a given vector. (Same value as getScale, no new vector)
- Subclasses that override getScale or getLocalScale are read through those functions.
- outVector2
- 쓸 벡터.Vector to write.
반환ReturnsVector2 out.
짝Counterpart: vanilla-engine NodeTree.read_scale
import { TransformNode, Vector2 } from "./vanilla.js";
const parentNode = new TransformNode();
parentNode.setLocalScale(Vector2.create(2, 2));
const childNode = new TransformNode();
childNode.setParent(parentNode);
childNode.setLocalScale(Vector2.create(0.5, 3));
const scale = Vector2.create(0, 0);
childNode.readScale(scale);
if (scale.x !== 1 || scale.y !== 6) {
throw new Error("scale failed");
}로컬 위치를 주어진 벡터에 쓰기. (getLocalPosition 과 같은 값, 복제하지 않는다)
Writes the local position into a given vector. (Same value as getLocalPosition, no clone)
- outVector2
- 쓸 벡터.Vector to write.
반환ReturnsVector2 out.
짝Counterpart: vanilla-engine WorldNode.read_local_position
import { TransformNode, Vector2 } from "./vanilla.js";
const node = new TransformNode();
node.setLocalPositionXY(3, 4);
const position = node.readLocalPosition(Vector2.create(0, 0));
if (position.x !== 3 || position.y !== 4) {
throw new Error("local position failed");
}로컬 크기를 주어진 벡터에 쓰기. (getLocalScale 과 같은 값, 복제하지 않는다)
Writes the local scale into a given vector. (Same value as getLocalScale, no clone)
- outVector2
- 쓸 벡터.Vector to write.
반환ReturnsVector2 out.
짝Counterpart: vanilla-engine WorldNode.read_local_scale
import { TransformNode, Vector2 } from "./vanilla.js";
const node = new TransformNode();
node.setLocalScaleXY(2, 0.5);
const scale = node.readLocalScale(Vector2.create(0, 0));
if (scale.x !== 2 || scale.y !== 0.5) {
throw new Error("local scale failed");
}글로벌 크기 설정.
Sets the global scale.
- scaleVector2
- 부모들을 거친 크기 배율. (부모 배율로 나눠 로컬 크기로 바꾸고, 부모 배율이 0 인 축은 0)Scale through the parents. (divided by the parent scale into the local scale; 0 on axes where the parent scale is 0)
짝Counterpart: vanilla-engine NodeTree.set_scale
글로벌 크기 반환.
Returns the global scale.
반환ReturnsVector2 부모들을 거친 크기 배율.Scale through the parents.
짝Counterpart: vanilla-engine NodeTree.get_scale
글로벌 회전 설정.
Sets the global rotation.
- rotationnumber
- 부모들을 거친 회전. (도)Rotation through the parents. (degrees)
짝Counterpart: vanilla-engine NodeTree.set_rotation
글로벌 회전 반환.
Returns the global rotation.
반환Returnsnumber 부모들을 거친 회전. (도)Rotation through the parents. (degrees)
짝Counterpart: vanilla-engine NodeTree.get_rotation
로컬 위치 설정.
Sets the local position.
- positionVector2
- 부모 기준 자리. (값을 옮겨 적고 받은 벡터는 들고 있지 않는다)Position relative to the parent. (values are copied; the given vector is not kept)
짝Counterpart: vanilla-engine WorldNode.set_local_position
로컬 위치 설정. (x, y 를 바로 받는다, Vector2 를 만들지 않는다)
- getLocalPosition() / setLocalPosition() 을 덮어쓴 하위 클래스면 setLocalPosition 으로 넘긴다.
Sets the local position. (takes x, y directly, does not create a Vector2)
- Subclasses that override getLocalPosition() / setLocalPosition() are forwarded to setLocalPosition.
- xnumber
- 부모 기준 X.X relative to the parent.
- ynumber
- 부모 기준 Y.Y relative to the parent.
짝Counterpart: vanilla-engine WorldNode.set_local_position_xy
로컬 위치 반환.
Returns the local position.
반환ReturnsVector2 로컬 위치의 사본.A copy of the local position.
짝Counterpart: vanilla-engine WorldNode.get_local_position
로컬 크기 설정.
Sets the local scale.
- scaleVector2
- 로컬 크기 배율. (값을 옮겨 적는다)Local scale. (values are copied)
짝Counterpart: vanilla-engine WorldNode.set_local_scale
로컬 크기 설정. (x, y 를 바로 받는다, Vector2 를 만들지 않는다)
- setLocalScale() 을 덮어쓴 하위 클래스면 setLocalScale 로 넘긴다.
Sets the local scale. (takes x, y directly, does not create a Vector2)
- Subclasses that override setLocalScale() are forwarded to setLocalScale.
- xnumber
- 로컬 가로 배율.Local horizontal scale.
- ynumber
- 로컬 세로 배율.Local vertical scale.
짝Counterpart: vanilla-engine WorldNode.set_local_scale_xy
로컬 크기 반환.
Returns the local scale.
반환ReturnsVector2 로컬 크기의 사본.A copy of the local scale.
짝Counterpart: vanilla-engine WorldNode.get_local_scale
로컬 회전 설정.
Sets the local rotation.
- rotationnumber
- 로컬 회전. (도)Local rotation. (degrees)
짝Counterpart: vanilla-engine WorldNode.set_local_rotation
로컬 회전 반환.
Returns the local rotation.
반환Returnsnumber 로컬 회전. (도)Local rotation. (degrees)
짝Counterpart: vanilla-engine WorldNode.get_local_rotation
보이기 설정. (켜짐, 투명도와 따로 두는 플래그, 러스트 판 WorldNode::set_visible 과 같다)
- 거짓이면 이 노드와 자손을 그리지 않고 TouchRaycaster 의 누름도 받지 않는다. 갱신(tick)은 그대로 돈다.
Sets visibility. (A flag kept separate from active and opacity, the same as the Rust edition's WorldNode::set_visible)
- If false, this node and its descendants are not drawn and do not receive TouchRaycaster presses. Updates (tick) still run.
- isVisibleboolean
- 거짓이면 숨긴다. (기본 참)Hides the node if false. (default true)
짝Counterpart: vanilla-engine WorldNode.set_visible
import { WorldNode } from "./build/vanilla.js";
const parentNode = new WorldNode();
const childNode = new WorldNode();
parentNode.addChild(childNode);
parentNode.setVisible(false);
console.log(parentNode.isVisible(), parentNode.isActive(), childNode.isVisible(), childNode.isVisibleInHierarchy());보이기 플래그 반환. (setVisible 로 정한 값, 켜짐과 투명도는 보지 않는다, 계층 판정은 isVisibleInHierarchy)
Returns the visibility flag. (The value set with setVisible, active and opacity are not considered, use isVisibleInHierarchy for the hierarchy)
반환Returnsboolean 보이기 플래그. (기본 참)Visibility flag. (default true)
짝Counterpart: vanilla-engine WorldNode.is_visible
현재부터 루트까지 계층 전체의 가시 상태 반환. (자신과 조상 모두 켜져 있고, 보이기 플래그가 참이고, 로컬 투명도가 0 보다 커야 참)
Returns the visibility of the whole hierarchy from this node to the root. (True only if this node and all ancestors are active, have the visibility flag set, and have local opacity above 0)
반환Returnsboolean 자신과 모든 부모가 보이면 참.True if itself and all parents are visible.
짝Counterpart: vanilla-engine NodeTree.is_visible_in_hierarchy
import { WorldNode } from "./build/vanilla.js";
const parentNode = new WorldNode();
const childNode = new WorldNode();
parentNode.addChild(childNode);
parentNode.setLocalOpacity(0);
console.log(childNode.isActiveInHierarchy(), childNode.isVisibleInHierarchy());
parentNode.setLocalOpacity(1);
childNode.setVisible(false);
console.log(parentNode.isVisibleInHierarchy(), childNode.isVisibleInHierarchy());글로벌 투명도 반환.
Returns the global alpha.
반환Returnsnumber 부모들의 투명도를 곱한 투명도. (0 ~ 1)Opacity multiplied by the parents' opacity. (0 ~ 1)
짝Counterpart: vanilla-engine NodeTree.get_opacity
로컬 투명도 설정.
Sets the local alpha.
- opacitynumber
- 로컬 투명도. (0 ~ 1 로 자른다)Local opacity. (clamped to 0 ~ 1)
짝Counterpart: vanilla-engine WorldNode.set_local_opacity
로컬 투명도 반환.
Returns the local alpha.
반환Returnsnumber 로컬 투명도. (0 ~ 1)Local opacity. (0 ~ 1)
짝Counterpart: vanilla-engine WorldNode.get_local_opacity
지난번 그릴 때 변환의 가장 큰 배율과 그 프레임 번호 설정. (Graphic.drawNode 가 부른다)
Sets the largest scale of the transform when last drawn and that frame number. (called by Graphic.drawNode)
- maximumScalenumber
- 변환의 가장 큰 배율.The largest scale of the transform.
- frameNumbernumber
- 그린 프레임 번호. (Graphic 이 프레임마다 하나씩 올리는 번호, 기본 0)The frame number it was drawn in. (a number Graphic raises by one each frame, default 0)
짝Counterpart: vanilla-engine WorldNode.set_last_drawn_maximum_scale
지난번 그린 프레임 번호 반환. (setLastDrawnMaximumScale 로 적은 번호, -1 이면 그린 적 없다)
Returns the frame number when last drawn. (the number written by setLastDrawnMaximumScale, -1 if never drawn)
반환Returnsnumber 지난번 그린 프레임 번호.The frame number when last drawn.
짝Counterpart: vanilla-engine WorldNode.get_last_drawn_frame_number
지난번 그릴 때 변환의 가장 큰 배율 반환. (0 이면 아직 모른다)
Returns the largest scale of the transform at the last draw. (0 means not known yet)
반환Returnsnumber 변환의 가장 큰 배율. (0 이면 아직 모른다)The largest scale of the transform. (0 if not yet known)
짝Counterpart: vanilla-engine WorldNode.get_last_drawn_maximum_scale
기즈모 그리기 여부 설정.
Sets whether gizmos are drawn.
- isVisibleboolean
- 참이면 기즈모를 그린다.If true, gizmos are drawn.
짝Counterpart: vanilla-engine WorldNode.set_gizmo_visible
기즈모 그리기 여부 반환.
Returns whether gizmos are drawn.
반환Returnsboolean 기즈모를 그리면 참.True if gizmos are drawn.
짝Counterpart: vanilla-engine WorldNode.is_gizmo_visible
투명도 층 설정. (CSS opacity 처럼 투명도를 노드와 자손에 묶어 한 번에 얹을지)
- 켜고 투명도(부모의 것을 곱한 값)가 1 보다 작으면 이 노드와 자손을 층에 모아 그렸다가 그 투명도로 한 번에 얹는다. (Graphic.beginOpacityLayer) 겹친 자식끼리 비치지 않는다. 끄면(처음) 노드마다 투명도를 곱해 따로 얹는다.
Sets the opacity layer. (Whether to group the opacity over the node and its descendants and lay it down at once, like CSS opacity)
- When on and the opacity (multiplied by the parent's) is below 1, this node and its descendants are drawn into a layer and laid down at once with that opacity. (Graphic.beginOpacityLayer) Overlapping children do not show through each other. When off (the default), opacity is multiplied per node and each is laid down separately.
- isOpacityLayerboolean
- 투명도를 묶어 얹을지.Whether to lay the opacity down as a group.
짝Counterpart: vanilla-engine WorldNode.set_opacity_layer
import { WorldNode } from "./build/vanilla.js";
const groupNode = new WorldNode();
groupNode.setLocalOpacity(0.5);
groupNode.setOpacityLayer(true);
console.log(groupNode.isOpacityLayer());투명도 층 여부 반환.
Returns whether the node is an opacity layer.
반환Returnsboolean 투명도를 노드와 자손에 묶어 얹으면 참.True if the opacity is grouped over the node and its descendants.
짝Counterpart: vanilla-engine WorldNode.is_opacity_layer
부모 설정. (오버라이드: 옛 부모와 새 부모의 하위 트리 그리기 경계가 바뀐다)
Sets the parent. (override: the subtree draw bounds of the old and the new parent change)
- parentNode | null
- 새 부모. (null 이면 떼어 낸다)The new parent. (null detaches)
반환Returnsboolean 붙였거나 떼었으면 참. (자기 자손을 부모로 주면 거짓)True if attached or detached. (false if a descendant of itself is given as the parent)
짝Counterpart: vanilla-engine NodeTree.set_parent
켜짐 설정. (오버라이드: 꺼진 자식은 부모의 하위 트리 그리기 경계에 들지 않는다)
Sets the active state. (override: an inactive child is not part of the parent's subtree draw bounds)
- activeboolean
- 켤지.Whether to enable it.
짝Counterpart: vanilla-engine WorldNode.set_active
하위 트리 그리기 경계가 바뀌었음을 표시. (이 노드와 조상이 다음에 그릴 때 경계를 다시 셈한다)
- 변환, 내용 크기, 자식 더함과 뺌, 켜짐과 보임, 컴포넌트가 바뀌면 엔진이 부른다. 조상으로 번지다 이미 표시된 노드에서 멈춘다.
- draw 를 덮어쓴 노드는 calculateDrawnRect 가 알리는 사각형이 바뀔 때 부른다.
Marks that the subtree draw bounds changed. (this node and its ancestors recalculate the bounds the next time they draw)
- The engine calls it when a transform, content size, added or removed child, active state, visibility or component changes. Spreading to ancestors stops at a node that is already marked.
- A node that overrides draw calls it when the rectangle reported by calculateDrawnRect changes.
짝Counterpart: vanilla-engine WorldNode.mark_draw_bounds_dirty
import { WorldNode, Rect, Colors } from "./build/vanilla.js";
class Ripple extends WorldNode {
radius = 10;
setRadius(radius) {
this.radius = radius;
this.markDrawBoundsDirty();
}
draw(graphic) {
super.draw(graphic);
graphic.setFillColor(Colors.white);
graphic.drawRect(Rect.create(-this.radius, -this.radius, this.radius * 2, this.radius * 2));
}
calculateDrawnRect(rect) {
rect.position.set(-this.radius, -this.radius);
rect.size.set(this.radius * 2, this.radius * 2);
return true;
}
}
const ripple = new Ripple();
ripple.setRadius(40);
const drawBounds = Rect.zero();
console.log(ripple.readSubtreeDrawBounds(drawBounds), drawBounds.size.x);부모의 하위 트리 그리기 경계가 바뀌었음을 표시. (이 노드의 변환, 켜짐, 보임이 바뀌면 이 노드의 경계는 그대로이고 부모의 경계가 바뀐다)
Marks that the parent's subtree draw bounds changed. (when this node's transform, active state or visibility changes, this node's bounds stay the same and the parent's bounds change)
짝Counterpart: vanilla-engine WorldNode.mark_parent_draw_bounds_dirty
하위 트리 그리기 경계 읽기. (이 노드의 내용 좌표, pushTransform 을 건 뒤의 좌표, 알면 true)
- 이 노드와 켜지고 보이는 자손이 그리는 곳을 모두 품는 사각형이다. 크기가 0 이면 아무것도 그리지 않는다.
- 바뀐 때만 다시 셈하고(calculateSubtreeDrawBounds) 그 밖에는 셈해 둔 것을 준다. 그리기 순회가 이 사각형이 화면과 자르기 밖이면 하위 트리를 통째로 건너뛴다.
- 어디에 그리는지 모르는 것(경계를 알리지 않는 컴포넌트, draw 를 덮어쓰고 calculateDrawnRect 를 알리지 않는 노드)이 들면 false.
Reads the subtree draw bounds. (in this node's content coordinates, the coordinates after pushTransform, true if known)
- A rectangle that covers everything drawn by this node and its active, visible descendants. A size of 0 means nothing is drawn.
- Recalculated only when something changed (calculateSubtreeDrawBounds), otherwise the stored bounds are returned. The draw traversal skips the whole subtree when this rectangle is outside the screen and the clips.
- False if something whose drawing area is unknown is included (a component that does not report its bounds, a node that overrides draw without reporting calculateDrawnRect).
- rectRect
- 경계를 적을 곳.Where to write the bounds.
반환Returnsboolean 경계를 알면 참. (모르면 rect 를 건드리지 않는다)True if the bounds are known. (rect is left untouched if unknown)
짝Counterpart: vanilla-engine NodeTree.read_subtree_draw_bounds
import { WorldNode, Paint, Rect, Vector2, Pivot } from "./build/vanilla.js";
const rowNode = new WorldNode();
rowNode.setPivot(Pivot.topLeft);
rowNode.setContentSize(Vector2.create(300, 40));
rowNode.addComponent(Paint);
const iconNode = new WorldNode();
iconNode.setPivot(Pivot.topLeft);
iconNode.setRect(-20, 4, 32, 32);
iconNode.addComponent(Paint);
rowNode.addChild(iconNode);
const drawBounds = Rect.zero();
const isKnown = rowNode.readSubtreeDrawBounds(drawBounds);
console.log(isKnown, drawBounds.position.x, drawBounds.size.x);부모가 셈해 둔 이 노드의 하위 트리 그리기 경계 읽기. (부모의 내용 좌표, 이 노드의 변환을 건 경계 상자, 맞으면 true)
- 부모가 하위 트리 경계를 셈할 때(calculateSubtreeDrawBounds) 자식마다 옮겨 적어 둔 것이다. 이 노드의 변환이나 경계가 바뀌면 부모가 다시 셈하므로 그때까지 그대로 쓴다.
- 그리기 순회가 부모의 변환 아래에서 이 사각형을 먼저 보아, 부모 좌표의 보이는 사각형 밖이면 이 노드에 변환을 걸지 않고 건너뛴다. (스크롤은 부모의 변환만 바뀌므로 자식마다 다시 셈하지 않는다)
- 부모가 아직 셈하지 않았거나 셈한 뒤 바뀌었으면(다시 셈할 차례), 이 노드가 어디에 그리는지 모르거나 놓이는 곳을 모르면 false.
Reads this node's subtree draw bounds as calculated by the parent. (In the parent's content coordinates, the bounding box with this node's transform applied; true if valid)
- The parent writes these for each child when it calculates its subtree bounds (calculateSubtreeDrawBounds). When this node's transform or bounds change the parent recalculates, so they are reused until then.
- The draw traversal checks this rectangle first under the parent's transform and skips this node without applying its transform when it lies outside the visible rectangle in parent coordinates. (Scrolling changes only the parent's transform, so children are not recalculated one by one)
- False if the parent has not calculated yet or something changed since (a recalculation is due), or if where this node draws or where it is placed is unknown.
- rectRect
- 경계를 적을 곳. (부모의 내용 좌표, 크기가 0 이면 아무것도 그리지 않는다)Where to write the bounds. (In the parent's content coordinates; a size of 0 means nothing is drawn)
반환Returnsboolean 맞는 경계가 있으면 참. (없으면 rect 를 건드리지 않는다)True if valid bounds exist. (Otherwise rect is left untouched)
짝Counterpart: vanilla-engine NodeTree.read_parent_draw_bounds
import { WorldNode, Paint, Rect, Vector2, Pivot } from "./build/vanilla.js";
const listNode = new WorldNode();
listNode.setPivot(Pivot.topLeft);
const rowNode = new WorldNode();
rowNode.setPivot(Pivot.topLeft);
rowNode.setRect(0, 120, 300, 40);
rowNode.addComponent(Paint);
listNode.addChild(rowNode);
const drawBounds = Rect.zero();
console.log(rowNode.readParentDrawBounds(drawBounds));
listNode.readSubtreeDrawBounds(drawBounds);
console.log(rowNode.readParentDrawBounds(drawBounds), drawBounds.position.y, drawBounds.size.y);노드 스스로(컴포넌트와 자식 밖에) 그리는 사각형을 rect 에 적기. (내용 영역의 왼쪽 위가 원점, 알면 true)
- draw 를 덮어쓰지 않은 노드는 스스로 그리는 것이 없으므로 크기 0 을 적고 true.
- draw 를 덮어쓴 노드는 어디에 그리는지 모르므로 false. (그 노드의 조상은 하위 트리 그리기를 건너뛰지 않는다) 덮어쓴 노드가 이 함수도 덮어써 그리는 사각형을 알리면 건너뛸 수 있다. 사각형이 바뀌면 markDrawBoundsDirty 를 부른다.
Writes into rect the rectangle the node draws by itself (outside its components and children). (origin at the top-left of the content area, true if known)
- A node that does not override draw draws nothing by itself, so it writes size 0 and returns true.
- A node that overrides draw does not know where it draws and returns false. (its ancestors do not skip the subtree drawing) If the overriding node also overrides this function to report the drawn rectangle it can be skipped. Call markDrawBoundsDirty when the rectangle changes.
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 알면 참.True if known.
import { TransformNode, Rect } from "./build/vanilla.js";
const node = new TransformNode();
const drawnRect = Rect.zero();
console.log(node.calculateDrawnRect(drawnRect), drawnRect.size.x);하위 트리 그리기 경계를 부모의 내용 좌표로 옮기기. (알면 true, calculateSubtreeDrawBounds 가 자식마다 부른다)
- TransformNode 는 내용 영역과 피봇이 없어 어디에 놓이는지 정하지 않으므로 false. (WorldNode, UINode 가 저마다 놓는 꼴로 덮어쓴다)
Moves subtree draw bounds into the parent's content coordinates. (True if known; calculateSubtreeDrawBounds calls it for each child)
- TransformNode has no content area or pivot and does not define its placement, so it returns false. (WorldNode and UINode override it with their own placement)
- rectRect
- 옮길 경계. (이 노드의 내용 좌표, 부모의 내용 좌표로 바뀐 경계 상자를 적는다)The bounds to move. (In this node's content coordinates; the bounding box in the parent's content coordinates is written back)
반환Returnsboolean 놓이는 곳을 알면 참.True if where the node is placed is known.
import { TransformNode, Rect } from "./build/vanilla.js";
const node = new TransformNode();
console.log(node.transformDrawBoundsToParent(Rect.create(0, 0, 10, 10)));사각형을 이 노드의 회전과 배율로 돌리고 키워 부모 좌표에 옮긴 경계 상자로 바꾸기. (transformDrawBoundsToParent 가 쓴다)
- 차례: 기준점만큼 당김 → 배율 → 회전 → 옮김. (pushTransform 의 옮김, 회전, 배율과 같은 결과)
Turns a rectangle into the bounding box after this node's rotation and scale and the move into parent coordinates. (Used by transformDrawBoundsToParent)
- Order: subtract the pivot → scale → rotate → translate. (Same result as pushTransform's translate, rotate, scale)
- rectRect
- 바꿀 사각형. (이 노드의 내용 좌표, 바뀐 경계 상자를 적는다)The rectangle to transform. (In this node's content coordinates; the transformed bounding box is written back)
- pivotOffsetXnumber
- 기준점의 가로 자리. (내용 좌표, 이만큼 당긴 뒤 키운다)Horizontal pivot position. (Content coordinates; subtracted before scaling)
- pivotOffsetYnumber
- 기준점의 세로 자리.Vertical pivot position.
- translateXnumber
- 부모 좌표로 옮기는 가로 거리.Horizontal distance to move into parent coordinates.
- translateYnumber
- 부모 좌표로 옮기는 세로 거리.Vertical distance to move into parent coordinates.
import { TransformNode, Rect, Vector2 } from "./build/vanilla.js";
const node = new TransformNode();
node.setLocalScale(Vector2.create(2, 2));
const rect = Rect.create(0, 0, 10, 10);
node.transformLocalRectToParent(rect, 5, 5, 100, 0);
console.log(rect.position.x, rect.size.x);하위 트리 그리기 경계 셈하기. (자기 그림과 켜지고 보이는 자식들 경계의 합, readSubtreeDrawBounds 가 바뀐 때만 부른다, 알면 true)
- 자기 그림: calculateDrawnRect 와 켜진 컴포넌트. 내용 영역 안에서만 그리는 컴포넌트(Component.isDrawnInsideContent)는 내용 영역을 한 단위씩 넓혀 보고, 밖까지 그리는 컴포넌트는 Component.calculateDrawnRect 로 본다. 그리지 않는 컴포넌트(draw 를 덮어쓰지 않은 것)는 빼고, 모르는 컴포넌트가 하나라도 있으면 모른다. 기즈모를 그리는 노드와 내용 크기를 읽을 수 없는 노드(내용 영역 안 컴포넌트가 있을 때)도 모른다.
- 자식: 자식의 하위 트리 경계를 자식이 옮긴(transformDrawBoundsToParent) 이 노드의 내용 좌표 경계 상자. 놓이는 곳을 모르는 자식이 있으면 모른다.
- 모르더라도 켜지고 보이는 자식의 경계는 모두 읽는다. (자식이 셈해 두어야 자손이 바뀐 것이 이 노드까지 번진다)
- 부모 좌표로 옮긴 자식의 경계는 자식에 적어 둔다. (readParentDrawBounds, 그리기 순회가 자식에 변환을 걸기 전에 본다, 이 노드가 다시 셈할 때까지 맞다)
- 마스크로 자식을 잘라도 경계는 줄이지 않는다. (넉넉하게 본다)
Calculates subtree draw bounds. (The union of the node's own drawing and its enabled, visible children's bounds; readSubtreeDrawBounds calls it only after a change; true if known)
- Own drawing: calculateDrawnRect and enabled components. Components drawing only inside the content area (Component.isDrawnInsideContent) count as the content area grown by one unit, components drawing outside use Component.calculateDrawnRect. Components that draw nothing (no draw override) are skipped; a single unknown component makes the bounds unknown. A node drawing gizmos, or one whose content size cannot be read (when it has inside-content components), is also unknown.
- Children: each child's subtree bounds moved by the child (transformDrawBoundsToParent) into this node's content coordinates. A child with unknown placement makes the bounds unknown.
- Even when unknown, all enabled and visible children's bounds are read. (Children must cache theirs so descendant changes propagate up to this node)
- Each child's bounds moved into parent coordinates are written onto the child. (readParentDrawBounds, which the draw traversal checks before applying the child's transform, valid until this node recalculates)
- Bounds are not shrunk by masks clipping children. (Kept generous)
- rectRect
- 셈한 경계를 적을 곳. (이 노드의 내용 좌표)Where to write the calculated bounds. (in this node's content coordinates)
반환Returnsboolean 경계를 알면 참.True if the bounds are known.