private FemaleIndex GetFemaleIndex(Mesh mesh, BranchIndex fromBranchIndex, GameObjectInfo objectInfo) { FemaleIndex femaleIndex; int index = GetIndexWithSameType <FemaleIndex>(OrganType.Fruit, fromBranchIndex, out femaleIndex); if (index >= 1) { femaleIndex.HairMesh = mesh; return(null); } else { femaleIndex = new FemaleIndex(); femaleIndex.Index = index; femaleIndex.CornMesh = mesh; femaleIndex.Radius = objectInfo.Radius; femaleIndex.Rotation = objectInfo.Rotation; femaleIndex.From = fromBranchIndex; return(femaleIndex); } }
private void CreateFruitModel(FemaleIndex index, Vector3 position) { if (index.Biomass <= Mathf.Epsilon) { return; } /* * 计算形态数据:长度和最大宽度 * 用于后续生成GameObject */ index.MorphologicalSim(BranchIndexes, OrganIndexes); /* * 临时位置 * 用于确定须的位置 */ Vector3 tempPosition = Vector3.zero; GameObject parentModel = new GameObject("Fruit"); parentModel.transform.position = tempPosition; /* * 创建果实模型 */ tempPosition = CreateFruitSubModel(index.CornMesh, index.CornLength, tempPosition, parentModel); /* * 创建果实须模型 */ CreateFruitSubModel(index.HairMesh, index.HairLength, tempPosition, parentModel); parentModel.transform.position = position; RotationGameObject(parentModel, position, index.Rotation); parentModel.transform.SetParent(BranchModel.transform); SetTagInParent(parentModel.transform, "Organ"); m_listOrganModels.Add(parentModel); index.Belong = parentModel; }
public void MorphologicalSim(double biomass, bool isClear = true, bool isSameGC = false) { DataCheck(); //数据检查 /* * 包含枝干和器官的索引 * 其每一个索引包含了后续生成GameObject所需的形态信息(旋转角度)以及 * 生成形态信息所需的数据(生物量、年龄) */ List <OrganIndex> indexes = GetIndexes(isClear, isSameGC); /* * 分配生物量给各个器官 * 累积的生物量为后续形态模拟提供参考依据 */ FunctionSim.PhotosynthateAllocation(this, biomass, FunctionSim.GrowthPeriodJudgment(BranchIndexes, OrganIndexes)); /* * 遍历每个Index * 计算形态数据 * 根据形态数据绘制GameObject */ int curLevel = 0; Vector3 curPosition = Vector3.zero; Stack <Vector3> positionStack = new Stack <Vector3>(); foreach (OrganIndex index in indexes) { switch (index.Type) { case OrganType.Branch: BranchIndex branchIndex = index as BranchIndex; if (branchIndex.Level > curLevel) { positionStack.Push(curPosition); } else if (branchIndex.Level < curLevel) { curPosition = positionStack.Pop(); } curLevel = branchIndex.Level; curPosition = RecordBranchModel(branchIndex, curPosition); break; case OrganType.Leaf: LeafIndex leafIndex = index as LeafIndex; CreateLeafModel(leafIndex, curPosition); break; case OrganType.Flower: MaleIndex maleIndex = index as MaleIndex; CreateFlowerModel(maleIndex, curPosition); break; case OrganType.Fruit: FemaleIndex femaleIndex = index as FemaleIndex; CreateFruitModel(femaleIndex, curPosition); break; } } CreateBranchModel(); /* * 病虫害模拟 * 测试 */ InsectSimulation(); PostProcessing(); }