コード例 #1
0
        public SingleScene(string path, string name, Index index, byte[] data = null, World owner = null) :
            base(index, data, owner)
        {
#if UNITY_EDITOR
            IsPrepared    = false;
            IsFinish      = false;
            curBakeVolume = 0;

            if (Config.SoftRenderer)
            {
                _renderer = new SoftRenderer();
            }
            else
            {
                _renderer = new MinRenderer();
            }
#endif

            tree = null;

            Path = path;
            Name = name;

            renderableSet = new RenderableObjectSet(this);

            treeMesh = null;

            _neighborMaxObjIdTable = null;

            if (owner != null)
            {
                var streamScene = owner as MultiScene;
                streamScene.GetMaxGUID(index.x, index.y);
            }
        }
コード例 #2
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;
        }
    }
コード例 #3
0
        public override void Unload()
        {
            volumelList.Clear();
            renderableSet.Clear();
            cellMap.Clear();

            tree = new BoundsOctree <Cell>();
        }
コード例 #4
0
 public void setUpEnergyContent()
 {
     primeLanding     = new BoundsOctree <hotspot>(oneMeterMemoryDistance, _thisT.position, minLandingSize, 1);
     AveragedHotspots = new BoundsOctree <hotspot>(oneMeterMemoryDistance, _thisT.position, 1, 1);
     //InvokeRepeating("RefreshMemory", 1, 0.1f);
     InvokeRepeating("FindLanding", 1, 0.1f);
     InvokeRepeating("GetBestLanding", 10, 10);
 }
コード例 #5
0
 public void Load()
 {
     using (var ocReader = new OCDataReader(GetOCDataFilePath()))
     {
         tree = new BoundsOctree <Cell>();
         LoadBlock(ocReader, 0);
     }
     RuntimeGetRenderableObjs();
 }
コード例 #6
0
ファイル: OctreeReader.cs プロジェクト: aofg/volumetric-map
        public OctreeReader(BoundsOctree <VolumetricAssetOctreeNode> octree)
        {
            // Create a dispose sentinel to track memory leaks. This also creates the AtomicSafetyHandle
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, 0, Allocator.TempJob);
#endif
            // Initialize the reference
            _octree = octree;
        }
コード例 #7
0
    private void Awake()
    {
        RecalculateBorders();

        _effectors    = new BoundsOctree <WindEffector>(8000f, Vector3.zero, 250f, 1.2f);
        _queryResults = new List <WindEffector>(8);

        _perlin = new Perlin(1234);
    }
コード例 #8
0
        protected override void OnCreateManager()
        {
            var size = new float3(32, 6, 32);

            worldBounds = new Bounds(size * 0.5f, size);

            octree        = new BoundsOctree <VolumetricAssetOctreeNode>(32f, size * 0.5f, 1f, 1f);
            knownEntities = new HashSet <Entity>();
        }
コード例 #9
0
        public override void Load(byte[] ocData, int blockIndex = 0)
        {
            using (var ocReader = new OCDataReader(ocData))
            {
                tree = new BoundsOctree <Cell>();
                LoadBlock(ocReader, blockIndex);
            }

            RuntimeGetRenderableObjs();
        }
コード例 #10
0
        public void TestLoad()
        {
            Open(OpenSceneMode.Single);
            using (var ocReader = new OCDataReader(GetOCDataFilePath()))
            {
                tree = new BoundsOctree <Cell>();
                LoadBlock(ocReader, 0);
            }

            RuntimeGetRenderableObjs();
        }
コード例 #11
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);
            }
        }
コード例 #12
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"));
    }
コード例 #13
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));
    }
コード例 #14
0
    private void SetupFishies()
    {
        int fishCount = 0;

        foreach (FishType ft in fishTypes)
        {
            fishCount += ft.count;
        }
        fishies       = new List <FishInfo> (fishCount);
        scratchList   = new List <FishInfo> (fishCount);
        fishContainer = new GameObject("fishes - " + gameObject.name);
        fishBounds    = new Bounds(Vector3.zero, new Vector3(0.2f, 0.2f, 0.2f));        //octree needs some fish size, values don't matter much
        octree        = new BoundsOctree <FishInfo> (schoolWidth, Vector3.zero, 0.1f, 1);

        float r = Mathf.Max(radiusOfOrientation, radiusOfRepulsion);

        collideBounds = new Bounds(Vector3.zero, new Vector3(r, r, r));
    }
コード例 #15
0
 public void ApplyColorSpace(BoundsOctree <Color> colorMap)
 {
     results.Clear();
     for (int i = 0; i < particle_count; i++)
     {
         colorMap.GetColliding(results, new Bounds(particles[i].position, particles[i].startSize * Vector3.one));
         if (results.Count > 0)
         {
             Color c = results[0];
             for (int j = 1; j < results.Count; j++)
             {
                 c += results[j];
             }
             particles[i].startColor = c;
         }
     }
     OnParticlesUpdated();
 }
コード例 #16
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);
    }
コード例 #17
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();
    }
コード例 #18
0
        public MultiScene(string path, string namePattern, int tileDimension, int tileSize, byte[] data = null)
        {
#if UNITY_EDITOR
            curBakeScene = 0;
            _window      = null;

            treeMesh = null;
            if (Config.SoftRenderer)
            {
                treeMesh = new BoundsOctree <MeshRenderer>();
            }
#endif
            _maxIDs = new int[tileDimension, tileDimension];
            for (int i = 0; i < TileDimension; i++)
            {
                for (int j = 0; j < TileDimension; j++)
                {
                    _maxIDs[i, j] = SingleScene.InvalidID;
                }
            }

            Path        = path;
            NamePattern = namePattern;

            _tileDimension = tileDimension;
            _tileSize      = tileSize;
            _data          = data;


            SetWorldLimits(0, _tileDimension * _tileSize, 0, _tileDimension * tileSize, _tileDimension, _tileDimension);

            for (int x = 0; x < tileDimension; ++x)
            {
                for (int y = 0; y < tileDimension; ++y)
                {
                    var sceneName = GetSceneName(x, y);
                    _sceneName2Index.Add(sceneName, new Index(x, y));
                }
            }
        }
コード例 #19
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);
        }
コード例 #20
0
    public void Update()
    {
        if (boundsOctree == null)
        {
            boundsOctree = BoidsArea.getBoundsOctree( transform.position);

            if (boundsOctree == null)
            {
                outsideBounds = true;
                gotBounds = false;

            }
        }

        if (boundsOctree != null)
        {
            if (!boundsOctree.isPointInside(transform.position) || boundsOctree.Obstacle)
            {
                boundsOctree = null;
            }
            else
            {
                oldPos = transform.position;

            }
            outsideBounds = false;
        }
        if (outsideBounds)
        {
            schooling.Overridden = true;
            fishMove.targetDirection = oldPos -transform.position;
            fishMove.moveDirection = fishMove.targetDirection;

        }
        else
        {
            schooling.Overridden = false;
        }
    }
コード例 #21
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);
    }
コード例 #22
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;
        }
コード例 #23
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;
            }
        }
    }
コード例 #24
0
    /// <summary>
    /// Apply a spatial color mapping to the points in the point cloud.
    /// </summary>
    /// <param name="colorMap">The bounding-box based octree defining the colors distribution of the space.</param>
    public void ApplyColorSpace(BoundsOctree <Color> colorMap)
    {
        // Search the octree for each particle in the point cloud.
        for (int i = 0; i < particle_count; i++)
        {
            // Search the octree using the current point.
            results.Clear();
            colorMap.GetColliding(results, new Bounds(particles[i].position, particles[i].startSize * Vector3.one));

            // Average the results.
            if (results.Count > 0)
            {
                Color c = results[0];
                for (int j = 1; j < results.Count; j++)
                {
                    c += results[j];
                }
                particles[i].startColor = c / results.Count;
            }
        }

        // Trigger particle system refresh.
        OnParticlesUpdated();
    }
コード例 #25
0
    public BoundsOctree GetCommonAncestor(BoundsOctree cell, int xDiff, int yDiff, int zDiff)
    {
        BoundsOctree c = cell;

        while (c.parentOctree != null && ((xDiff & (1 << c.levelDepth))>0
            ||  (yDiff & (1 << c.levelDepth))>0
            ||  (zDiff & (1 << c.levelDepth))>0))
        {
            c = c.parentOctree;
        }
        return c;
    }
コード例 #26
0
    //needs heavy optimization, creating too many subs
    public void GetBounds(bool createdRecursively, List<BoundsOctree> foundBounds,Vector3 point,float radius,ref int octreesCreated)
    {
        octreesCreated += 0;
        if (BoidsArea.fastObstacle && Obstacle)
        {

            return;
        }

        if (IntersectSphere(point, radius))
        {

            //create children
            if (!isSphereOverlapCorner(point, radius))
            {
                if (subOctrees == null && levelDepth >= 1)
                {
                    //create children.
                    subOctrees = new BoundsOctree[8];
                    for (int i = 0; i < 8; i++)
                    {
                        subOctrees[i] = new BoundsOctree(this, i, "Name", size * 0.5f, position, levelDepth - 1, relatedOctrees);
                        subOctrees[i].Empty = Empty;
                    }
                    foreach (var sub in subOctrees)
                    {
                        sub.RefreshNeighbors(); // this one should be able to be moved down to "check children"
                    }

                }

                //check children
                if (subOctrees != null)
                {
                    bool AllSubsObstacled = true;

                    foreach (var sub in subOctrees)
                    {
                        sub.GetBounds(true, foundBounds, point, radius, ref octreesCreated);
                        if (!sub.Obstacle || !sub.Empty)
                        {
                            AllSubsObstacled = false;
                        }

                    }
                    if (AllSubsObstacled) //lets clean subs and have this be the end of the branch
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            subOctrees[i].ClearOctree();
                            subOctrees[i] = null;
                        }
                        octreesCreated += 8;

                        subOctrees = null;
                        RefreshNeighbors();
                    }
                    else
                    {
                        neighbors = null;
                        foreach (var sub in subOctrees)
                        {
                            //sub.RefreshNeighbors();
                            if (sub.Obstacle)
                            {
                                if (!foundBounds.Contains(sub))
                                    foundBounds.Add(sub);
                            }
                        }
                    }
                }
            }

            if(subOctrees==null)
            {
                Obstacle = true;
                if (!createdRecursively)
                {
                    if (!foundBounds.Contains(this))
                        foundBounds.Add(this);
                }
            }

        }
    }
コード例 #27
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);
            }
        }
コード例 #28
0
    Vector3 getFaceDirection(Vector3 point,BoundsOctree bo)
    {
        Vector3 dir = new Vector3();
        if (point.y >= bo.top.y)
        {
            dir.y = 1;
        }
        else if ( point.y < bo.bottom.y)
        {
            dir.y = -1;
        }

        if (point.x >= bo.east.x )
        {
            dir.x = 1;
        }
        else if ( point.x < bo.west.x)
        {
            dir.x = -1;
        }

        if (point.z >= bo.north.z )
        {
            dir.z = 1;
        }
        else if ( point.z < bo.south.z)
        {
            dir.z = -1;
        }
        return dir;
    }
コード例 #29
0
 private void InitVirtualSpace()
 {
     _virtualSpace = new BoundsOctree <RoomPrototype>(15, Vector3.zero, 1, 1.25f);
 }
コード例 #30
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"));
    }
コード例 #31
0
ファイル: Simulation.cs プロジェクト: skasteve/TowerDefense
 public Simulation(int seed, Plane goal)
 {
     Goal    = goal;
     randGen = new MersenneTwister(seed);
     Octtree = new BoundsOctree <IOctreeObject>(1000.0f, Vector3.zero, 10.0f, 1);
 }
コード例 #32
0
ファイル: BoidsArea.cs プロジェクト: pbostrm/showcase_u_pelle
    public void LoadBounds()
    {
        DebugOutput.Shout("Starting BoundsOctrees test");
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();

        DebugOutput.Shout("Testing LoadingBounds");
        string fileName = "OctreeData/" + BoundsName;

        TextAsset ta = (TextAsset)Resources.Load(fileName);
        BinaryReader br = new BinaryReader(new MemoryStream(ta.bytes));
        DebugOutput.Shout("bounds were created: " +br.ReadString());
        bounds = new BoundsOctree(null, 0, BoundsName, boundsSize, transform.position, br.ReadInt32(), null);

        bounds.CreateFromStream(br);

        foreach (var relatedOctree in bounds.relatedOctrees)
        {
            relatedOctree.RefreshNeighbors();
        }
        BoundsOctree origoBound = bounds.GetBound(true, transform.position + startingPoint);
        if (origoBound != null)
        {
            origoBound.EstablishRelations();
        }
        else
        {
            DebugOutput.Shout("Origopoint is unreachable.");
        }
        stopWatch.Stop();
        DebugOutput.Shout("Finished Loading bounds in "+stopWatch.ElapsedMilliseconds +" milliseconds.");
        int cnt = 0;
        foreach (var relatedBounds in bounds.relatedOctrees)
        {
            if (relatedBounds.Empty && relatedBounds.Related)
            {
                cnt++;
            }
        }
        DebugOutput.Shout("finished bounds in " + (stopWatch.ElapsedMilliseconds) + ", a total of " + bounds.relatedOctrees.Count + " octrees remains, of which " + cnt + " is traversable");
    }
コード例 #33
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));
            }
        }
コード例 #34
0
    public BoundsOctree(BoundsOctree _parent, int _cornerID, string _name, float _size, Vector3 _pos, int _maxLevelDepth,List<BoundsOctree> relatedOcs)
    {
        if (relatedOcs == null)
        {
            relatedOctrees = new List<BoundsOctree>();
            relatedOctrees.Add(this);
        }
        else
        {
            relatedOctrees = relatedOcs;
            relatedOctrees.Add(this);
        }
        parentOctree = _parent;
        cornerID = _cornerID;

        levelDepth = _maxLevelDepth;
        size = _size;
        if (parentOctree != null)
        {
            position = parentOctree.subCornerCenter[cornerID];

            binaryLocation_X = parentOctree.binaryLocation_X;
            binaryLocation_Y = parentOctree.binaryLocation_Y;
            binaryLocation_Z = parentOctree.binaryLocation_Z;
            if (cornerID % 2 != 0)
            {
                binaryLocation_X += (int) Math.Pow(2, levelDepth);
            }
            if (cornerID > 3)
            {
                binaryLocation_Y += (int)Math.Pow(2, levelDepth);

            }
            if (cornerID == 2 || cornerID == 3 || cornerID == 6 || cornerID == 7)
            {
                binaryLocation_Z += (int)Math.Pow(2, levelDepth);
            }
            maxLevelDepth = parentOctree.maxLevelDepth;
        }
        else
        {
            maxLevelDepth = levelDepth;

            position = _pos;
            binaryLocation_X += (int)Math.Pow(2, levelDepth);
            binaryLocation_Y += (int)Math.Pow(2, levelDepth);
            binaryLocation_Z += (int)Math.Pow(2, levelDepth);
        }

        subCornerCenter = new Vector3[8];
        subCornerCenter[0] = new Vector3(-0.5f, -0.5f, -0.5f) * size + position;
        subCornerCenter[1] = new Vector3(0.5f, -0.5f, -0.5f) * size + position;
        subCornerCenter[2] = new Vector3(-0.5f, -0.5f, 0.5f) * size + position;
        subCornerCenter[3] = new Vector3(0.5f, -0.5f, 0.5f) * size + position;
        subCornerCenter[4] = new Vector3(-0.5f, 0.5f, -0.5f) * size + position;
        subCornerCenter[5] = new Vector3(0.5f, 0.5f, -0.5f) * size + position;
        subCornerCenter[6] = new Vector3(-0.5f, 0.5f, 0.5f) * size + position;
        subCornerCenter[7] = new Vector3(0.5f, 0.5f, 0.5f) * size + position;

        corners = new Vector3[8];
        corners[0] = new Vector3(-1f, -1f, -1f) * size + position;
        corners[1] = new Vector3(1f, -1f, -1f) * size + position;
        corners[2] = new Vector3(-1f, -1f, 1f) * size + position;
        corners[3] = new Vector3(1f, -1f, 1f) * size + position;
        corners[4] = new Vector3(-1f, 1f, -1f) * size + position;
        corners[5] = new Vector3(1f, 1f, -1f) * size + position;
        corners[6] = new Vector3(-1f, 1f, 1f) * size + position;
        corners[7] = new Vector3(1f, 1f, 1f) * size + position;
    }
コード例 #35
0
    public BoundsOctree LocateNeighbor(BoundsOctree source, short _x, short _y, short _z)
    {
        int binaryCellSize = 1 << levelDepth;

        int xLoc = binaryLocation_X;
        int yLoc = binaryLocation_Y;
        int zLoc = binaryLocation_Z;

        if ((binaryLocation_X + binaryCellSize) * _x < (1 << (maxLevelDepth + 1)) &&
            (binaryLocation_X + (1 << maxLevelDepth) * _x) > 0)
        {
            if(_x == -1)
            {
                xLoc = binaryLocation_X - 0x00000001;
            }
            else
            {
                xLoc += binaryCellSize*_x;
            }

            if ((binaryLocation_Y + binaryCellSize) * _y < (1 << (maxLevelDepth + 1)) &&
                (binaryLocation_Y + (1 << maxLevelDepth) * _y) > 0)
            {
                if (_y == -1)
                {
                    yLoc = binaryLocation_Y - 0x00000001;
                }
                else
                {
                    yLoc += binaryCellSize*_y;
                }

                if ((binaryLocation_Z + binaryCellSize) * _z < (1 << (maxLevelDepth + 1)) &&
                    (binaryLocation_Z + (1 << maxLevelDepth) * _z) > 0)
                {
                    if (_z == -1)
                    {
                        zLoc = binaryLocation_Z - 0x00000001;
                    }
                    else
                    {
                        zLoc += binaryCellSize*_z;
                    }
                    GetCommonAncestor(this, binaryLocation_X ^ xLoc, binaryLocation_Y ^ yLoc, binaryLocation_Z ^ zLoc).
                    AddToNeighbors(source,xLoc, yLoc, zLoc);
                }
            }
        }
        return null;
    }
コード例 #36
0
    public void Update()
    {
        if (BoidsArea.boundsCollection != null)
        {

            currentBound = BoidsArea.boundsCollection[0].GetBound(transform.position);
        }
    }
コード例 #37
0
 public void AddNeighbor(BoundsOctree neighbor)
 {
     if (neighbor == null|| neighbor == this)
     {
         return;
     }
     if (neighbors == null)
     {
         neighbors = new List<BoundsOctree>();
     }
     if (!neighbors.Contains(neighbor))
     {
         neighbors.Add(neighbor);
     }
 }
コード例 #38
0
    public void AddToNeighbors(BoundsOctree source, int targetXLoc, int targetYLoc, int targetZLoc)
    {
        /* if
        * you have suboctrees lower than the asked for target it will get all the nodes that
        * neighbor it, by comparing the coordinates we create a filter, i wish i could make this a little bit more automated. but it iss friggin fast anyway.*/
        if (source == null)
        {
            return;
        }
        if (subOctrees == null) // (subOctrees == null && Empty) would remove nonEmpty objects from neighbor lists... depending on what you want to do with the octree.
        {
            source.AddNeighbor(this);
        }
        else
        {
            int childBranchBit = 1 << (levelDepth - 1);
            int childIndex;
            if (source.levelDepth >= levelDepth &&subOctrees!=null)
            {
                int binaryCellSize = 1 << levelDepth;
                bool x = (targetXLoc < source.binaryLocation_X || targetXLoc >= source.binaryLocation_X + binaryCellSize);
                bool y = (targetYLoc < source.binaryLocation_Y || targetYLoc >= source.binaryLocation_Y + binaryCellSize);
                bool z = (targetZLoc < source.binaryLocation_Z || targetZLoc >= source.binaryLocation_Z + binaryCellSize);

                if(x&&y&&z)
                {
                    childIndex =
                    (((targetXLoc & childBranchBit) >> levelDepth - 1)) +
                    (((targetYLoc & childBranchBit) >> levelDepth - 1) * 4) +
                    (((targetZLoc & childBranchBit) >> levelDepth - 1) * 2);
                    subOctrees[childIndex].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                }
                else if (!x && !z)
                {

                    int offset = (((targetYLoc & childBranchBit) >> levelDepth - 1)*4);
                    subOctrees[0 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[1 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[2 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[3 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);

                }
                else if(!x && !y)
                {
                    int offset = (((targetZLoc & childBranchBit) >> levelDepth - 1) * 2);
                    subOctrees[0 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[1 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[4 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[5 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                }
                else if (!y && !z)
                {
                    int offset = (((targetXLoc & childBranchBit) >> levelDepth - 1) );
                    subOctrees[0 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[2 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[4 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[6 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                }
                else if(!x)
                {
                    int offset = (((targetYLoc & childBranchBit) >> levelDepth - 1) * 4) +
                         (((targetZLoc & childBranchBit) >> levelDepth - 1) * 2);

                    subOctrees[0 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[1 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);

                }
                else if(!y)
                {
                    int offset = (((targetXLoc & childBranchBit) >> levelDepth - 1)) +
                         (((targetZLoc & childBranchBit) >> levelDepth - 1) * 2);
                    subOctrees[0 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[4 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                }
                else //z
                {
                    int offset = (((targetXLoc & childBranchBit) >> levelDepth - 1)) +
                                 (((targetYLoc & childBranchBit) >> levelDepth - 1)*4);
                    subOctrees[0 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                    subOctrees[2 + offset].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);
                }

            }
            else
            {

                if (subOctrees != null)
                {
                    childIndex =
                    (((targetXLoc & childBranchBit) >> levelDepth - 1)) +
                    (((targetYLoc & childBranchBit) >> levelDepth - 1) * 4) +
                    (((targetZLoc & childBranchBit) >> levelDepth - 1) * 2);
                    if (subOctrees[childIndex] == null)
                    {
                        int subsMissing = 0;
                        foreach (var sub in subOctrees)
                        {
                            if (sub == null)
                            {
                                subsMissing++;
                            }
                        }
                        DebugOutput.Shout("SubOctree has been deleted somewhere : "+subsMissing);
                    }
                    subOctrees[childIndex].AddToNeighbors(source, targetXLoc, targetYLoc, targetZLoc);

                }

            }

        }
    }
コード例 #39
0
    public void Update()
    {
        if(boundsOctree==null)
        {
            boundsOctree = BoidsArea.getBoundsOctree(transform.position);
        }

        if (boundsOctree != null)
        {
            if(!boundsOctree.isPointInside(transform.position))
            {
                boundsOctree = BoidsArea.getBoundsOctree(transform.position);
            }

            if(boundsOctree !=null && boundsOctree.Border)
            {
                if (boundsOctree.neighbors != null)
                {
                    RepelVelocity = Vector3.zero;
                    gotObstacles = false;
                    foreach (var neighBor in boundsOctree.neighbors)
                    {
                        if (!neighBor.Empty || neighBor.Obstacle)
                        {
                            Vector3 v1 = (boundsOctree.position - neighBor.position);
                            Vector3 v2 = getFaceDirection((v1 * neighBor.size * 2)+boundsOctree.position, neighBor);

                            Vector3 facePoint = boundsOctree.position + (-v2 * boundsOctree.size);
                            //getting corner
                            Vector3 v2isOne;
                            v2isOne.x = v2.x * v2.x;
                            v2isOne.y = v2.y * v2.y;
                            v2isOne.z = v2.z * v2.z;

                            if (v2isOne == Vector3.one) // special case if its a corner.
                            {
                                Vector3 repelDir = facePoint - transform.position;
                                if (repelDir.sqrMagnitude <= maximumObstacleDistance * maximumObstacleDistance)
                                {
                                    RepelVelocity += repelDir.normalized * (1.0f - (repelDir.magnitude / maximumObstacleDistance));
                                    gotObstacles = true;

                                }
                            }
                            else
                            {
                                Plane p1 = new Plane((facePoint - boundsOctree.position).normalized, facePoint);
                                float distance = p1.GetDistanceToPoint(transform.position);

                                Debug.DrawLine(facePoint, transform.position, Color.yellow);

                                if (distance < maximumObstacleDistance)
                                {
                                    Debug.DrawLine(transform.position, transform.position - (p1.normal * distance), Color.red);

                                    gotObstacles = true;

                                    RepelVelocity += v2.normalized * (1.0f - (distance / maximumObstacleDistance));
                                }

                            }
                        }
                    }
                    if (gotObstacles)
                    {
                        schooling.RepelVelocity = RepelVelocity;
                        schooling.GroupUpVelocity = Vector3.zero;
                        schooling.MatchVelocity = Vector3.zero;

                    }

                }
            }
        }
    }
コード例 #40
0
 public void CheckBounds(LayerMask obstacleMask)
 {
     /*1.732 is the distance from center of a 2 unit wide cube's center to one of the corners, ish.
         * this is because i use Unity's own physics to determine if there is any obstacles(static not my own dynamic)
      * and the easiest way of doing that is by doing a cube scan for each node. but unity does not support that, so a sphere would have to do.
      */
     if (Physics.CheckSphere(position, size*1.732f,obstacleMask) )
     {
         if (levelDepth >= 1)
         {
             subOctrees = new BoundsOctree[8];
             bool subsEmpty = true;  // used to check if subs are pointless or not, we dont want more nodes than we need.
             for (int i = 0; i < 8; i++)
             {
                 subOctrees[i] = new BoundsOctree(this, i, "Name", size * 0.5f,
                     position, levelDepth - 1,relatedOctrees);
                 subOctrees[i].CheckBounds(obstacleMask);
                 if (!subOctrees[i].Empty)
                 {
                     subsEmpty = false;
                 }
             }
             if (subsEmpty)
             {
                 for (int i = 0; i < 8; i++)
                 {
                     subOctrees[i] = null;
                 }
                 subOctrees = null;
                 Empty = true;
             }
         }
     }
     else
     {
         Empty = true;
     }
 }
コード例 #41
0
 private void ScanElementsFromSpaces(SpatialElement space, MEPRevitGraph graph, HashSet <int> scannedElements, BoundsOctree <GeometrySegment> geoTree)
 {
 }
コード例 #42
0
    public void CreateFromStream(BinaryReader br)
    {
        Empty = br.ReadBoolean();
        Related = br.ReadBoolean();
        if (br.ReadBoolean())
        {
            subOctrees = new BoundsOctree[8];

            for (int i = 0; i < 8; i++)
            {
                subOctrees[i] = new BoundsOctree(this, i, "Name", size * 0.5f, position, levelDepth - 1, relatedOctrees);
                subOctrees[i].CreateFromStream(br);
            }
        }
    }
コード例 #43
0
ファイル: BoidsArea.cs プロジェクト: pbostrm/showcase_u_pelle
    public void CreateBounds()
    {
        DebugOutput.Shout("Starting BoundsOctrees test");
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();

        Stopwatch stopWatch2 = new Stopwatch();
        stopWatch2.Start();

        bounds = new BoundsOctree(null, 0, BoundsName, boundsSize, transform.position, maxLevels, null);
        bounds.CheckBounds(ObstacleMask);

        stopWatch2.Stop();
        DebugOutput.Shout("created bounds in " + (stopWatch2.ElapsedMilliseconds) + ", a total of " + bounds.relatedOctrees.Count + " octrees were created");

        Stopwatch stopWatch3 = new Stopwatch();
        stopWatch3.Start();
        foreach (var relatedOctree in bounds.relatedOctrees)
        {
            relatedOctree.RefreshNeighbors();
        }
        int oldCnt = bounds.relatedOctrees.Count;
        stopWatch3.Stop();

        DebugOutput.Shout("established neighbors in " + (stopWatch3.ElapsedMilliseconds));

        Stopwatch stopWatch4 = new Stopwatch();
        stopWatch4.Start();

        Stopwatch stopWatch41 = new Stopwatch();
        stopWatch41.Start();
        BoundsOctree origoBound = bounds.GetBound(true,transform.position + startingPoint);
        if (origoBound != null)
        {
            origoBound.EstablishRelations();
        }
        else
        {
            DebugOutput.Shout("Origopoint is unreachable.");
        }
        stopWatch41.Stop();

        DebugOutput.Shout("Established Relations in" + (stopWatch41.ElapsedMilliseconds));

        if (CleanUpBounds)
        {
            Stopwatch stopWatch42 = new Stopwatch();
            stopWatch42.Start();
            bounds.CleanOutUnrelated();
            foreach (var relatedOctree in bounds.relatedOctrees)
            {
                relatedOctree.RefreshNeighbors();
            }
            stopWatch42.Stop();
            DebugOutput.Shout("cleanedoutUnrelated in" + (stopWatch42.ElapsedMilliseconds));

        }

        stopWatch4.Stop();
        DebugOutput.Shout("cleaned up octrees in" + (stopWatch4.ElapsedMilliseconds)
            + ", a total of " + (oldCnt - bounds.relatedOctrees.Count) + "were eliminated");

        int cnt = 0;
        foreach (var relatedBounds in bounds.relatedOctrees)
        {
            if (relatedBounds.Empty && relatedBounds.Related)
            {
                cnt++;
            }
        }
        stopWatch.Stop();
        DebugOutput.Shout("finished bounds in " + (stopWatch.ElapsedMilliseconds)
            + ", a total of " + bounds.relatedOctrees.Count + " octrees remains, of which "
            + cnt + " is traversable");
    }
コード例 #44
0
 public void Initialise(ICollection <Element> geoSerchElements, BoundsOctree <GeometrySegment> geo)
 {
     _geoTree = geo;
 }