Files
bioDome/Assets/DomeShift/DomeArchitecture.cs
2026-12-04 18:19:26 -05:00

611 lines
28 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace DomeShift
{
internal sealed class DomeArchitecture
{
private const float Deck = 0.02f;
private const float CorridorHalfWidth = 1.86f;
private const float CornerLimit = 68f;
private readonly Transform shell;
private DomeArchitecture(Transform shell)
{
this.shell = shell;
}
public static DomeArchitecture Create(Transform parent, DomeEnvironment profile)
{
Transform foundation = Group(parent, "Foundation and galleries");
Transform shell = Group(parent, "Glass superstructure");
var builder = new Builder(profile);
builder.BuildFoundation(foundation);
builder.BuildShell(shell);
return new DomeArchitecture(shell);
}
public void SetCutaway(bool cutaway)
{
shell.gameObject.SetActive(!cutaway);
}
private static Transform Group(Transform parent, string name)
{
var node = new GameObject(name);
node.transform.SetParent(parent, false);
return node.transform;
}
private sealed class Builder
{
private readonly DomeEnvironment profile;
private readonly float heightScale;
private readonly int bays;
private readonly Material concrete;
private readonly Material sandstone;
private readonly Material steel;
private readonly Material aluminum;
private readonly Material mullions;
private readonly Material floor;
private readonly Material floorEdge;
private readonly Material amber;
private readonly Material glass;
private static readonly float[,] Eaves =
{
{ 4.70f, 5.05f, 4.60f },
{ 5.10f, 4.95f, 4.75f },
{ 5.75f, 5.10f, 4.90f }
};
public Builder(DomeEnvironment profile)
{
this.profile = profile;
heightScale = profile.RoofHeight / 13f;
bays = Mathf.Clamp(profile.RoofBays, 2, 20);
concrete = Material("Cream concrete", "#AFA998", 0f, 0.16f);
sandstone = Material("Sandstone retaining wall", "#AA8B69", 0f, 0.11f);
steel = Material("Slate steel", "#516566", 0.12f, 0.27f);
aluminum = Material("Warm aluminum frame", "#DDDCC5", 0.22f, 0.33f);
mullions = Material("Light gray mullions", "#ABB7AA", 0.12f, 0.27f);
floor = Material("Gallery concrete", "#AAB2A1", 0f, 0.19f);
floorEdge = Material("Gallery edge", "#D2CFB7", 0f, 0.2f);
amber = Material("Amber wayfinding paint", "#CC9B50", 0f, 0.22f);
if (profile.Glazing)
glass = GlassMaterial();
}
public void BuildFoundation(Transform parent)
{
var retaining = new Geometry();
var slab = new Geometry();
var steelwork = new Geometry();
var walkway = new Geometry();
var edges = new Geometry();
var paint = new Geometry();
Vector2[] outline = Outline(43f, 32f, CornerLimit);
retaining.Prism(Outline(47.6f, 36.8f, 75f), -1.35f, -0.87f);
retaining.Prism(Outline(45.6f, 34.7f, 71.9f), -0.87f, -0.62f);
slab.Prism(outline, -0.62f, -0.07f);
slab.Box(new Vector3(0f, -0.41f, -34.4f), new Vector3(8.4f, 0.68f, 5.3f), Quaternion.identity);
// Continuous gallery decking on both axes, interrupted only at the crossings.
foreach (float x in new[] { -14f, 14f })
Gallery(walkway, edges, paint, new Vector2(x, -31.7f), new Vector2(x, 31.7f));
foreach (float z in new[] { -10.5f, 10.5f })
{
Gallery(walkway, edges, paint, new Vector2(-42.8f, z), new Vector2(-14f - CorridorHalfWidth, z));
Gallery(walkway, edges, paint, new Vector2(-14f + CorridorHalfWidth, z), new Vector2(14f - CorridorHalfWidth, z));
Gallery(walkway, edges, paint, new Vector2(14f + CorridorHalfWidth, z), new Vector2(42.8f, z));
}
Gallery(walkway, edges, paint, new Vector2(0f, -37f), new Vector2(0f, -10.5f - CorridorHalfWidth));
for (int side = 0; side < outline.Length; side++)
{
Vector2 a = outline[side];
Vector2 b = outline[(side + 1) % outline.Length];
if (side == 0)
{
BuildSill(slab, steelwork, a, new Vector2(-4.25f, a.y));
BuildSill(slab, steelwork, new Vector2(4.25f, b.y), b);
}
else
BuildSill(slab, steelwork, a, b);
}
AddEntryBase(slab, steelwork, paint);
foreach (float x in new[] { -39.2f, -14f, 14f, 39.2f })
{
float z = Mathf.Min(31.95f, CornerLimit - Mathf.Abs(x));
slab.Box(new Vector3(x, 0.64f, z), new Vector3(0.85f, 1.45f, 0.74f), Quaternion.identity);
steelwork.Box(new Vector3(x, 1.38f, z), new Vector3(0.98f, 0.13f, 0.86f), Quaternion.identity);
}
retaining.Apply(parent, sandstone, "Stepped desert plinth", profile);
slab.Apply(parent, concrete, "Concrete slab and facade sills", profile);
steelwork.Apply(parent, steel, "Foundation bands", profile);
walkway.Apply(parent, floor, "Crossing galleries", profile);
edges.Apply(parent, floorEdge, "Gallery borders", profile);
paint.Apply(parent, amber, "Service markings", profile);
}
public void BuildShell(Transform parent)
{
var structure = new Geometry();
var detail = new Geometry();
var panes = new Geometry();
var cladding = new Geometry();
// The tall rainforest pyramid is terraced. The adjoining houses use lower hip and ridge roofs.
BuildRoof(structure, detail, panes, -42.9f, -14f, 10.5f, 31.9f, Eaves[2, 0], 13f, 0.16f, 0.08f, true);
BuildRoof(structure, detail, panes, -14f, 14f, 10.5f, 31.9f, Eaves[2, 1], 10.6f, 0.49f, 0.06f);
BuildRoof(structure, detail, panes, 14f, 42.9f, 10.5f, 31.9f, Eaves[2, 2], 9.6f, 0.10f, 0.21f);
BuildRoof(structure, detail, panes, -42.9f, -14f, -10.5f, 10.5f, Eaves[1, 0], 9.4f, 0.58f, 0.045f);
BuildRoof(structure, detail, panes, -14f, 14f, -10.5f, 10.5f, Eaves[1, 1], 10.35f, 0.18f, 0.08f);
BuildRoof(structure, detail, panes, 14f, 42.9f, -10.5f, 10.5f, Eaves[1, 2], 8.55f, 0.56f, 0.05f);
BuildRoof(structure, detail, panes, -42.9f, -14f, -31.9f, -10.5f, Eaves[0, 0], 8.4f, 0.03f, 0.56f);
BuildRoof(structure, detail, panes, -14f, 14f, -31.9f, -10.5f, Eaves[0, 1], 8.85f, 0.06f, 0.48f);
BuildRoof(structure, detail, panes, 14f, 42.9f, -31.9f, -10.5f, Eaves[0, 2], 7.95f, 0.48f, 0.045f);
AddRoofSeams(detail, panes);
AddFacade(structure, detail, panes);
AddEntrySuperstructure(structure, detail, panes, cladding);
cladding.Apply(parent, concrete, "Airlock canopy", profile);
structure.Apply(parent, aluminum, "Spaceframe and columns", profile);
detail.Apply(parent, mullions, "Pane muntins and wall braces", profile);
if (glass != null)
panes.Apply(parent, glass, "Sage glass panels", profile, false);
}
private static void Gallery(Geometry walkway, Geometry edges, Geometry paint, Vector2 start, Vector2 end)
{
Vector2 tangent = (end - start).normalized;
Vector2 side = new Vector2(-tangent.y, tangent.x);
Vector3 a = World(start, Deck);
Vector3 b = World(end, Deck);
walkway.Beam(a, b, CorridorHalfWidth * 2f, 0.08f);
foreach (float sign in new[] { -1f, 1f })
{
Vector2 border = side * ((CorridorHalfWidth - 0.12f) * sign);
edges.Beam(World(start + border, Deck + 0.045f), World(end + border, Deck + 0.045f), 0.09f, 0.035f);
}
float length = Vector2.Distance(start, end);
for (float distance = 1.5f; distance < length - 1.3f; distance += 3.6f)
{
Vector2 center = start + tangent * distance;
paint.Beam(World(center - tangent * 0.54f, Deck + 0.046f), World(center + tangent * 0.54f, Deck + 0.046f),
0.085f, 0.018f);
}
}
private static void BuildSill(Geometry slab, Geometry steelwork, Vector2 start, Vector2 end)
{
slab.Beam(World(start, 0.25f), World(end, 0.25f), 0.53f, 0.62f);
steelwork.Beam(World(start, 0.58f), World(end, 0.58f), 0.56f, 0.10f);
steelwork.Beam(World(start, -0.22f), World(end, -0.22f), 0.58f, 0.09f);
}
private static void AddEntryBase(Geometry slab, Geometry steelwork, Geometry paint)
{
foreach (float sign in new[] { -1f, 1f })
{
float x = 4.12f * sign;
BuildSill(slab, steelwork, new Vector2(x, -37.25f), new Vector2(x, -31.9f));
steelwork.Box(new Vector3(sign * 3.6f, 0.62f, -36.5f), new Vector3(0.42f, 1.25f, 0.42f), Quaternion.identity);
paint.Box(new Vector3(sign * 3.6f, 1.21f, -36.5f), new Vector3(0.44f, 0.17f, 0.44f), Quaternion.identity);
}
for (int i = -3; i <= 3; i++)
{
paint.Box(new Vector3(i * 0.48f, Deck + 0.052f, -36.45f), new Vector3(0.18f, 0.02f, 0.58f),
Quaternion.Euler(0f, -34f, 0f));
}
}
private void BuildRoof(Geometry structure, Geometry detail, Geometry panes, float left, float right, float front,
float back, float eave, float crown, float crownX, float crownZ, bool terraced = false)
{
Vector2[] rim = ClipCorners(new[]
{
new Vector2(left, front), new Vector2(right, front), new Vector2(right, back), new Vector2(left, back)
});
var center = new Vector2((left + right) * 0.5f, (front + back) * 0.5f);
Vector3[] lower = ScaledRing(rim, center, 1f, 1f, eave * heightScale);
Vector3[] upper = ScaledRing(rim, center, crownX, crownZ, crown * heightScale);
if (terraced)
{
float deckHeight = Mathf.Lerp(eave, crown, 0.52f) * heightScale;
Vector3[] shoulder = ScaledRing(rim, center, 0.73f, 0.74f, deckHeight);
Vector3[] step = ScaledRing(rim, center, 0.61f, 0.62f, deckHeight + 0.14f);
AddRoofTier(structure, detail, panes, lower, shoulder, 3);
AddRoofTier(structure, detail, panes, shoulder, step, 1);
AddRoofTier(structure, detail, panes, step, upper, 3);
}
else
AddRoofTier(structure, detail, panes, lower, upper, 4);
if (glass != null)
{
for (int i = 1; i < upper.Length - 1; i++)
panes.Triangle(upper[0], upper[i], upper[i + 1], true);
}
}
private void AddRoofTier(Geometry structure, Geometry detail, Geometry panes, Vector3[] lower, Vector3[] upper, int rows)
{
int count = lower.Length;
for (int side = 0; side < count; side++)
{
int next = (side + 1) % count;
float width = Vector3.Distance(lower[side], lower[next]);
int columns = Mathf.Max(1, Mathf.RoundToInt(bays * width / 28f));
Vector3 bottomLeft = lower[side];
Vector3 bottomRight = lower[next];
Vector3 topLeft = upper[side];
Vector3 topRight = upper[next];
structure.Beam(bottomLeft, topLeft, 0.24f, 0.24f);
structure.Beam(bottomLeft, bottomRight, 0.26f, 0.23f);
structure.Beam(topLeft, topRight, 0.19f, 0.16f);
for (int row = 0; row < rows; row++)
{
float low = (float)row / rows;
float high = (float)(row + 1) / rows;
Vector3 a = Vector3.Lerp(bottomLeft, topLeft, low);
Vector3 b = Vector3.Lerp(bottomRight, topRight, low);
Vector3 c = Vector3.Lerp(bottomRight, topRight, high);
Vector3 d = Vector3.Lerp(bottomLeft, topLeft, high);
if (row > 0)
detail.Beam(a, b, 0.13f, 0.115f);
for (int column = 0; column < columns; column++)
{
float from = (float)column / columns;
float to = (float)(column + 1) / columns;
Vector3 p = Vector3.Lerp(a, b, from);
Vector3 q = Vector3.Lerp(a, b, to);
Vector3 r = Vector3.Lerp(d, c, to);
Vector3 s = Vector3.Lerp(d, c, from);
if (column > 0)
detail.Beam(p, s, 0.105f, 0.102f);
if ((row + column) % 2 == 0)
detail.Beam(p, r, 0.075f, 0.076f);
else
detail.Beam(q, s, 0.075f, 0.076f);
if (glass != null)
panes.Quad(p, q, r, s, true);
}
}
}
}
private void AddFacade(Geometry structure, Geometry detail, Geometry panes)
{
Vector2[] outline = Outline(42.9f, 31.9f, CornerLimit);
for (int side = 0; side < outline.Length; side++)
{
Vector2 start = outline[side];
Vector2 end = outline[(side + 1) % outline.Length];
if (side == 0)
{
Wall(structure, detail, panes, start, new Vector2(-14f, start.y), Eaves[0, 0]);
Wall(structure, detail, panes, new Vector2(-14f, start.y), new Vector2(-4.17f, end.y), Eaves[0, 1]);
Wall(structure, detail, panes, new Vector2(-4.17f, start.y), new Vector2(4.17f, end.y), Eaves[0, 1], 3.95f * heightScale);
Wall(structure, detail, panes, new Vector2(4.17f, start.y), new Vector2(14f, end.y), Eaves[0, 1]);
Wall(structure, detail, panes, new Vector2(14f, start.y), end, Eaves[0, 2]);
}
else if (side == 2 || side == 6)
{
float x = start.x;
float zSign = Mathf.Sign(end.y - start.y);
Vector2 first = new Vector2(x, -10.5f * zSign);
Vector2 second = new Vector2(x, 10.5f * zSign);
int column = side == 2 ? 2 : 0;
int firstRow = side == 2 ? 0 : 2;
Wall(structure, detail, panes, start, first, Eaves[firstRow, column]);
Wall(structure, detail, panes, first, second, Eaves[1, column]);
Wall(structure, detail, panes, second, end, Eaves[2 - firstRow, column]);
}
else if (side == 4)
{
Wall(structure, detail, panes, start, new Vector2(14f, start.y), Eaves[2, 2]);
Wall(structure, detail, panes, new Vector2(14f, start.y), new Vector2(-14f, end.y), Eaves[2, 1]);
Wall(structure, detail, panes, new Vector2(-14f, end.y), end, Eaves[2, 0]);
}
else
{
float doorHeight = Eaves[side == 1 || side == 7 ? 0 : 2, side < 4 ? 2 : 0];
Wall(structure, detail, panes, start, end, doorHeight);
}
}
}
private void AddRoofSeams(Geometry detail, Geometry panes)
{
float[] x = { -42.9f, -14f, 14f, 42.9f };
float[] z = { -31.9f, -10.5f, 10.5f, 31.9f };
for (int row = 0; row < 3; row++)
{
for (int column = 0; column < 3; column++)
{
float eave = Eaves[row, column];
if (column < 2)
Seam(detail, panes, new Vector2(x[column + 1], z[row]), new Vector2(x[column + 1], z[row + 1]), eave, Eaves[row, column + 1]);
if (row < 2)
Seam(detail, panes, new Vector2(x[column], z[row + 1]), new Vector2(x[column + 1], z[row + 1]), eave, Eaves[row + 1, column]);
}
}
}
private void Seam(Geometry detail, Geometry panes, Vector2 start, Vector2 end, float left, float right)
{
float low = Mathf.Min(left, right) * heightScale;
float high = Mathf.Max(left, right) * heightScale;
int segments = Mathf.Max(1, Mathf.RoundToInt(bays * Vector2.Distance(start, end) / 28f));
for (int i = 1; i < segments; i++)
{
Vector2 point = Vector2.Lerp(start, end, (float)i / segments);
detail.Beam(World(point, low), World(point, high), 0.12f, 0.12f);
}
if (glass != null)
panes.Quad(World(start, low), World(end, low), World(end, high), World(start, high), true);
}
private void Wall(Geometry structure, Geometry detail, Geometry panes, Vector2 start, Vector2 end, float height, float sill = 0.60f)
{
float top = height * heightScale;
float middle = Mathf.Lerp(sill, top, 0.53f);
int count = Mathf.Max(1, Mathf.RoundToInt(bays * Vector2.Distance(start, end) / 28f));
structure.Beam(World(start, top), World(end, top), 0.27f, 0.24f);
detail.Beam(World(start, middle), World(end, middle), 0.135f, 0.14f);
for (int i = 0; i < count; i++)
{
Vector2 a = Vector2.Lerp(start, end, (float)i / count);
Vector2 b = Vector2.Lerp(start, end, (float)(i + 1) / count);
Vector3 p = World(a, sill);
Vector3 q = World(b, sill);
Vector3 r = World(b, top);
Vector3 s = World(a, top);
structure.Beam(p, s, 0.22f, 0.26f);
if (i % 2 == 0)
detail.Beam(p, r, 0.088f, 0.09f);
else
detail.Beam(q, s, 0.088f, 0.09f);
if (glass != null)
panes.Quad(p, q, r, s, true);
}
}
private void AddEntrySuperstructure(Geometry structure, Geometry detail, Geometry panes, Geometry cladding)
{
float height = 3.95f * heightScale;
cladding.Box(new Vector3(0f, height + 0.13f, -34.55f), new Vector3(8.74f, 0.36f, 5.52f), Quaternion.identity);
foreach (float side in new[] { -1f, 1f })
{
float x = 4.12f * side;
Wall(structure, detail, panes, new Vector2(x, -37.18f), new Vector2(x, -31.95f), 3.95f);
structure.Beam(new Vector3(x, 0.6f, -37.18f), new Vector3(x, height, -37.18f), 0.34f, 0.34f);
}
structure.Beam(new Vector3(-4.21f, height - 0.26f, -37.22f), new Vector3(4.21f, height - 0.26f, -37.22f),
0.36f, 0.43f);
cladding.Box(new Vector3(0f, height + 0.41f, -37.12f), new Vector3(7.2f, 0.30f, 0.42f), Quaternion.identity);
}
private Material Material(string name, string hex, float metallic, float smoothness)
{
var material = new Material(Shader.Find("Standard")) { name = name };
ColorUtility.TryParseHtmlString(hex, out Color color);
material.color = color;
material.SetFloat("_Metallic", metallic);
material.SetFloat("_Glossiness", smoothness);
profile.Own(material);
return material;
}
private Material GlassMaterial()
{
Shader shader = Resources.Load<Shader>("DomeGlass");
var material = new Material(shader) { name = "Sage glazing" };
ColorUtility.TryParseHtmlString("#96C7BF", out Color color);
color.a = Mathf.Clamp01(profile.GlazingOpacity);
material.color = color;
profile.Own(material);
return material;
}
}
private static Vector2[] Outline(float x, float z, float corner)
{
float innerX = corner - z;
float innerZ = corner - x;
return new[]
{
new Vector2(-innerX, -z), new Vector2(innerX, -z), new Vector2(x, -innerZ), new Vector2(x, innerZ),
new Vector2(innerX, z), new Vector2(-innerX, z), new Vector2(-x, innerZ), new Vector2(-x, -innerZ)
};
}
private static Vector2[] ClipCorners(Vector2[] points)
{
foreach (Vector2 inward in new[] { Vector2.one, new Vector2(1f, -1f), new Vector2(-1f, 1f), -Vector2.one })
{
var clipped = new List<Vector2>(points.Length + 1);
Vector2 previous = points[points.Length - 1];
float previousDistance = CornerLimit - Vector2.Dot(inward, previous);
foreach (Vector2 current in points)
{
float currentDistance = CornerLimit - Vector2.Dot(inward, current);
if ((previousDistance < 0f) != (currentDistance < 0f))
{
float t = previousDistance / (previousDistance - currentDistance);
clipped.Add(Vector2.LerpUnclamped(previous, current, t));
}
if (currentDistance >= 0f)
clipped.Add(current);
previous = current;
previousDistance = currentDistance;
}
points = clipped.ToArray();
}
return points;
}
private static Vector3[] ScaledRing(Vector2[] points, Vector2 center, float scaleX, float scaleZ, float height)
{
var ring = new Vector3[points.Length];
for (int i = 0; i < points.Length; i++)
{
Vector2 offset = points[i] - center;
ring[i] = World(center + new Vector2(offset.x * scaleX, offset.y * scaleZ), height);
}
return ring;
}
private static Vector3 World(Vector2 point, float height)
{
return new Vector3(point.x, height, point.y);
}
private sealed class Geometry
{
private readonly List<Vector3> vertices = new List<Vector3>();
private readonly List<Vector3> normals = new List<Vector3>();
private readonly List<int> triangles = new List<int>();
public void Beam(Vector3 a, Vector3 b, float width, float depth)
{
Vector3 span = b - a;
if (span.sqrMagnitude < 0.00001f)
return;
Vector3 up = Mathf.Abs(Vector3.Dot(span.normalized, Vector3.up)) > 0.95f ? Vector3.forward : Vector3.up;
Box((a + b) * 0.5f, new Vector3(width, depth, span.magnitude), Quaternion.LookRotation(span, up));
}
public void Box(Vector3 center, Vector3 size, Quaternion rotation)
{
Vector3 x = rotation * new Vector3(size.x * 0.5f, 0f, 0f);
Vector3 y = rotation * new Vector3(0f, size.y * 0.5f, 0f);
Vector3 z = rotation * new Vector3(0f, 0f, size.z * 0.5f);
Vector3 a = center - x - y - z;
Vector3 b = center + x - y - z;
Vector3 c = center + x - y + z;
Vector3 d = center - x - y + z;
Vector3 e = a + 2f * y;
Vector3 f = b + 2f * y;
Vector3 g = c + 2f * y;
Vector3 h = d + 2f * y;
Quad(a, b, c, d);
Quad(e, h, g, f);
Quad(a, e, f, b);
Quad(b, f, g, c);
Quad(c, g, h, d);
Quad(d, h, e, a);
}
public void Prism(Vector2[] outline, float bottom, float top)
{
for (int side = 0; side < outline.Length; side++)
{
Vector2 a = outline[side];
Vector2 b = outline[(side + 1) % outline.Length];
Quad(World(a, bottom), World(a, top), World(b, top), World(b, bottom));
}
for (int i = 1; i < outline.Length - 1; i++)
{
Triangle(World(outline[0], top), World(outline[i + 1], top), World(outline[i], top));
Triangle(World(outline[0], bottom), World(outline[i], bottom), World(outline[i + 1], bottom));
}
}
public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, bool doubleSided = false)
{
AddQuad(a, b, c, d);
if (doubleSided)
AddQuad(d, c, b, a);
}
private void AddQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
{
Vector3 normal = Vector3.Cross(b - a, c - a).normalized;
int index = vertices.Count;
AddVertex(a, normal);
AddVertex(b, normal);
AddVertex(c, normal);
AddVertex(d, normal);
AddIndices(index, index + 1, index + 2);
AddIndices(index, index + 2, index + 3);
}
public void Triangle(Vector3 a, Vector3 b, Vector3 c, bool doubleSided = false)
{
Vector3 normal = Vector3.Cross(b - a, c - a).normalized;
int index = vertices.Count;
AddVertex(a, normal);
AddVertex(b, normal);
AddVertex(c, normal);
AddIndices(index, index + 1, index + 2);
if (doubleSided)
Triangle(c, b, a);
}
private void AddVertex(Vector3 point, Vector3 normal)
{
vertices.Add(point);
normals.Add(normal);
}
private void AddIndices(int a, int b, int c)
{
triangles.Add(a);
triangles.Add(b);
triangles.Add(c);
}
public void Apply(Transform parent, Material material, string name, DomeEnvironment profile, bool shadow = true)
{
if (vertices.Count == 0)
return;
Mesh mesh = new Mesh { name = name };
if (vertices.Count > 65535)
mesh.indexFormat = IndexFormat.UInt32;
mesh.SetVertices(vertices);
mesh.SetNormals(normals);
mesh.SetTriangles(triangles, 0);
mesh.RecalculateBounds();
profile.Own(mesh);
GameObject node = Group(parent, name).gameObject;
node.AddComponent<MeshFilter>().sharedMesh = mesh;
var renderer = node.AddComponent<MeshRenderer>();
renderer.sharedMaterial = material;
renderer.shadowCastingMode = shadow ? ShadowCastingMode.On : ShadowCastingMode.Off;
renderer.receiveShadows = shadow;
}
}
}
}