private void GenerateLeaves() { lastLeafPosition.Clear(); lastLeafRotation.Clear(); foreach (Transform child in Leaves.transform) { GameObject.Destroy(child.gameObject); } for (int i = 0; i < LeafAmount; ++i) { GameObject leaf = Instantiate(LeafPrefab, Leaves.transform); Vector3 tempPosition = stemPath.GetPointAtDistance(1f / LeafAmount * i * 10); Vector3 tempRotation = stemPath.GetNormalAtDistance(1f / LeafAmount * i * 10); leaf.transform.position = tempPosition; float normalAngle = Vector3.Angle(tempRotation, Vector3.right); normalAngle = tempRotation.y > 0 ? normalAngle : -normalAngle; float[] currAngle = new float[] { Random.Range(0, 360), normalAngle }; leaf.transform.Rotate(new Vector3(0, currAngle[0], currAngle[1])); lastLeafPosition.Add(tempPosition); lastLeafRotation.Add(currAngle); } lastLeafAmount = LeafAmount; stemPath = StemSpline.GetComponent <PathCreator>().path; }
public void AddObstacle(int index) { if (NextDistance > path.length) { ++cont; NextDistance = NextDistance % path.length; } if (NextDistance > middle_point) { half = 1; } else { half = 0; } string name = "Obstacles" + cont + half; GetParentObject(name); Vector3 position = path.GetPointAtDistance(NextDistance, endOfPathInstruction); Vector3 upward = path.GetDirectionAtDistance(NextDistance, endOfPathInstruction); Vector3 forward = path.GetNormalAtDistance(NextDistance, endOfPathInstruction); Quaternion rotation = Quaternion.LookRotation(forward, upward); Instantiate(obstacles[index], position, rotation, obstacles_object.transform); NextDistance += DistanceGap; }
private INode[] GenerateNodes() { VertexPath path = Road.path; List <INode> allNodes = new List <INode>(); nodeSpacing = Mathf.Max(NODE_MIN_SPACING, nodeSpacing); float distance = 0; int nodesPerAnchor = 3; // Create all nodes while (distance < path.length) { Vector3 centre = path.GetPointAtDistance(distance, TrackType); Vector3 normal = path.GetNormalAtDistance(distance, TrackType); Vector3 forward = Road.path.GetDirectionAtDistance(distance, TrackType); distance += nodeSpacing; allNodes.Add(new Node(centre + normal * (RoadWidth - nodesRoadEdgeOffset) * -1, forward, allNodes.Count)); allNodes.Add(new Node(centre, forward, allNodes.Count)); allNodes.Add(new Node(centre + normal * (RoadWidth - nodesRoadEdgeOffset), forward, allNodes.Count)); if (distance > path.length - nodeSpacing) { break; } } // Fill node connections for (int i = 0; i < allNodes.Count; i++) { allNodes[i].Connections = new int[nodesPerAnchor]; int neighbourIndexOffset = nodesPerAnchor - i % nodesPerAnchor; for (int j = 0; j < nodesPerAnchor; j++) { int connectionIndex = (i + j + neighbourIndexOffset) % allNodes.Count; allNodes[i].Connections[j] = allNodes[connectionIndex].ID; } } return(allNodes.ToArray()); }
public void GenerateTube(bool file) { string name = "Tube"; var generated_tranform = transform.Find(name); if (generated_tranform != null) { DestroyImmediate(generated_tranform.gameObject); Debug.Log("destroyed"); } tube = Create(name, gameObject); Debug.Log("create tube"); PathCreator path_creator = gameObject.GetComponent <PathCreator>(); if (path_creator != null) { VertexPath path = path_creator.path; /*if (file) * { * BezierPath bp = path_creator.LoadPath(); * path = new VertexPath(bp, transform); * } * else * { * path = path_creator.path; * }*/ Debug.Log("got path"); for (float distance = 0; distance < path.length; distance += 0.2f) { Vector3 position = path.GetPointAtDistance(distance, endOfPathInstruction); Vector3 upward = path.GetDirectionAtDistance(distance, endOfPathInstruction); Vector3 forward = path.GetNormalAtDistance(distance, endOfPathInstruction); Quaternion rotation = Quaternion.LookRotation(forward, upward); Instantiate(segment, position, rotation, tube.transform); } } }
//public override void CollectObservations(VectorSensor sensor) //{ // // # Basic information // Rigidbody rBody = GetComponent<Rigidbody>(); // // Agent positions & velocity // sensor.AddObservation(this.transform.localPosition); // sensor.AddObservation(rBody.velocity); // // # Collect Path's observations // float centerDistance = vertexPath.GetClosestDistanceAlongPath(this.transform.localPosition); // for (int d = tickerStart; d <= tickerEnd; d++) // { // float distance = centerDistance + d * tickerSpace; // Vector3 point = vertexPath.GetPointAtDistance(distance, EndOfPathInstruction.Loop); // Vector3 normal = vertexPath.GetNormalAtDistance(distance, EndOfPathInstruction.Loop); // AddObservationInXYZMode(sensor, point); // AddObservationInXYZMode(sensor, normal); // } // // # Padding observations // // If custom setting will have too more observations and cause the buffer overflow, We // // must warn user (in Pyhon interface level). // // Here we are padding the observation buffer with all zero // int MaxObservationSize = GetComponent<BehaviorParameters>().BrainParameters.VectorObservationSize; // for (int i = 0; i < MaxObservationSize - ObservationSize; i++) // sensor.AddObservation(0); //} public override void CollectObservations(VectorSensor sensor) { // # Basic information Rigidbody rBody = GetComponent <Rigidbody>(); // Agent velocity sensor.AddObservation(this.transform.localPosition); sensor.AddObservation(rBody.velocity); // # Collect Path's basic information float centerDistance = vertexPath.GetClosestDistanceAlongPath(this.transform.localPosition); Vector3 direction = vertexPath.GetDirectionAtDistance(centerDistance); // Check clockwise direction & determine ticker's start and end bool clockwise = (Vector3.Dot(rBody.velocity, direction) >= 0); int t_s = clockwise ? tickerStart : -tickerEnd; int t_e = clockwise ? tickerEnd : -tickerStart; // # Collect Path's observations for (int d = t_s; d <= t_e; d++) { float distance = centerDistance + d * tickerSpace; Vector3 point = vertexPath.GetPointAtDistance(distance, EndOfPathInstruction.Loop); Vector3 normal = vertexPath.GetNormalAtDistance(distance, EndOfPathInstruction.Loop); AddObservationInXYZMode(sensor, point - this.transform.localPosition); AddObservationInXYZMode(sensor, normal); } // # Padding observations // If custom setting will have too more observations and cause the buffer overflow, We // must warn user (in Pyhon interface level). // Here we are padding the observation buffer with all zero int MaxObservationSize = GetComponent <BehaviorParameters>().BrainParameters.VectorObservationSize; for (int i = 0; i < MaxObservationSize - ObservationSize; i++) { sensor.AddObservation(0); } }