10using System.Collections;
11using System.Collections.Generic;
24 this.center = localBox.
center;
25 this.radii = localBox.
radii;
26 this.transform =
null;
27 this.overrideMatrix =
null;
32 this.transform = withTransform;
38 if (transformSource !=
null) { this.transform = transformSource.transform; }
39 else { this.transform =
null; }
40 this.overrideMatrix =
null;
46 this(Vector3.zero,
radii, transformSource) { }
48 public Box(
float radius) : this(Vector3.one * radius) { }
51 this(Vector3.one * radius, transformSource) { }
64 return Matrix4x4.Translate(
center);
70 private Vector3 corner000 {
73 private Vector3 corner100 {
74 get {
return matrix.MultiplyPoint3x4(
new Vector3(
110 public Vector3
Sample(Vector3 coords01) {
111 var coordsN1to1 = coords01.CompWise(f => Mathf.Clamp01(f) * 2 - 1);
112 return matrix.MultiplyPoint3x4(this.radii.CompMul(coordsN1to1));
115 public void DrawLines(System.Action<Vector3, Vector3> drawLineFunc,
118 divisions = Mathf.Max(1, divisions);
119 var frac = 1f / divisions;
121 drawDividedLines(draw: drawLineFunc, step: frac, a: corner000, b: corner100);
122 drawDividedLines(draw: drawLineFunc, step: frac, a: corner000, b: corner010);
123 drawDividedLines(draw: drawLineFunc, step: frac, a: corner110, b: corner100);
124 drawDividedLines(draw: drawLineFunc, step: frac, a: corner110, b: corner010);
126 drawDividedLines(draw: drawLineFunc, step: frac, a: corner000, b: corner001);
127 drawDividedLines(draw: drawLineFunc, step: frac, a: corner100, b: corner101);
128 drawDividedLines(draw: drawLineFunc, step: frac, a: corner010, b: corner011);
129 drawDividedLines(draw: drawLineFunc, step: frac, a: corner110, b: corner111);
131 drawDividedLines(draw: drawLineFunc, step: frac, a: corner001, b: corner101);
132 drawDividedLines(draw: drawLineFunc, step: frac, a: corner001, b: corner011);
133 drawDividedLines(draw: drawLineFunc, step: frac, a: corner111, b: corner101);
134 drawDividedLines(draw: drawLineFunc, step: frac, a: corner111, b: corner011);
137 private void drawDividedLines(System.Action<Vector3, Vector3> draw,
138 float step, Vector3 a, Vector3 b)
140 step = Mathf.Max(0.01f, step);
142 for (var t = step; t <= 1f; t += step) {
143 var b_t = Vector3.Lerp(a, b, t);
150 if (color !=
null) { drawer.
color = color.Value; }
163 drawBoxGizmos(drawer, Vector3.zero, Vector3.one);
177 float invDiv = 1f / div;
178 for (
int i = 0; i < div; i++) {
179 for (
int j = 0; j < div; j++) {
180 for (
int k = 0; k < div; k++) {
182 radii * invDiv * 2f);
UnityEngine.Component Component
Simple drawing interface abstraction (intended for debug drawing, not production!) with statically-ac...
void Line(Vector3 a, Vector3 b)
Color color
Calls the setColor delegate.
void DrawWireCube(Vector3 position, Vector3 size)
Draws a wire gizmo cube at the given position with the given size.
void PushMatrix()
Saves the current gizmo matrix to the gizmo matrix stack.
void PopMatrix()
Restores the current gizmo matrix from the gizmo matrix stack.
Matrix4x4 matrix
Sets or gets the matrix used to transform all gizmos.
void DrawCube(Vector3 position, Vector3 size)
Draws a filled gizmo cube at the given position with the given size.
Color color
Sets or gets the color for the gizmos that will be drawn next.
Matrix4x4? overrideMatrix
Box(LocalBox localBox, Transform withTransform)
Vector3 Sample(Vector3 coords01)
Returns the world-space position of the normalized coordinates (X, Y, Z each from 0 to 1) given this ...
void DrawLines(System.Action< Vector3, Vector3 > drawLineFunc, int divisions=0)
Box(Vector3 radii, Component transformSource)
Box(float radius, Component transformSource)
Box(Vector3 center, Vector3 radii, Component transformSource=null)
void DrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
void Draw(Drawer drawer, Color? color=null)
Matrix4x4 matrix
Local-to-world matrix for this Box.