Exemple #1
0
    public CreateDataJob(Bounds VolumnBound, int sub, Vector2 PillarSize, float thickness, float serr)
    {
        maxX           = Mathf.CeilToInt(VolumnBound.size.x / PillarSize.x);
        maxZ           = Mathf.CeilToInt(VolumnBound.size.z / PillarSize.y);
        subdivision    = sub;
        center         = new float[] { VolumnBound.center.x, VolumnBound.center.y, VolumnBound.center.z };
        heightValRange = new float[] { VolumnBound.center.y - 0.5f * VolumnBound.size.y,
                                       VolumnBound.center.y + 0.5f * VolumnBound.size.y };
        sliceSize = new float[] { PillarSize.x, PillarSize.y };
        vCheckTop = new Vector3(VolumnBound.center.x - VolumnBound.size.x / 2,
                                VolumnBound.center.y + VolumnBound.size.y / 2 + 10f * thickness,
                                VolumnBound.center.z - VolumnBound.size.z / 2);
        int sliceCount = Mathf.CeilToInt((heightValRange[1] - heightValRange[0]) / thickness);

        sliceCount     = Mathf.Min(sliceCount, ushort.MaxValue);
        heightPerGrade = (heightValRange[1] - heightValRange[0]) / sliceCount;
        QuadTrees      = new QuadTreeBase[maxX * maxZ];
        slopeErr       = serr;
        //
        detailedSize = 1 << subdivision;
        Vector3 checkHalfExtent = new Vector3(sliceSize[0] / 2, thickness, sliceSize[1] / 2);

        checkHalfExtent = 1f / detailedSize * checkHalfExtent;
        mScanner        = new MPUnityHeightScanner(checkHalfExtent);
        //
    }
    private void InitLooseQuadtree()
    {
        if (autoConfig)
        {
            qt = LooseQuadTree <BoidBase> .NewTree(sets.bounds.width, sets.bounds.height, 2);
        }
        else
        {
            qt = new LooseQuadTree <BoidBase>(sets.bounds.width, sets.bounds.height, elementsPerQuad, maxDepth);
        }

        Boid.qt = qt;

        for (int i = 0; i < sets.testElements; ++i)
        {
            Vector3Int pos = new Vector3Int(r.Next(sets.bounds.width), 0, r.Next(sets.bounds.height));
            GameObject go  = Instantiate(boidPrefab, pos, Quaternion.identity);
            go.TryGetComponent(out Boid b);
            b.Init();
            UnityEngine.Profiling.Profiler.BeginSample("Insert boids");
            b.index_TEMP = ((LooseQuadTree <BoidBase>)qt).BulkInsertPoint(b, b.X, b.Y, b.Width, b.Height);
            UnityEngine.Profiling.Profiler.EndSample();
            ++entityCount;
        }
    }
Exemple #3
0
    public void EditorCreateDataEnd()
    {
        if (mCreateDataJob == null || mCreateDataJob.QuadTrees == null)
        {
            return;
        }
        PillarSetting setting = mCreateDataJob.CreateSetting();

        //finaliz the tree data
        for (int i = 0; i < mCreateDataJob.QuadTrees.Length; ++i)
        {
            QuadTreeNodeSerializable node        = (QuadTreeNodeSerializable)mCreateDataJob.QuadTrees[i];
            QuadTreeBase             replaceLeaf = QuadTreeNode.CombineTree(node, 0.5f * mCreateDataJob.sliceSize[0],
                                                                            0.5f * mCreateDataJob.sliceSize[1], mCreateDataJob.heightPerGrade, mCreateDataJob.slopeErr);
            if (replaceLeaf != null)
            {
                mCreateDataJob.QuadTrees[i] = replaceLeaf;
            }
        }
        //
        string path = string.Format("{0}/MightyPillar/Resources/{1}.bytes", Application.dataPath, DataName);

        MPFileUtil.SaveData(path, setting, mCreateDataJob.QuadTrees);
        MPDataDisplayer displayer = gameObject.GetComponent <MPDataDisplayer>();

        if (displayer != null)
        {
            displayer.OnCreatorRegenData();
        }
    }