private void Update() { if (!Input.GetKeyDown(KeyCode.G) && m_LineCreator != null) { return; } if (m_LineCreator != null) { m_LineCreator.Dispose(); } LineCreator.TotalNumSeg = 0; var paramChanges = new List <LineCreator.ParamChangeEvent>(); foreach (string line in File.ReadAllLines(INSTRUCTIONS_FILE_PATH)) { var tokens = line.Split('|'); Debug.Assert(tokens.Length == 5); for (int i = 0; i < tokens.Length; i++) { tokens[i] = tokens[i].Trim(); } paramChanges.Add(new LineCreator.ParamChangeEvent { RelPos = float.Parse(tokens[0]), ParamType = (ParamType)Enum.Parse(typeof(ParamType), tokens[1]), NewVal = new Vector3(float.Parse(tokens[2]), float.Parse(tokens[3]), float.Parse(tokens[4])) }); } m_LineCreator = new LineCreator(Vector3.zero, 10, 0, paramChanges); m_LineCreator.Generate(); }
private void Split() { if (m_Level == MAX_NUM_LEVELS) { Debug.logger.Log("MAX LEVEL REACHED"); return; } /* * var dir2D = Random.insideUnitCircle; * var dir = new Vector3(dir2D.x, 0, dir2D.y); */ float mean = m_Params[ParamType.SPLIT_ANGLE_AVERAGE].x; float stdDev = m_Params[ParamType.SPLIT_ANGLE_STD_DEV].x; float phi = Random.value * 2 * Mathf.PI; float theta = SampleNormalDistribution(mean, stdDev) * Mathf.Deg2Rad; var dir = new Vector3( Mathf.Sin(theta) * Mathf.Cos(phi), Mathf.Cos(theta), Mathf.Sin(theta) * Mathf.Sin(phi)); //var mat = Matrix4x4.TRS(Vector3.zero, Quaternion.LookRotation(dir), Vector3.one); //dir = mat * m_Params[ParamType.DIRECTION]; //var rotation = Quaternion.LookRotation(m_Params[ParamType.DIRECTION], dir); var paramChanges = new List <ParamChangeEvent>(); float distFactor = m_Params[ParamType.SPLIT_CHILD_TOTAL_DIST_FACTOR].x; foreach (var paramAndVal in m_Params) { var paramType = paramAndVal.Key; var val = paramAndVal.Value; switch (paramType) { case ParamType.DIRECTION: val = dir; break; case ParamType.GENERAL_DIRECTION: val = dir; break; case ParamType.SPLIT_DISTANCE_AVERAGE: val = m_Params[ParamType.SPLIT_DISTANCE_AVERAGE] * distFactor; break; default: break; } paramChanges.Add(new ParamChangeEvent { RelPos = 0, ParamType = paramAndVal.Key, NewVal = val }); } var childLine = new LineCreator(m_Position, m_TotalDist * distFactor, m_Level + 1, paramChanges); childLine.m_Obj.transform.parent = m_Obj.transform; childLine.Generate(); m_Children.Add(childLine); m_NextSplitDist = -1; }