예제 #1
0
    private void Init()
    {
        _cubes = GetChildrenByDepth(this.gameObject, 0);
        Debug.Log(_cubes.Length);
        CubeAsset.Settings settings = new CubeAsset.Settings();
        settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(1, 1, 1), NvBlastChunkDesc.Flags.NoFlags));
        settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(2, 2, 2), NvBlastChunkDesc.Flags.SupportFlag));
        settings.extents      = new Vector3(10, 10, 10);
        settings.staticHeight = 1.0f;

        _thisCubeAsset = CubeAsset.generate(settings);

        NvBlastAssetDesc desc = _thisCubeAsset.solverAssetDesc;

        _blastAsset  = new NvBlastAsset(desc);
        _blastFamily = new NvBlastFamily(_blastAsset);

        NvBlastActorDesc actorDesc = new NvBlastActorDesc();

        actorDesc.uniformInitialBondHealth = 1.0f;
        actorDesc.uniformInitialLowerSupportChunkHealth = 1.0f;
        var actor = new NvBlastActor(_blastFamily, actorDesc);

        OnActorCreated(actor, Vector3.zero, Quaternion.identity);

        // Reserved buffers
        _fractureBuffers = new NvBlastFractureBuffers();
        _fractureBuffers.chunkFractures = Marshal.AllocHGlobal((int)desc.chunkCount * Marshal.SizeOf(typeof(NvBlastChunkFractureData)));
        _fractureBuffers.bondFractures  = Marshal.AllocHGlobal((int)desc.bondCount * Marshal.SizeOf(typeof(NvBlastBondFractureData)));
        _leafChunkCount  = (uint)_blastAsset.leafChunkCount;
        _newActorsBuffer = Marshal.AllocHGlobal((int)_leafChunkCount * Marshal.SizeOf(typeof(IntPtr)));
    }
예제 #2
0
    private void generateCity()
    {
        const int BUILDING_TYPE_COUNT = 5;
        Vector3   BUILDING_MIN_SIZE   = new Vector3(10, 10, 10);
        Vector3   BUILDING_MAX_SIZE   = new Vector3(50, 200, 50);

        List <CubeAsset> buildingTypes = new List <CubeAsset>(BUILDING_TYPE_COUNT);

        for (int i = 0; i < BUILDING_TYPE_COUNT; ++i)
        {
            CubeAsset.Settings settings = new CubeAsset.Settings();
            settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(1, 1, 1), NvBlastChunkDesc.Flags.NoFlags));
            settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(1, 2, 1), NvBlastChunkDesc.Flags.NoFlags));
            settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(2, 3, 2), NvBlastChunkDesc.Flags.NoFlags));
            settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(2, 2, 2), NvBlastChunkDesc.Flags.SupportFlag));
            settings.extents      = new Vector3(Random.Range(BUILDING_MIN_SIZE.x, BUILDING_MAX_SIZE.x), Random.Range(BUILDING_MIN_SIZE.y, BUILDING_MAX_SIZE.y), Random.Range(BUILDING_MIN_SIZE.z, BUILDING_MAX_SIZE.z));
            settings.staticHeight = 10.0f;

            CubeAsset cubeAsset = CubeAsset.generate(settings);

            buildingTypes.Add(cubeAsset);
        }

        int totalBuildings = 0;

        const float CITY_HALF_SIZE = 200.0f;
        const float SPARSITY       = 30.0f;
        //razz
        //const int BUILDING_COUNT_MAX = 20;
        const int BUILDING_COUNT_MAX = 0;
        Vector2   pos          = new Vector2(-CITY_HALF_SIZE, -CITY_HALF_SIZE);
        float     buildingYMax = 0.0f;

        while (pos.y < CITY_HALF_SIZE && totalBuildings < BUILDING_COUNT_MAX)
        {
            // random jump
            pos.x += Random.Range(0.0f, SPARSITY);
            if (pos.x > CITY_HALF_SIZE)
            {
                pos.x        = -CITY_HALF_SIZE;
                pos.y       += buildingYMax + Random.Range(0.0f, SPARSITY);
                buildingYMax = 0.0f;
                continue;
            }

            // random bulding type spawn
            int       type       = Random.Range(0, buildingTypes.Count);
            var       cubeFamily = (new GameObject("Cube Actor #" + type)).AddComponent <CubeFamily>();
            CubeAsset asset      = buildingTypes[type];
            cubeFamily.transform.localPosition = new Vector3(pos.x, asset.extents.y / 2.0f, pos.y);
            pos.x       += asset.extents.x;
            buildingYMax = Mathf.Max(buildingYMax, asset.extents.z);
            cubeFamily.Initialize(asset);
            totalBuildings++;
        }
    }
 private void Init()
 {
     CubeAsset.Settings settings = new CubeAsset.Settings();
     //First depth for first state, so it will be unfractred (1,1,1)
     settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(1, 1, 1), NvBlastChunkDesc.Flags.NoFlags));
     //Second depth for first fracture, so it will fractured by 2 per axis. You can add more depths or increase this depths count.
     settings.depths.Add(new CubeAsset.DepthInfo(new Vector3(2, 2, 2), NvBlastChunkDesc.Flags.SupportFlag));
     //this is size
     settings.extents = new Vector3(10, 10, 10);
     //this is static parts of object, so 1.0 means first row will be static.
     settings.staticHeight = 1.0f;
     _thisCubeAsset        = CubeAsset.generate(settings);
     _objectToBlastFamily.Initialize(_thisCubeAsset);
     _objectToBlastFamily.transform.localPosition = this.transform.localPosition;
 }