コード例 #1
0
ファイル: MQuadTree.cs プロジェクト: pumachen/Unity-MPipeline
        public void Dispose()
        {
            if (lodLevel == MTerrain.current.lodOffset)
            {
                var loadCommand = new MTerrain.MaskLoadCommand
                {
                    load = false,
                    pos  = rootPos
                };
                MTerrain.current.maskLoadList.Add(loadCommand);
                lock (MTerrain.current)
                {
                    MTerrain.current.boundBoxLoadList.Add(loadCommand);
                }
            }
            if (MTerrain.current != null)
            {
                if (isRendering)
                {
                    int2 startIndex = VirtualTextureIndex;
                    MTerrain.current.loadDataList.Add(new TerrainLoadData
                    {
                        ope        = TerrainLoadData.Operator.Unload,
                        startIndex = startIndex
                    });
                }
                isRendering = false;
            }
            else
            {
                m_isRendering = false;
            }

            if (leftDown != null)
            {
                leftDown->Dispose();
                leftUp->Dispose();
                rightDown->Dispose();
                rightUp->Dispose();
                UnsafeUtility.Free(leftDown, Allocator.Persistent);
                leftDown  = null;
                leftUp    = null;
                rightDown = null;
                rightUp   = null;
            }
        }
コード例 #2
0
ファイル: MQuadTree.cs プロジェクト: pumachen/Unity-MPipeline
        public TerrainQuadTree(int parentLodLevel, LocalPos sonPos, int2 parentPos, int2 parentRenderingPos, double worldSize, double3 maskScaleOffset, int2 rootPos)
        {
            toPoint        = 0;
            initializing   = true;
            separate       = false;
            dist           = 0;
            isInRange      = false;
            this.worldSize = worldSize;
            distOffset     = MTerrain.current.terrainData.lodDeferredOffset;
            m_isRendering  = false;
            lodLevel       = parentLodLevel + 1;
            leftDown       = null;
            leftUp         = null;
            rightDown      = null;
            rightUp        = null;
            localPosition  = parentPos * 2;
            switch (sonPos)
            {
            case LocalPos.LeftUp:
                localPosition += int2(0, 1);
                break;

            case LocalPos.RightDown:
                localPosition += int2(1, 0);
                break;

            case LocalPos.RightUp:
                localPosition += 1;
                break;
            }
            int decalLayer = lodLevel - MTerrain.current.decalLayerOffset;

            decalMask = decalLayer < 0 ? (LayerMask)0 : MTerrain.current.terrainData.allDecalLayers[decalLayer];
            if (lodLevel >= MTerrain.current.lodOffset)
            {
                //Larger
                if (lodLevel > MTerrain.current.lodOffset)
                {
                    double subScale = maskScaleOffset.x * 0.5;
                    renderingLocalPosition = parentRenderingPos * 2;
                    double2 offset = maskScaleOffset.yz;
                    switch (sonPos)
                    {
                    case LocalPos.LeftUp:
                        offset += double2(0, subScale);
                        renderingLocalPosition += int2(0, 1);
                        break;

                    case LocalPos.RightDown:
                        offset += double2(subScale, 0);
                        renderingLocalPosition += int2(1, 0);
                        break;

                    case LocalPos.RightUp:
                        offset += subScale;
                        renderingLocalPosition += 1;
                        break;
                    }
                    this.maskScaleOffset = double3(subScale, offset);
                    this.rootPos         = rootPos;
                }
                //Equal
                else
                {
                    this.rootPos           = localPosition;
                    this.maskScaleOffset   = maskScaleOffset;
                    renderingLocalPosition = 0;
                    var loadCommand = new MTerrain.MaskLoadCommand
                    {
                        load = true,
                        pos  = this.rootPos
                    };
                    MTerrain.current.maskLoadList.Add(loadCommand);
                    lock (MTerrain.current)
                    {
                        MTerrain.current.boundBoxLoadList.Add(loadCommand);
                    }
                }
            }
            else
            {
                this.rootPos           = localPosition;
                renderingLocalPosition = parentRenderingPos;
                this.maskScaleOffset   = maskScaleOffset;
            }
        }