コード例 #1
0
    private void MakeFishies()
    {
        float halfWidth = schoolWidth / 2;

        foreach (FishType fishType in fishTypes)
        {
            fishType.Verify();
            for (int i = 0; i < fishType.count; i++)
            {
                if (fishType.prefab == null)
                {
                    Debug.LogWarning("One of the FishTypes in FishSchool has a null prefab. Oops! " + gameObject);
                    continue;
                }
                Vector3 startPosition = new Vector3(Random.Range(-halfWidth, halfWidth),
                                                    Random.Range(-halfWidth, halfWidth),
                                                    Random.Range(-halfWidth, halfWidth));

                GameObject fish = Instantiate(fishType.prefab, startPosition, Random.rotation) as GameObject;
                fish.transform.parent = fishContainer.transform;

                FishInfo info = new FishInfo(fish, fishType);
                fishies.Add(info);
//			Color newColor = new Color( Random.value, Random.value, Random.value, 1.0f ); // RANDOM COLOR ADDED
//			fishies[i].GetComponent<MeshRenderer>().material.color = newColor; // RANDOM COLOR APPLIED
                fishBounds.center = fish.transform.localPosition;
                octree.Add(info, fishBounds);
            }
        }
    }
コード例 #2
0
        public void Add(Entity e, Bounds bounds)
        {
            if (!worldBounds.Intersects(bounds))
            {
                // out of the world:
                Remove(e);
                return;
            }

            var node = new VolumetricAssetOctreeNode(e, bounds);

            if (knownEntities.Contains(e))
            {
                octree.Remove(node);
            }
            else
            {
                knownEntities.Add(e);
            }

            var max = math.max(mapBounds.max, bounds.max);
            var min = math.min(mapBounds.min, bounds.min);

            mapBounds.SetMinMax(min, max);
            octree.Add(node, bounds);
        }
コード例 #3
0
 protected override void AddCells_internal()
 {
     foreach (var cell in CellList)
     {
         UnityOctreeCellTree.Add(cell, new Bounds(cell.Position, cell.Size));
     }
 }
コード例 #4
0
    /// <summary>
    /// The callback for receiving data on the subscribed channel.
    /// Parses and checks if message is corrupted.
    /// Stores data ready for visualization.
    /// </summary>
    /// <param name="timestamp">The timestamp of the received message.</param>
    /// <param name="message">The raw contents of the message.</param>
    public void OnReceiveMessage(float timestamp, string message)
    {
        if (string.Compare(message.ToString(), "End of Radiation") == 0)
        {
            finished = true;
        }
        string[] parts = message.Split(',');
        float    x, y, z, intensity, size;

        if (parts.Length >= 4 && float.TryParse(parts[0], out x) &&
            float.TryParse(parts[1], out y) && float.TryParse(parts[2], out z) &&
            float.TryParse(parts[3], out intensity))
        {
            if (boundsTree == null)
            {
                boundsTree = new BoundsOctree <float>(this.size * 100, new Vector3(0, 0, 0), this.size, 1f);
            }
            ParticleSystem.Particle p = new ParticleSystem.Particle();
            p.position  = (flipYZ) ? new Vector3(x, z, y) : new Vector3(x, y, z);
            p.startSize = this.size;

            p.startColor = colorFromIntensity(intensity);

            AddParticle(p);

            // Adding the cube to the octree
            Vector3 bounds = new Vector3(this.size, this.size, this.size);
            boundsTree.Add(intensity, new Bounds(p.position, bounds));
        }
        else if (parts.Length == 1 && float.TryParse(parts[0], out size))
        {
            this.size = size;
        }
    }
コード例 #5
0
        private void SetupOctree()
        {
            Bounds sceneBounds = GetSceneBounds();

            BoundsOctree = new BoundsOctree <MeshRendererRaycastInfo>(sceneBounds.size.magnitude, sceneBounds.center, 1, 1.2f);

            for (int i = 0; i <= MeshRendererRaycastInfoList.Count - 1; i++)
            {
                BoundsOctree.Add(MeshRendererRaycastInfoList[i], MeshRendererRaycastInfoList[i].Bounds);
            }
        }
コード例 #6
0
        private void Start()
        {
            // Initial size (metres), initial centre position, minimum node size (metres), looseness
            boundsTree = new BoundsOctree <Collider>(worldSize, pos, minNodeSize, loosenessval);
            // Initial size (metres), initial centre position, minimum node size (metres)
            //pointTree = new PointOctree<GameObject>(150, .pos, 1);
            for (int i = 0; i < count; i++)
            {
                var obj = GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent <Collider>();
                obj.transform.SetParent(transform, false);
                obj.transform.position   = new Vector3(Random.Range(0, worldSize), 0, Random.Range(0, worldSize));
                obj.transform.localScale = new Vector3(Random.Range(1, 4), Random.Range(1, 4), Random.Range(1, 4));

                var mat = new Material(obj.GetComponent <Renderer>().material);
                obj.GetComponent <Renderer>().material = mat;
                if (i % Mathf.CeilToInt(1 / percent) == 0)
                {
                    StartCoroutine(RandomMove(obj, () => {
                        boundsTree.Remove(obj);
                        boundsTree.Add(obj, obj.bounds);
                    }));
                }
                else if (i % Mathf.CeilToInt(1 / percent) == 1)
                {
                    objs.Add(obj);
                    mats.Add(mat);
                    isCollide.Add(false);
                    StartCoroutine(RandomMove(obj, null));
                }
                else
                {
                    boundsTree.Add(obj, obj.bounds);
                }
            }

            testObj = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
            mat     = new Material(testObj.GetComponent <Renderer>().material);
            testObj.GetComponent <Renderer>().material = mat;
        }
コード例 #7
0
    // Start is called before the first frame update
    void Start()
    {
        boundsOctree = new BoundsOctree <int> (8, Vector3.zero, 1, 1);
        // boundsOctree = new BoundsOctree <int> ( 10, Vector3.zero, 4, 1 ) ;

        //boundsOctree.Add ( 10, new Bounds () { center = Vector3.one * 5, size = Vector3.one * 5 } ) ;
        //boundsOctree.Add ( 11, new Bounds () { center = Vector3.one * 15, size = Vector3.one * 5 } ) ;
        //_OctreeAddInstance ( 12, new Bounds () { center = Vector3.one * 25, size = Vector3.one * 5 } ) ;
        //boundsOctree.Add ( 12, new Bounds () { center = Vector3.one * 25, size = Vector3.one * 5 } ) ;

        //boundsOctree.Add ( 4, new Bounds () { center = new Vector3 ( 0, 0, 0 ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
        //boundsOctree.Add ( 5, new Bounds () { center = new Vector3 ( 0, 0, 5 ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
        //boundsOctree.Add ( 6, new Bounds () { center = new Vector3 ( 1, 0, 6 ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;



        for (int i = 0; i < 100; i++)
        {
            int x = i % 10;
            Debug.LogWarning("x: " + i + "; " + ((float)i % 10f));
            int y = Mathf.FloorToInt(i / 10);
            Debug.Log("Test instance spawn #" + i + " x: " + x + " y: " + y);
            boundsOctree.Add(i, new Bounds()
            {
                center = new Vector3(x, 0, y) + Vector3.one * 0.5f, size = Vector3.one * 1
            });
            // _OctreeAddInstance ( i, new Bounds () { center = new Vector3 ( x, 0, y ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
        }



//        boundsOctree.Remove ( 11 ) ;

        int i_instanceIndex;

        Bounds checkBounds = new Bounds()
        {
            center = Vector3.one * 30, size = Vector3.one * 4
        };
        bool isColliding = boundsOctree.IsColliding(checkBounds, out i_instanceIndex);

        Debug.Log("Orig Colliding: " + (isColliding ? "T" : "F"));

        checkBounds = new Bounds()
        {
            center = Vector3.one * 0, size = Vector3.one * 30
        };
        isColliding = boundsOctree.IsColliding(checkBounds, out i_instanceIndex);
        Debug.Log("Orig Colliding: " + (isColliding ? "T" : "F"));
    }
コード例 #8
0
    public void RefreshMemory()
    {
        //bool hasFinished = true;
        List <hotspot> allLanding = primeLanding.GetAllItems();

        nLandingSpots = allLanding.Count;
        foreach (var spot in allLanding)
        {
            List <hotspot> colliding;
            primeLanding.GetColliding(out colliding, new Bounds(spot.location, spot.heat * Vector3.one));
            if (colliding.Count > 1)
            {
                hotspot newSpot = new hotspot(colliding);
                primeLanding.Add(newSpot, new Bounds(newSpot.location, hotspot.GetBucketSize(minLandingSize, minMemoryDistance, oneMeterMemoryDistance, newSpot.location, _thisT.position) * Vector3.one));
                foreach (var item in colliding)
                {
                    primeLanding.Remove(item);
                }
                //hasFinished = false;
                break;
            }
        }
    }
コード例 #9
0
    void Start()
    {
        gameObject.transform.position = Vector3.zero;
        octree = new BoundsOctree <GameObject> (10, transform.position, 1, 1);
        for (int i = 0; i < transform.childCount; i++)
        {
            GameObject child = transform.GetChild(i).gameObject;
            octree.Add(child, child.GetComponent <MeshRenderer>().bounds);
        }
        cube = GameObject.Find("Cube");

        int size = 10;

        bounds = new Bounds(cube.transform.position, new Vector3(size, size, size));
    }
コード例 #10
0
    // Start is called before the first frame update
    void Start()
    {
        _meshFilter     = GetComponent <MeshFilter>();
        _computeKernel  = Instantiate(_computeKernel);
        _countVertices  = _meshFilter.mesh.vertexCount;
        _initPos        = new List <Vector3>();
        _initNormal     = new List <Vector3>();
        _impactList     = new List <Vector3>();
        _pos            = new List <Vector3>();
        _colors         = new List <Color>();
        _buffInitPos    = new ComputeBuffer(_countVertices, sizeof(float) * 3);
        _buffInitNormal = new ComputeBuffer(_countVertices, sizeof(float) * 3);
        _buffPos        = new ComputeBuffer(_countVertices, sizeof(float) * 3);
        _impactPos      = new ComputeBuffer(_countVertices, sizeof(float) * 3);
        _buffColor      = new ComputeBuffer(_countVertices, sizeof(float) * 4);
        _kernelId       = _computeKernel.FindKernel("CSMain");
        _computeKernel.SetBuffer(_kernelId, "_VertexBuffer", _buffPos);
        _computeKernel.SetBuffer(_kernelId, "_InitialPositionBuffer", _buffInitPos);
        _computeKernel.SetBuffer(_kernelId, "_InitialNormalBuffer", _buffInitNormal);
        _computeKernel.SetBuffer(_kernelId, "_ImpactPositionBuffer", _impactPos);
        _computeKernel.SetFloat("_drag", _drag);
        _computeKernel.SetFloat("_elacticity", _elasticity);
        _computeKernel.SetBuffer(_kernelId, "_ColorsBuffer", _buffColor);
        _meshFilter   = GetComponent <MeshFilter>();
        _octreePoints = new BoundsOctree <int>(1, Vector3.zero, 0.01f, 1);
        Mesh         tmpMesh = _meshFilter.mesh;
        MeshRenderer render  = GetComponent <MeshRenderer>();

        for (int i = 0; i < tmpMesh.vertexCount; i++)
        {
            _initPos.Add(tmpMesh.vertices[i]);
            _pos.Add(tmpMesh.vertices[i]);
            _initNormal.Add(tmpMesh.normals[i]);
            _impactList.Add(Vector3.zero);
            _colors.Add(((Texture2D)render.material.GetTexture("_MetallicGlossMap")).GetPixelBilinear(i % render.material.mainTexture.width, i / render.material.mainTexture.height));
            _octreePoints.Add(i, new Bounds((Quaternion.Euler(transform.rotation.eulerAngles) * Vector3.Scale(tmpMesh.vertices[i], transform.localScale)) + transform.position, Vector3.one * 0.01f));
        }
        _buffInitPos.SetData(_initPos.ToArray());
        _buffInitNormal.SetData(_initNormal.ToArray());
        _buffPos.SetData(_pos.ToArray());
        _buffColor.SetData(_colors.ToArray());
        _meshFilter.mesh.MarkDynamic();
    }
コード例 #11
0
    // Use this for initialization
    void Start()
    {
        // Initial size (metres), initial centre position, minimum node size (metres), looseness
        boundsTree = new BoundsOctree <GameObject>(15, MyContainer.position, 1, 1.25f);
        // Initial size (metres), initial centre position, minimum node size (metres)
        pointTree = new PointOctree <GameObject>(15, MyContainer.position, 1);

        boundsTree.Add(myObject, myBounds);
        //boundsTree.Remove(myObject);

        pointTree.Add(myObject, myVector3);
        //boundsTree.Remove(myObject);

        //bool result = boundsTree.IsColliding(bounds);

        //GameObject[] result2 = boundsTree.GetColliding(bounds);

        //pointTree.GetNearby(myRay, 4);
    }
コード例 #12
0
ファイル: MeshUtils.cs プロジェクト: Avatarchik/serpent
        public static BoundsOctree <int> GenerateOctree(this Mesh mesh)
        {
            var octree = new BoundsOctree <int>(64, Vector3.zero, 1, 1.25f);

            Func <int, Bounds> getTriangleBounds = (int index) => {
                RawTriangle t    = mesh.GetRawTriangleByIndex(index);
                Bounds      aabb = new Bounds(t.v1, Vector3.zero);
                aabb.Encapsulate(t.v2);
                aabb.Encapsulate(t.v3);

                return(aabb);
            };

            int triangleCount = mesh.GetSaneTriangles(0).Length;

            for (int i = 0; i < triangleCount; ++i)
            {
                octree.Add(i, getTriangleBounds(i));
            }

            return(octree);
        }
コード例 #13
0
    public Vector3 GetBestLanding()
    {
        AveragedHotspots = new BoundsOctree <hotspot>(oneMeterMemoryDistance, _thisT.position, 1, 1);
        List <hotspot> allLanding  = primeLanding.GetAllItems();
        Bounds         memoryLimit = primeLanding.GetMaxBounds();
        Vector3        testSpot;
        float          temoHeat;

        for (int i = (int)memoryLimit.min.y; i <= (int)memoryLimit.max.x; i++)
        {
            for (int j = (int)memoryLimit.min.y; j < (int)memoryLimit.max.y; j++)
            {
                for (int k = (int)memoryLimit.min.z; k < (int)memoryLimit.max.z; k++)
                {
                    testSpot = new Vector3(i, j, k);
                    temoHeat = hotspot.GetCombinedHeat(allLanding, testSpot);
                    AveragedHotspots.Add(new hotspot(temoHeat, testSpot), new Bounds(testSpot, Vector3.one));
                }
            }
        }
        return(Vector3.zero);
    }
コード例 #14
0
    void OnDrawGizmos()
    {
        BoundsOctree <GameObject> boundsTree = new BoundsOctree <GameObject>(15, MyContainer.position, 1, 1.5f);
        PointOctree <GameObject>  pointTree  = new PointOctree <GameObject>(15, MyContainer.position, 1.0f);

        for (int i = 0; i < myObject.Count; i++)
        {
            boundsTree.Add(myObject[i], myBounds);
            boundsTree.DrawAllBounds(); // Draw node boundaries

            Gizmos.color = Color.yellow;
            Gizmos.DrawSphere(transform.position, radius);
            boundsTree.DrawAllObjects(); // Draw object boundaries
                                         //.DrawCollisionChecks(); // Draw the last *numCollisionsToSave* collision check boundaries

            pointTree.DrawAllBounds();   // Draw node boundaries
            pointTree.DrawAllObjects();  // Mark object positions

            if (track[i])
            {
                myBounds.center = track[i].position;
            }
        }
    }
コード例 #15
0
        public void PlaceObjects(float x, float y, List <CityObject> objectsToPlace, AnalyzisResult analyzisResult)
        {
            /* objectsToPlace.Sort((a, b) =>
             * {
             *   float diff = a.objectInfo.BoundingBoxVolume - b.objectInfo.BoundingBoxVolume;
             *
             *   if (diff > 0)
             *   {
             *       return 1;
             *   }
             *
             *   if (diff < 0)
             *
             *   {
             *       return -1;
             *   }
             *
             *   return 0;
             * });*/

            minBoundsSize = analyzisResult.minBoundsSize;

            CreateSpreadSheet(x, y, objectsToPlace.Count);

            _octree = new BoundsOctree <CityElement>(new Vector3(x, analyzisResult.maxYSize, y),
                                                     new Vector3(x / 2, analyzisResult.maxYSize / 2, y / 2), minBoundsSize, 1f);

            int    placedObjectIndex = 0;
            Bounds bounds            = new Bounds();

            while (placedObjectIndex < objectsToPlace.Count && _spreadsheet.ActiveCellsCount > 0)
            {
                bool finded     = false;
                var  activeCell = _spreadsheet.GetRandomActiveCell();

                int i = placedObjectIndex;

                for (; i < objectsToPlace.Count; i++)
                {
                    var objectToPlace   = objectsToPlace[i];
                    var objectTransform = objectToPlace.Object.transform;

                    if (!activeCell.CellValue.IsActive)
                    {
                        Debug.LogError("Cell is not active");
                    }

                    Vector3 position = objectTransform.position;
                    position.x = activeCell.CellValue.Position.x;
                    position.y = objectToPlace.objectInfo.CorrectYPos;
                    position.z = activeCell.CellValue.Position.y;

                    objectTransform.position = position;
                    bounds = objectToPlace.MeshRenderer.bounds;

                    if (!_octree.IsColliding(bounds))
                    {
                        var node = _octree.Add(objectToPlace.objectInfo, bounds);

                        if (node != null)
                        {
                            finded = true;
                            break;
                        }
                    }
                }

                if (finded)
                {
                    var t = objectsToPlace[i];
                    objectsToPlace[i] = objectsToPlace[placedObjectIndex];
                    objectsToPlace[placedObjectIndex] = t;
                    placedObjectIndex++;
                    _spreadsheet.SetCellsInactiveInRect(activeCell, new Vector2(bounds.size.x, bounds.size.z));
                }
                else
                {
                    _spreadsheet.SetCellInactive(activeCell);
                }
            }

            for (var index = placedObjectIndex; index < objectsToPlace.Count; index++)
            {
                Object.Destroy(objectsToPlace[index].Object);
            }
        }
コード例 #16
0
    // Start is called before the first frame update
    void Start()
    {
        boundsOctree = new BoundsOctree <int> (1, -Vector3.zero * 0.5f, 1, 1f);
        // boundsOctree = new BoundsOctree <int> ( 1, Vector3.one * 0.5f, 0.5f, 1f ) ;
        // boundsOctree = new BoundsOctree <int> ( 16, Vector3.one * 0.5f, 3, 2f ) ;
        // boundsOctree = new BoundsOctree <int> ( 16, Vector3.one, 2, 2f ) ;
        // boundsOctree = new BoundsOctree <int> ( 10, Vector3.zero, 4, 1 ) ;

        //boundsOctree.Add ( 10, new Bounds () { center = Vector3.one * 5, size = Vector3.one * 5 } ) ;
        //boundsOctree.Add ( 11, new Bounds () { center = Vector3.one * 15, size = Vector3.one * 5 } ) ;
        //_OctreeAddInstance ( 12, new Bounds () { center = Vector3.one * 25, size = Vector3.one * 5 } ) ;
        //boundsOctree.Add ( 12, new Bounds () { center = Vector3.one * 25, size = Vector3.one * 5 } ) ;

        //boundsOctree.Add ( 4, new Bounds () { center = new Vector3 ( 0, 0, 0 ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
        //boundsOctree.Add ( 5, new Bounds () { center = new Vector3 ( 0, 0, 5 ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
        //boundsOctree.Add ( 6, new Bounds () { center = new Vector3 ( 1, 0, 6 ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;


        boundsOctree.Add(0, new Bounds()
        {
            center = new Vector3(0, 0, 0) + Vector3.one * 0.0f, size = Vector3.one * 1
        });
        GameObject.Instantiate(GameObject.Find("TempInstance"), new Vector3(0, 0, 0), Quaternion.identity);
        boundsOctree.Add(1, new Bounds()
        {
            center = new Vector3(0, 1, 0) + Vector3.one * 0.0f, size = Vector3.one * 1
        });
        GameObject.Instantiate(GameObject.Find("TempInstance"), new Vector3(0, 1, 0), Quaternion.identity);
        boundsOctree.Add(2, new Bounds()
        {
            center = new Vector3(0, 1, -1) + Vector3.one * 0.0f, size = Vector3.one * 1
        });
        GameObject.Instantiate(GameObject.Find("TempInstance"), new Vector3(0, 1, -1), Quaternion.identity);
        boundsOctree.Add(3, new Bounds()
        {
            center = new Vector3(0, 2, -1) + Vector3.one * 0.0f, size = Vector3.one * 1
        });
        GameObject.Instantiate(GameObject.Find("TempInstance"), new Vector3(0, 2, -1), Quaternion.identity);
        boundsOctree.Add(4, new Bounds()
        {
            center = new Vector3(-1, 2, -1) + Vector3.one * 0.0f, size = Vector3.one * 1
        });
        GameObject.Instantiate(GameObject.Find("TempInstance"), new Vector3(-1, 2, -1), Quaternion.identity);


        int x = 0;
        int y = 0;
        int z = 0;

        /*
         * for ( int i = 0; i < 10; i ++ )
         * {
         *  x = i ;
         *  // Debug.LogWarning ( "x: " + i + "; " + ((float) i % 10f ) ) ;
         *  y = i / 2 ;
         *  z = -i / 2 ;
         *
         *  if ( i >= 6 )
         *  {
         *      z += 3 ;
         *      y = 1 ;
         *  }
         *
         *  GameObject.Instantiate ( GameObject.Find ( "TempInstance" ), new Vector3 ( x, y, z ), Quaternion.identity ) ;
         *
         *  Debug.Log ( "Test instance spawn #" + i + " x: " + x + " y: " + y ) ;
         *  boundsOctree.Add ( i, new Bounds () { center = new Vector3 ( x, y, z ) + Vector3.one * 0.0f, size = Vector3.one * 1 } ) ;
         *  // boundsOctree.Add ( i, new Bounds () { center = new Vector3 ( x, y, z ) + Vector3.one * 0.0f, size = Vector3.one * 1 + Vector3.right * 2 } ) ;
         *  // _OctreeAddInstance ( i, new Bounds () { center = new Vector3 ( x, 0, y ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
         * }
         */

        /*
         * for ( int i = 0; i < 3; i ++ )
         * {
         *  int x = i == 0 ? 0 : 1 ;
         *  // Debug.LogWarning ( "x: " + i + "; " + ((float) i % 10f ) ) ;
         *  int y = 0 ;
         *  int z = -i ;
         *  Debug.Log ( "Test instance spawn #" + i + " x: " + x + " y: " + y ) ;
         *  boundsOctree.Add ( i, new Bounds () { center = new Vector3 ( x, y, z ) + Vector3.one * 0.0f, size = Vector3.one * 1 + Vector3.right * 2 } ) ;
         *  // _OctreeAddInstance ( i, new Bounds () { center = new Vector3 ( x, 0, y ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
         * }
         */

        // boundsOctree.Remove ( 1 ) ;

        /*
         * for ( int i = 0; i < 100; i ++ )
         * {
         *  int x = i % 10 ;
         *  Debug.LogWarning ( "x: " + i + "; " + ((float) i % 10f ) ) ;
         *  int y = Mathf.FloorToInt ( i / 10 ) ;
         *  Debug.Log ( "Test instance spawn #" + i + " x: " + x + " y: " + y ) ;
         *  boundsOctree.Add ( i, new Bounds () { center = new Vector3 ( x, 0, y ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
         *  // _OctreeAddInstance ( i, new Bounds () { center = new Vector3 ( x, 0, y ) + Vector3.one * 0.5f, size = Vector3.one * 1 } ) ;
         * }
         */


//        boundsOctree.Remove ( 11 ) ;

        int i_instanceIndex;

        Bounds checkBounds = new Bounds()
        {
            center = Vector3.one * 30, size = Vector3.one * 4
        };
        bool isColliding = boundsOctree.IsColliding(checkBounds, out i_instanceIndex);

        Debug.Log("Orig Colliding: " + (isColliding ? "T" : "F"));

        checkBounds = new Bounds()
        {
            center = Vector3.one * 0, size = Vector3.one * 30
        };
        isColliding = boundsOctree.IsColliding(checkBounds, out i_instanceIndex);
        Debug.Log("Orig Colliding: " + (isColliding ? "T" : "F"));
    }
コード例 #17
0
ファイル: TreeInfo.cs プロジェクト: sjaakjules/DDL_BirdSim
        public static BoundsOctree <BranchLineInfo> TreesInWorld;// = new BoundsOctree<BranchLineInfo>(10, origin, .1, 1);


        public TreeInfo(List <string[]> _text, int _id)
        {
            id = _id;
            Vector3 tempStart = Vector3.one;

            for (int i = 0; i < _text.Count; i++)
            {
                if (_text[i].Length == 23)
                {
                    BranchLineInfo newBranchLine = new BranchLineInfo(_text[i]);
                    BranchInfo     newBranch     = new BranchInfo(_text[i], this);
                    if (i == 0)
                    {
                        tempStart = newBranchLine.startPt;
                    }
                    if (tempStart.y > newBranchLine.startPt.y)
                    {
                        tempStart = newBranchLine.startPt;
                    }
                    if (!branchLines.ContainsKey(newBranchLine.id))
                    {
                        branchLines.Add(newBranchLine.id, newBranchLine);
                    }

                    if (branches.ContainsKey(newBranch.id))
                    {
                        branches[newBranch.id].addLine(newBranchLine);
                        newBranchLine.setBranch(branches[newBranch.id]);
                    }
                    else
                    {
                        branches.Add(newBranch.id, newBranch);
                        newBranch.addLine(newBranchLine);
                        newBranchLine.setBranch(newBranch);
                    }
                }
            }
            // set branch transforms.
            foreach (var branch in branches)
            {
                branch.Value.SetTransform(this);
            }
            branchTransforms = new List <List <Matrix4x4> >();// new Matrix4x4[branchLines.Count];
            branchColour     = new List <List <Vector4> >();
            branchs          = new List <List <BranchLineInfo> >();
            int count = 0;
            int index = 0;

            branchTransforms.Add(new List <Matrix4x4>());
            branchColour.Add(new List <Vector4>());
            branchs.Add(new List <BranchLineInfo>());
            foreach (var branchLine in branchLines)
            {
                count++;
                if (count > 1020)
                {
                    branchTransforms.Add(new List <Matrix4x4>());
                    branchColour.Add(new List <Vector4>());
                    branchs.Add(new List <BranchLineInfo>());
                    count = 0;
                    index++;
                }
                branchTransforms[index].Add(branchLine.Value.transform);
                branchs[index].Add(branchLine.Value);

                /*
                 * switch (branchLine.Value.branch.bType)
                 * {
                 *  case BranchType.Hidden:
                 *      branchColour[index].Add((new Vector4(0.5f, 0.5f, 0.5f, 1)));
                 *      break;
                 *  case BranchType.Undefined:
                 *      branchColour[index].Add((new Vector4(0.5f, 0.5f, 0.5f, 1)));
                 *      break;
                 *  case BranchType.Exposed:
                 *      branchColour[index].Add((new Vector4(1, 0, 0, 1)));
                 *      break;
                 *  case BranchType.Lateral:
                 *      branchColour[index].Add((new Vector4(1, 0.5f, 1, 1)));
                 *      break;
                 *  case BranchType.DeadTipLow:
                 *      branchColour[index].Add((new Vector4(0, 0.5f, 1, 1)));
                 *      break;
                 *  case BranchType.DeadLateralLow:
                 *      branchColour[index].Add((new Vector4(0.5f, 0, 0.5f, 1)));
                 *      break;
                 *  default:
                 *      break;
                 * }
                 */
                if (branchLine.Value.radius > 0.1)
                {
                    branchColour[index].Add((new Vector4(1, 0, 0, 1)));
                }
                else
                {
                    branchColour[index].Add((new Vector4(0.5f, 0.5f, 0.5f, 1)));
                }

                /*
                 * if (branchLine.Value.branch.isDead && branchLine.Value.inclanation < 45 && branchLine.Value.radius > 0.02)
                 *  branchColour[index].Add((new Vector4(1, 0, 0, 1)));
                 * else
                 *  branchColour[index].Add((new Vector4(0.5f, 0.5f, 0.5f, 1)));
                 */
                //branchColour[index].Add((new Vector4(branchLine.Value.distanceToTip, branchLine.Value.elevation, branchLine.Value.inclanation, 1.0f)).normalized);
            }
            origin = tempStart;
            if (TreesInWorld == null)
            {
                TreesInWorld = new BoundsOctree <BranchLineInfo>(30, origin, .1f, 1);
            }
            foreach (var branchLine in branchLines)
            {
                TreesInWorld.Add(branchLine.Value, new Bounds((branchLine.Value.endPt + branchLine.Value.startPt) / 2, branchLine.Value.endPt - branchLine.Value.startPt));
            }
        }
コード例 #18
0
        private List <MeshRenderer> GetSceneMeshes()
        {
            var meshList = new List <MeshRenderer>();

            renderableSet.Clear();
            curMultiTagID = 0;
            UnityEngine.SceneManagement.Scene curScene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(Name);

            Debug.LogFormat("Get OC RendererObjs for Scene {0}", Name);
            GameObject[] objs = curScene.GetRootGameObjects();

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                if (!obj.activeInHierarchy || !obj.activeSelf)
                {
                    continue;
                }

                //重置ID
                MeshRenderer[] meshes = obj.GetComponentsInChildren <MeshRenderer>();
                for (int j = 0; j < meshes.Length; j++)
                {
                    var r = meshes[j];
                    if (r != null)
                    {
                        var com = r.gameObject.GetComponent <GameObjectID>();
                        if (com != null)
                        {
                            com.Reset();
                        }
                        else
                        {
                            if (Util.IsValidOCRenderer(r))
                            {
                                com = r.gameObject.AddComponent <GameObjectID>();
                                com.Reset();
                            }
                        }
                    }
                }


                //multiTag
                Traverse(obj);
            }

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                if (!obj.activeInHierarchy || !obj.activeSelf)
                {
                    continue;
                }

                //lod meshes
                var groups = obj.GetComponentsInChildren <LODGroup>();
                List <MeshRenderer> lodMeshes = new List <MeshRenderer>();
                for (int j = 0; j < groups.Length; j++)
                {
                    var group = groups[j];
                    lodMeshes.Clear();
                    var lods = group.GetLODs();
                    for (int k = 0; k < lods.Length; k++)
                    {
                        var lod = lods[k];
                        for (int l = 0; l < lod.renderers.Length; l++)
                        {
                            var mesh = lod.renderers[l] as MeshRenderer;
                            if (Util.IsValidOCRenderer(mesh))
                            {
                                //lodMeshes.Add(mesh);
                                Util.TryAdd(mesh, lodMeshes);
                            }
                        }
                    }
                    if (lodMeshes.Count > 0)
                    {
                        renderableSet.Add(lodMeshes);
                    }
                }
            }

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                if (!obj.activeInHierarchy || !obj.activeSelf)
                {
                    continue;
                }

                MeshRenderer[] meshes = obj.GetComponentsInChildren <MeshRenderer>();

                //no lod group
                for (int j = 0; j < meshes.Length; j++)
                {
                    MeshRenderer mr = meshes[j];

                    if (Util.IsValidOCRenderer(mr))
                    {
                        bool add = Util.TryAdd(mr, meshList);
                        if (add)
                        {
                            renderableSet.Add(mr);
                        }


                        if (Config.SoftRenderer && add)
                        {
                            if (Owner == null)
                            {
                                treeMesh.Add(mr, mr.bounds);
                            }
                            else
                            {
                                Owner.treeMesh.Add(mr, mr.bounds);
                            }
                        }
                    }
                }
            }


            if (Config.PreProcess && Owner != null)
            {
                curScene = SceneManager.GetSceneByName(StreamSceneName);
            }

            Debug.LogFormat("Get OC RendererObjs for Scene {0}", StreamSceneName);
            objs = curScene.GetRootGameObjects();

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                if (!obj.activeInHierarchy || !obj.activeSelf)
                {
                    continue;
                }

                //重置ID
                MeshRenderer[] meshes = obj.GetComponentsInChildren <MeshRenderer>();
                for (int j = 0; j < meshes.Length; j++)
                {
                    var r = meshes[j];
                    if (r != null)
                    {
                        var com = r.gameObject.GetComponent <GameObjectID>();
                        if (com != null)
                        {
                            com.Reset();
                        }
                        else
                        {
                            if (Util.IsValidOCRenderer(r))
                            {
                                com = r.gameObject.AddComponent <GameObjectID>();
                                com.Reset();
                            }
                        }
                    }
                }
                //multiTag
                Traverse(obj);
            }

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                if (!obj.activeInHierarchy || !obj.activeSelf)
                {
                    continue;
                }

                //lod meshes
                var groups = obj.GetComponentsInChildren <LODGroup>();
                List <MeshRenderer> lodMeshes = new List <MeshRenderer>();
                for (int j = 0; j < groups.Length; j++)
                {
                    var group = groups[j];
                    lodMeshes.Clear();
                    var lods = group.GetLODs();
                    for (int k = 0; k < lods.Length; k++)
                    {
                        var lod = lods[k];
                        for (int l = 0; l < lod.renderers.Length; l++)
                        {
                            var mesh = lod.renderers[l] as MeshRenderer;
                            if (Util.IsValidOCRenderer(mesh))
                            {
                                //lodMeshes.Add(mesh);
                                Util.TryAdd(mesh, lodMeshes);
                            }
                        }
                    }
                    if (lodMeshes.Count > 0)
                    {
                        renderableSet.Add(lodMeshes);
                    }
                }
            }

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                if (!obj.activeInHierarchy || !obj.activeSelf)
                {
                    continue;
                }

                MeshRenderer[] meshes = obj.GetComponentsInChildren <MeshRenderer>();

                //no lod group
                for (int j = 0; j < meshes.Length; j++)
                {
                    MeshRenderer mr = meshes[j];

                    if (Util.IsValidOCRenderer(mr))
                    {
                        bool add = Util.TryAdd(mr, meshList);
                        if (add)
                        {
                            renderableSet.Add(mr);
                        }


                        if (Config.SoftRenderer && add)
                        {
                            if (Owner == null)
                            {
                                treeMesh.Add(mr, mr.bounds);
                            }
                            else
                            {
                                Owner.treeMesh.Add(mr, mr.bounds);
                            }
                        }
                    }
                }
            }
            return(meshList);
        }
コード例 #19
0
 public void AddObject(T obj, Bounds bounds)
 {
     m_AllObjects.Add(obj);
     m_Octree.Add(obj, bounds);
 }