public void Initialize() { if (this.root == null) { this.branchGroups = new TreeGroupBranch[0]; this.leafGroups = new TreeGroupLeaf[0]; this.nodes = new TreeNode[0]; this._uniqueID = 1; this.root = new TreeGroupRoot(); this.root.uniqueID = this._uniqueID; this.root.distributionFrequency = 1; this._uniqueID++; this.UpdateFrequency(this.root.uniqueID); this.AddGroup(this.root, typeof(TreeGroupBranch)); } }
public override void UpdateMatrix() { if (this.parentGroup == null) { for (int i = 0; i < this.nodes.Count; i++) { TreeNode treeNode = this.nodes[i]; treeNode.matrix = Matrix4x4.identity; } } else { if (this.parentGroup is TreeGroupRoot) { TreeGroupRoot treeGroupRoot = this.parentGroup as TreeGroupRoot; for (int j = 0; j < this.nodes.Count; j++) { TreeNode treeNode2 = this.nodes[j]; float num = treeNode2.offset * base.GetRootSpread(); float f = treeNode2.angle * 0.0174532924f; Vector3 pos = new Vector3(Mathf.Cos(f) * num, -treeGroupRoot.groundOffset, Mathf.Sin(f) * num); Quaternion q = Quaternion.Euler(treeNode2.pitch * -Mathf.Sin(f), 0f, treeNode2.pitch * Mathf.Cos(f)) * Quaternion.Euler(0f, treeNode2.angle, 0f); treeNode2.matrix = Matrix4x4.TRS(pos, q, Vector3.one); } } else { for (int k = 0; k < this.nodes.Count; k++) { TreeNode treeNode3 = this.nodes[k]; Vector3 pos2 = default(Vector3); Quaternion q2 = default(Quaternion); float y = 0f; treeNode3.parent.GetPropertiesAtTime(treeNode3.offset, out pos2, out q2, out y); Quaternion q3 = Quaternion.Euler(90f, treeNode3.angle, 0f); Matrix4x4 rhs = Matrix4x4.TRS(Vector3.zero, q3, Vector3.one); Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(treeNode3.pitch, 0f, 0f), Vector3.one); treeNode3.matrix = treeNode3.parent.matrix * Matrix4x4.TRS(pos2, q2, Vector3.one) * rhs * rhs2; Vector3 vector = treeNode3.matrix.MultiplyPoint(new Vector3(0f, y, 0f)); treeNode3.matrix.m03 = vector.x; treeNode3.matrix.m13 = vector.y; treeNode3.matrix.m23 = vector.z; } } } }
public override void UpdateMatrix() { if (base.parentGroup == null) { for (int i = 0; i < base.nodes.Count; i++) { TreeNode node = base.nodes[i]; node.matrix = Matrix4x4.identity; } } else if (base.parentGroup is TreeGroupRoot) { TreeGroupRoot parentGroup = base.parentGroup as TreeGroupRoot; for (int j = 0; j < base.nodes.Count; j++) { TreeNode node2 = base.nodes[j]; float num3 = node2.offset * base.GetRootSpread(); float f = node2.angle * 0.01745329f; Vector3 pos = new Vector3(Mathf.Cos(f) * num3, -parentGroup.groundOffset, Mathf.Sin(f) * num3); Quaternion q = Quaternion.Euler(node2.pitch * -Mathf.Sin(f), 0f, node2.pitch * Mathf.Cos(f)) * Quaternion.Euler(0f, node2.angle, 0f); node2.matrix = Matrix4x4.TRS(pos, q, Vector3.one); } } else { for (int k = 0; k < base.nodes.Count; k++) { TreeNode node3 = base.nodes[k]; Vector3 vector2 = new Vector3(); Quaternion rot = new Quaternion(); float rad = 0f; node3.parent.GetPropertiesAtTime(node3.offset, out vector2, out rot, out rad); Quaternion quaternion3 = Quaternion.Euler(90f, node3.angle, 0f); Matrix4x4 matrixx = Matrix4x4.TRS(Vector3.zero, quaternion3, Vector3.one); Matrix4x4 matrixx2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(node3.pitch, 0f, 0f), Vector3.one); node3.matrix = ((node3.parent.matrix * Matrix4x4.TRS(vector2, rot, Vector3.one)) * matrixx) * matrixx2; Vector3 vector3 = node3.matrix.MultiplyPoint(new Vector3(0f, rad, 0f)); node3.matrix.m03 = vector3.x; node3.matrix.m13 = vector3.y; node3.matrix.m23 = vector3.z; } } }
public void InspectorRoot(TreeData treeData, TreeGroupRoot group) { GUIContent[] contentArray1 = new GUIContent[6]; contentArray1[0] = TreeEditorHelper.GetGUIContent("Distribution|"); contentArray1[1] = TreeEditorHelper.GetGUIContent("Geometry|"); contentArray1[2] = TreeEditorHelper.GetGUIContent("Material|Controls global material properties of the tree."); GUIContent[] names = contentArray1; bool enabled = GUI.enabled; BeginSettingsSection(0, names); this.PrepareSpacing(false); int seed = group.seed; group.seed = this.GUIIntSlider(PropertyType.Normal, treeSeedString, group.seed, 0, 0x98967f, false); if (group.seed != seed) { treeData.UpdateSeed(group.uniqueID); } group.rootSpread = this.GUISlider(PropertyType.Normal, areaSpreadString, group.rootSpread, 0f, 10f, false); group.groundOffset = this.GUISlider(PropertyType.Normal, groundOffsetString, group.groundOffset, 0f, 10f, false); EndSettingsSection(); BeginSettingsSection(1, names); this.PrepareSpacing(false); group.adaptiveLODQuality = this.GUISlider(PropertyType.FullUndo, lodQualityString, group.adaptiveLODQuality, 0f, 1f, false); group.enableAmbientOcclusion = this.GUIToggle(PropertyType.FullUndo, ambientOcclusionString, group.enableAmbientOcclusion, false); GUI.enabled = group.enableAmbientOcclusion; group.aoDensity = this.GUISlider(PropertyType.Normal, aoDensityString, group.aoDensity, 0f, 1f, false); GUI.enabled = true; EndSettingsSection(); Material optimizedCutoutMaterial = treeData.optimizedCutoutMaterial; if (optimizedCutoutMaterial != null) { BeginSettingsSection(2, names); this.PrepareSpacing(false); bool changed = GUI.changed; bool flag3 = this.GUIMaterialColor(optimizedCutoutMaterial, "_TranslucencyColor", translucencyColorString) | this.GUIMaterialSlider(optimizedCutoutMaterial, "_TranslucencyViewDependency", transViewDepString); flag3 |= this.GUIMaterialSlider(optimizedCutoutMaterial, "_Cutoff", alphaCutoffString); flag3 |= this.GUIMaterialSlider(optimizedCutoutMaterial, "_ShadowStrength", shadowStrengthString); if (flag3 | this.GUIMaterialFloatField(optimizedCutoutMaterial, "_ShadowOffsetScale", shadowOffsetString)) { s_CutoutMaterialHashBeforeUndo = GenerateMaterialHash(treeData.optimizedCutoutMaterial); } group.shadowTextureQuality = this.GUIPopup(PropertyType.FullUpdate, shadowCasterResString, leafMaterialOptions, group.shadowTextureQuality, false); GUI.changed = changed; EndSettingsSection(); } GUI.enabled = enabled; EditorGUILayout.Space(); }
public override void UpdateMatrix() { if (base.parentGroup == null) { for (int i = 0; i < base.nodes.Count; i++) { TreeNode node = base.nodes[i]; node.matrix = Matrix4x4.identity; } } else { TreeGroupRoot parentGroup = base.parentGroup as TreeGroupRoot; for (int j = 0; j < base.nodes.Count; j++) { Vector3 vector3; TreeNode node2 = base.nodes[j]; Vector3 pos = new Vector3(); Quaternion rot = new Quaternion(); float rad = 0f; float surfaceAngleAtTime = 0f; if (parentGroup != null) { float num5 = node2.offset * base.GetRootSpread(); float f = node2.angle * 0.01745329f; pos = new Vector3(Mathf.Cos(f) * num5, -parentGroup.groundOffset, Mathf.Sin(f) * num5); rot = Quaternion.Euler(node2.pitch * -Mathf.Sin(f), 0f, node2.pitch * Mathf.Cos(f)) * Quaternion.Euler(0f, node2.angle, 0f); } else { node2.parent.GetPropertiesAtTime(node2.offset, out pos, out rot, out rad); surfaceAngleAtTime = node2.parent.GetSurfaceAngleAtTime(node2.offset); } Quaternion q = Quaternion.Euler(90f, node2.angle, 0f); Matrix4x4 matrixx = Matrix4x4.TRS(Vector3.zero, q, Vector3.one); Matrix4x4 matrixx2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(node2.pitch + surfaceAngleAtTime, 0f, 0f), Vector3.one); node2.matrix = ((node2.parent.matrix * Matrix4x4.TRS(pos, rot, Vector3.one)) * matrixx) * matrixx2; node2.matrix *= Matrix4x4.TRS(new Vector3(0f, 0f, 0f), node2.rotation, new Vector3(1f, 1f, 1f)); if (this.horizontalAlign > 0f) { Vector4 column = node2.matrix.GetColumn(3); Quaternion b = Quaternion.Euler(90f, node2.angle, 0f); Quaternion quaternion4 = Quaternion.Slerp(MathUtils.QuaternionFromMatrix(node2.matrix), b, this.horizontalAlign); node2.matrix = Matrix4x4.TRS(Vector3.zero, quaternion4, Vector3.one); node2.matrix.SetColumn(3, column); } if (this.geometryMode == 4) { vector3 = node2.matrix.MultiplyPoint(new Vector3(0f, rad, 0f)); node2.matrix *= Matrix4x4.Scale(new Vector3(node2.scale, node2.scale, node2.scale)); } else { vector3 = node2.matrix.MultiplyPoint(new Vector3(0f, rad + node2.scale, 0f)); } node2.matrix.m03 = vector3.x; node2.matrix.m13 = vector3.y; node2.matrix.m23 = vector3.z; } } base.UpdateMatrix(); }
override public void UpdateMatrix() { if (parentGroup == null) { for (int n = 0; n < nodes.Count; n++) { TreeNode node = nodes[n]; node.matrix = Matrix4x4.identity; } } else { TreeGroupRoot tgr = parentGroup as TreeGroupRoot; for (int n = 0; n < nodes.Count; n++) { TreeNode node = nodes[n]; Vector3 pos = new Vector3(); Quaternion rot = new Quaternion(); float rad = 0.0f; float surfaceAngle = 0.0f; if (tgr != null) { // attached to root node float dist = node.offset * GetRootSpread(); float ang = node.angle * Mathf.Deg2Rad; pos = new Vector3(Mathf.Cos(ang) * dist, -tgr.groundOffset, Mathf.Sin(ang) * dist); rot = Quaternion.Euler(node.pitch * -Mathf.Sin(ang), 0, node.pitch * Mathf.Cos(ang)) * Quaternion.Euler(0, node.angle, 0); } else { // attached to branch node node.parent.GetPropertiesAtTime(node.offset, out pos, out rot, out rad); surfaceAngle = node.parent.GetSurfaceAngleAtTime(node.offset); } Quaternion angle = Quaternion.Euler(90.0f, node.angle, 0.0f); Matrix4x4 aog = Matrix4x4.TRS(Vector3.zero, angle, Vector3.one); // pitch matrix Matrix4x4 pit = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(node.pitch + surfaceAngle, 0.0f, 0.0f), Vector3.one); node.matrix = node.parent.matrix * Matrix4x4.TRS(pos, rot, Vector3.one) * aog * pit; // spin node.matrix *= Matrix4x4.TRS(new Vector3(0, 0, 0), node.rotation, new Vector3(1, 1, 1)); // horizontalize if (horizontalAlign > 0.0f) { Vector4 opos = node.matrix.GetColumn(3); Quaternion targetQuat = Quaternion.Euler(90.0f, node.angle, 0.0f); Quaternion newQuat = Quaternion.Slerp(MathUtils.QuaternionFromMatrix(node.matrix), targetQuat, horizontalAlign); node.matrix = Matrix4x4.TRS(Vector3.zero, newQuat, Vector3.one); node.matrix.SetColumn(3, opos); } Vector3 off; if (geometryMode == (int)GeometryMode.MESH) { off = node.matrix.MultiplyPoint(new Vector3(0, rad, 0)); node.matrix = node.matrix * Matrix4x4.Scale(new Vector3(node.scale, node.scale, node.scale)); } else { off = node.matrix.MultiplyPoint(new Vector3(0, rad + node.scale, 0)); } node.matrix.m03 = off.x; node.matrix.m13 = off.y; node.matrix.m23 = off.z; } } // Update child groups.. base.UpdateMatrix(); }
public override void UpdateMatrix() { if (this.parentGroup == null) { for (int i = 0; i < this.nodes.Count; i++) { TreeNode treeNode = this.nodes[i]; treeNode.matrix = Matrix4x4.identity; } } else { TreeGroupRoot treeGroupRoot = this.parentGroup as TreeGroupRoot; for (int j = 0; j < this.nodes.Count; j++) { TreeNode treeNode2 = this.nodes[j]; Vector3 pos = default(Vector3); Quaternion q = default(Quaternion); float num = 0f; float num2 = 0f; if (treeGroupRoot != null) { float num3 = treeNode2.offset * base.GetRootSpread(); float f = treeNode2.angle * 0.0174532924f; pos = new Vector3(Mathf.Cos(f) * num3, -treeGroupRoot.groundOffset, Mathf.Sin(f) * num3); q = Quaternion.Euler(treeNode2.pitch * -Mathf.Sin(f), 0f, treeNode2.pitch * Mathf.Cos(f)) * Quaternion.Euler(0f, treeNode2.angle, 0f); } else { treeNode2.parent.GetPropertiesAtTime(treeNode2.offset, out pos, out q, out num); num2 = treeNode2.parent.GetSurfaceAngleAtTime(treeNode2.offset); } Quaternion q2 = Quaternion.Euler(90f, treeNode2.angle, 0f); Matrix4x4 rhs = Matrix4x4.TRS(Vector3.zero, q2, Vector3.one); Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(treeNode2.pitch + num2, 0f, 0f), Vector3.one); treeNode2.matrix = treeNode2.parent.matrix * Matrix4x4.TRS(pos, q, Vector3.one) * rhs * rhs2; treeNode2.matrix *= Matrix4x4.TRS(new Vector3(0f, 0f, 0f), treeNode2.rotation, new Vector3(1f, 1f, 1f)); if (this.horizontalAlign > 0f) { Vector4 column = treeNode2.matrix.GetColumn(3); Quaternion to = Quaternion.Euler(90f, treeNode2.angle, 0f); Quaternion q3 = Quaternion.Slerp(MathUtils.QuaternionFromMatrix(treeNode2.matrix), to, this.horizontalAlign); treeNode2.matrix = Matrix4x4.TRS(Vector3.zero, q3, Vector3.one); treeNode2.matrix.SetColumn(3, column); } Vector3 vector; if (this.geometryMode == 4) { vector = treeNode2.matrix.MultiplyPoint(new Vector3(0f, num, 0f)); treeNode2.matrix *= Matrix4x4.Scale(new Vector3(treeNode2.scale, treeNode2.scale, treeNode2.scale)); } else { vector = treeNode2.matrix.MultiplyPoint(new Vector3(0f, num + treeNode2.scale, 0f)); } treeNode2.matrix.m03 = vector.x; treeNode2.matrix.m13 = vector.y; treeNode2.matrix.m23 = vector.z; } } base.UpdateMatrix(); }
override public void UpdateMatrix() { if (parentGroup == null) { // root node, use rootSpread parameter for (int i = 0; i < nodes.Count; i++) { TreeNode node = nodes[i]; /* * float dist = node.offset * rootSpread; * float ang = node.angle * Mathf.Deg2Rad; * Vector3 pos = new Vector3(Mathf.Cos(ang) * dist, 0.0f, Mathf.Sin(ang) * dist); * Quaternion rot = Quaternion.Euler(node.pitch*-Mathf.Sin(ang), 0, node.pitch * Mathf.Cos(ang)) * Quaternion.Euler(0, node.angle, 0); * node.matrix = Matrix4x4.TRS(pos, rot, Vector3.one); */ node.matrix = Matrix4x4.identity; } } else if (parentGroup is TreeGroupRoot) { TreeGroupRoot tgr = parentGroup as TreeGroupRoot; // Attached to root node for (int i = 0; i < nodes.Count; i++) { TreeNode node = nodes[i]; float dist = node.offset * GetRootSpread(); float ang = node.angle * Mathf.Deg2Rad; Vector3 pos = new Vector3(Mathf.Cos(ang) * dist, -tgr.groundOffset, Mathf.Sin(ang) * dist); Quaternion rot = Quaternion.Euler(node.pitch * -Mathf.Sin(ang), 0, node.pitch * Mathf.Cos(ang)) * Quaternion.Euler(0, node.angle, 0); node.matrix = Matrix4x4.TRS(pos, rot, Vector3.one); } } else { // has a parent so, use that.. for (int i = 0; i < nodes.Count; i++) { TreeNode node = nodes[i]; Vector3 pos = new Vector3(); Quaternion rot = new Quaternion(); float rad = 0.0f; node.parent.GetPropertiesAtTime(node.offset, out pos, out rot, out rad); // x=90 makes sure start growth is perpendicular.. Quaternion angle = Quaternion.Euler(90.0f, node.angle, 0); Matrix4x4 aog = Matrix4x4.TRS(Vector3.zero, angle, Vector3.one); // pitch matrix Matrix4x4 pit = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(node.pitch, 0.0f, 0.0f), Vector3.one); node.matrix = node.parent.matrix * Matrix4x4.TRS(pos, rot, Vector3.one) * aog * pit; Vector3 off = node.matrix.MultiplyPoint(new Vector3(0, rad, 0)); node.matrix.m03 = off.x; node.matrix.m13 = off.y; node.matrix.m23 = off.z; } } // Update child groups.. //base.UpdateMatrix(); }
public void InspectorRoot(TreeData treeData, TreeGroupRoot group) { GUIContent[] expr_06 = new GUIContent[6]; expr_06[0] = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroupRoot.Distribution"); expr_06[1] = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroupRoot.Geometry"); expr_06[2] = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroupRoot.MaterialProperties"); GUIContent[] names = expr_06; bool enabled = GUI.enabled; TreeEditor.BeginSettingsSection(0, names); this.PrepareSpacing(false); int seed = group.seed; group.seed = this.GUIIntSlider(TreeEditor.PropertyType.Normal, "TreeEditor.TreeGroupRoot.GroupSeed", group.seed, 0, 9999999, false); if (group.seed != seed) { treeData.UpdateSeed(group.uniqueID); } group.rootSpread = this.GUISlider(TreeEditor.PropertyType.Normal, "TreeEditor.TreeGroupRoot.AreaSpread", group.rootSpread, 0f, 10f, false); group.groundOffset = this.GUISlider(TreeEditor.PropertyType.Normal, "TreeEditor.TreeGroupRoot.GroundOffset", group.groundOffset, 0f, 10f, false); TreeEditor.EndSettingsSection(); TreeEditor.BeginSettingsSection(1, names); this.PrepareSpacing(false); group.adaptiveLODQuality = this.GUISlider(TreeEditor.PropertyType.FullUndo, "TreeEditor.TreeGroupRoot.LODQuality", group.adaptiveLODQuality, 0f, 1f, false); group.enableAmbientOcclusion = this.GUIToggle(TreeEditor.PropertyType.FullUndo, "TreeEditor.TreeGroupRoot.AmbientOcclusion", group.enableAmbientOcclusion, false); GUI.enabled = group.enableAmbientOcclusion; group.aoDensity = this.GUISlider(TreeEditor.PropertyType.Normal, "TreeEditor.TreeGroupRoot.AODensity", group.aoDensity, 0f, 1f, false); GUI.enabled = true; TreeEditor.EndSettingsSection(); Material optimizedCutoutMaterial = treeData.optimizedCutoutMaterial; if (optimizedCutoutMaterial != null) { TreeEditor.BeginSettingsSection(2, names); this.PrepareSpacing(false); bool changed = GUI.changed; bool flag = this.GUIMaterialColor(optimizedCutoutMaterial, "_TranslucencyColor", "TreeEditor.TreeGroupRoot.TranslucencyColor"); flag |= this.GUIMaterialSlider(optimizedCutoutMaterial, "_TranslucencyViewDependency", "TreeEditor.TreeGroupRoot.TranslucencyViewDependency"); flag |= this.GUIMaterialSlider(optimizedCutoutMaterial, "_Cutoff", "TreeEditor.TreeGroupRoot.AlphaCutoff"); flag |= this.GUIMaterialSlider(optimizedCutoutMaterial, "_ShadowStrength", "TreeEditor.TreeGroupRoot.ShadowStrength"); flag |= this.GUIMaterialFloatField(optimizedCutoutMaterial, "_ShadowOffsetScale", "TreeEditor.TreeGroupRoot.ShadowOffsetScale"); if (flag) { TreeEditor.s_CutoutMaterialHashBeforeUndo = TreeEditor.GenerateMaterialHash(treeData.optimizedCutoutMaterial); } string[] optionIDs = new string[] { "Full", "Half", "Quarter", "OneEighth", "OneSixteenth" }; group.shadowTextureQuality = this.GUIPopup(TreeEditor.PropertyType.FullUpdate, "TreeEditor.TreeGroupRoot.ShadowTextureQuality", "TreeEditor.TreeGroupRoot.ShadowTextureQualityOption", optionIDs, group.shadowTextureQuality, false); GUI.changed = changed; TreeEditor.EndSettingsSection(); } GUI.enabled = enabled; EditorGUILayout.Space(); }