Flat Hierarchy
This commit is contained in:
parent
7adb1376a8
commit
1d3d62dd31
@ -130,8 +130,6 @@ GameObject:
|
|||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 197491476}
|
- component: {fileID: 197491476}
|
||||||
- component: {fileID: 197491475}
|
|
||||||
- component: {fileID: 197491474}
|
|
||||||
- component: {fileID: 197491473}
|
- component: {fileID: 197491473}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Fractal
|
m_Name: Fractal
|
||||||
@ -153,53 +151,8 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
depth: 6
|
depth: 6
|
||||||
--- !u!23 &197491474
|
mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
MeshRenderer:
|
material: {fileID: 2100000, guid: 8f3914ac4291e664ba60ae208ae66460, type: 2}
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 197491472}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_CastShadows: 1
|
|
||||||
m_ReceiveShadows: 1
|
|
||||||
m_DynamicOccludee: 1
|
|
||||||
m_MotionVectors: 1
|
|
||||||
m_LightProbeUsage: 1
|
|
||||||
m_ReflectionProbeUsage: 1
|
|
||||||
m_RayTracingMode: 2
|
|
||||||
m_RenderingLayerMask: 1
|
|
||||||
m_RendererPriority: 0
|
|
||||||
m_Materials:
|
|
||||||
- {fileID: 2100000, guid: 8f3914ac4291e664ba60ae208ae66460, type: 2}
|
|
||||||
m_StaticBatchInfo:
|
|
||||||
firstSubMesh: 0
|
|
||||||
subMeshCount: 0
|
|
||||||
m_StaticBatchRoot: {fileID: 0}
|
|
||||||
m_ProbeAnchor: {fileID: 0}
|
|
||||||
m_LightProbeVolumeOverride: {fileID: 0}
|
|
||||||
m_ScaleInLightmap: 1
|
|
||||||
m_ReceiveGI: 1
|
|
||||||
m_PreserveUVs: 0
|
|
||||||
m_IgnoreNormalsForChartDetection: 0
|
|
||||||
m_ImportantGI: 0
|
|
||||||
m_StitchLightmapSeams: 1
|
|
||||||
m_SelectedEditorRenderState: 3
|
|
||||||
m_MinimumChartSize: 4
|
|
||||||
m_AutoUVMaxDistance: 0.5
|
|
||||||
m_AutoUVMaxAngle: 89
|
|
||||||
m_LightmapParameters: {fileID: 0}
|
|
||||||
m_SortingLayerID: 0
|
|
||||||
m_SortingLayer: 0
|
|
||||||
m_SortingOrder: 0
|
|
||||||
--- !u!33 &197491475
|
|
||||||
MeshFilter:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 197491472}
|
|
||||||
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
|
||||||
--- !u!4 &197491476
|
--- !u!4 &197491476
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -2,44 +2,108 @@
|
|||||||
|
|
||||||
public class Fractal : MonoBehaviour
|
public class Fractal : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
private struct FractalPart
|
||||||
|
{
|
||||||
|
public Vector3 direction;
|
||||||
|
public Quaternion rotation;
|
||||||
|
public Transform transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
FractalPart[][] parts;
|
||||||
|
|
||||||
[SerializeField, Range(1, 8)]
|
[SerializeField, Range(1, 8)]
|
||||||
int depth = 4;
|
int depth = 4;
|
||||||
|
|
||||||
private void Start()
|
[SerializeField]
|
||||||
{
|
Mesh mesh = default;
|
||||||
name = "Fractal " + depth;
|
|
||||||
Debug.Log(name);
|
|
||||||
|
|
||||||
if (depth <= 1)
|
[SerializeField]
|
||||||
|
Material material = default;
|
||||||
|
|
||||||
|
static Vector3[] directions =
|
||||||
|
{
|
||||||
|
Vector3.up,
|
||||||
|
Vector3.right,
|
||||||
|
Vector3.left,
|
||||||
|
Vector3.forward,
|
||||||
|
Vector3.back
|
||||||
|
};
|
||||||
|
|
||||||
|
static Quaternion[] rotations =
|
||||||
|
{
|
||||||
|
Quaternion.identity,
|
||||||
|
Quaternion.Euler(0f, 0f, -90f),
|
||||||
|
Quaternion.Euler(0f, 0f, 90f),
|
||||||
|
Quaternion.Euler(90f, 0f, 0f),
|
||||||
|
Quaternion.Euler(-90f, 0f, 0f)
|
||||||
|
};
|
||||||
|
|
||||||
|
private FractalPart CreatePart(int levelIndex, int childIndex, float scale)
|
||||||
|
{
|
||||||
|
var go = new GameObject("Fractal Part L" + levelIndex + " C" + childIndex);
|
||||||
|
go.transform.localScale = scale * Vector3.one;
|
||||||
|
go.transform.SetParent(transform, false);
|
||||||
|
go.AddComponent<MeshFilter>().mesh = mesh;
|
||||||
|
go.AddComponent<MeshRenderer>().material = material;
|
||||||
|
|
||||||
|
return new FractalPart()
|
||||||
{
|
{
|
||||||
return;
|
direction = directions[childIndex],
|
||||||
|
rotation = rotations[childIndex],
|
||||||
|
transform = go.transform
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
parts = new FractalPart[depth][];
|
||||||
|
for (int i = 0, length = 1; i < parts.Length; i++, length *= 5)
|
||||||
|
{
|
||||||
|
parts[i] = new FractalPart[length];
|
||||||
}
|
}
|
||||||
|
|
||||||
var childA = CreateChild(Vector3.up, Quaternion.identity);
|
var scale = 1f;
|
||||||
var childB = CreateChild(Vector3.right, Quaternion.Euler(0f, 0f, -90f));
|
parts[0][0] = CreatePart(0, 0, scale);
|
||||||
var childC = CreateChild(Vector3.left, Quaternion.Euler(0f, 0f, 90f));
|
for (int li = 1; li < parts.Length; li++)
|
||||||
var childD = CreateChild(Vector3.forward, Quaternion.Euler(90f, 0f, 0f));
|
{
|
||||||
var childE = CreateChild(Vector3.back, Quaternion.Euler(-90f, 0f, 0f));
|
scale *= 0.5f;
|
||||||
|
FractalPart[] levelParts = parts[li];
|
||||||
childA.transform.SetParent(transform, false);
|
for (int fpi = 0; fpi < levelParts.Length; fpi += 5)
|
||||||
childB.transform.SetParent(transform, false);
|
{
|
||||||
childC.transform.SetParent(transform, false);
|
for (int ci = 0; ci < 5; ci++)
|
||||||
childD.transform.SetParent(transform, false);
|
{
|
||||||
childE.transform.SetParent(transform, false);
|
levelParts[fpi + ci] = CreatePart(li, ci, scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
transform.Rotate(0f, 22.5f * Time.deltaTime, 0f);
|
Quaternion deltaRotation = Quaternion.Euler(0f, 22.5f * Time.deltaTime, 0f);
|
||||||
}
|
|
||||||
|
|
||||||
private Fractal CreateChild(Vector3 direction, Quaternion rotation)
|
FractalPart rootPart = parts[0][0];
|
||||||
{
|
rootPart.rotation *= deltaRotation;
|
||||||
var child = Instantiate(this);
|
rootPart.transform.localRotation = rootPart.rotation;
|
||||||
child.depth = depth - 1;
|
parts[0][0] = rootPart;
|
||||||
child.transform.localPosition = 0.75f * direction;
|
|
||||||
child.transform.localRotation = rotation;
|
for (int li = 1; li < parts.Length; li++)
|
||||||
child.transform.localScale = 0.5f * Vector3.one;
|
{
|
||||||
return child;
|
FractalPart[] parentParts = parts[li - 1];
|
||||||
|
FractalPart[] levelParts = parts[li];
|
||||||
|
for (int fpi = 0; fpi < levelParts.Length; fpi++)
|
||||||
|
{
|
||||||
|
var parentTransform = parentParts[fpi / 5].transform;
|
||||||
|
var part = levelParts[fpi];
|
||||||
|
part.rotation *= deltaRotation;
|
||||||
|
part.transform.rotation =
|
||||||
|
parentTransform.localRotation * part.rotation;
|
||||||
|
part.transform.localPosition =
|
||||||
|
parentTransform.localPosition +
|
||||||
|
parentTransform.localRotation *
|
||||||
|
(1.5f * part.transform.localScale.x * part.direction);
|
||||||
|
levelParts[fpi] = part;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user