Ejemplo n.º 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)));
    }
Ejemplo n.º 2
0
    public NvBlastActor(NvBlastFamily family_, NvBlastActorDesc desc)
    {
        family = family_;

        var scratchSize = NvBlastFamilyGetRequiredScratchForCreateFirstActor(family.ptr, NvBlastWrapper.Log);
        var actor       = NvBlastFamilyCreateFirstActor(family.ptr, desc, NvBlastWrapper.GetScratch((int)scratchSize), NvBlastWrapper.Log);

        Initialize(actor);
    }
Ejemplo n.º 3
0
    public void Initialize(CubeAsset asset)
    {
        // Blast asset creation
        _cubeAsset = asset;

        NvBlastAssetDesc desc = _cubeAsset.solverAssetDesc;

        _blastAsset = new NvBlastAsset(desc);
//        Debug.Log(_blastAsset.leafChunkCount);

        // Actual Cubes
        var cubePrefab = Resources.Load <GameObject>("CubePrefab");

        _cubes = new GameObject[desc.chunkCount];
        for (int i = 0; i < desc.chunkCount; ++i)
        {
            GameObject cube = GameObject.Instantiate <GameObject>(cubePrefab);
            cube.transform.parent        = transform;
            cube.transform.localScale    = _cubeAsset.chunks[i].extents;
            cube.transform.localPosition = _cubeAsset.chunks[i].position;
            cube.transform.localRotation = Quaternion.identity;
            cube.SetActive(false);
            Color color = Color.HSVToRGB(UnityEngine.Random.Range(0f, 1f), 0.42f, 1.0f);
            cube.GetComponent <Renderer>().material.color = color;
            _cubes[i] = cube;
        }

        // First actor
        _blastFamily = new NvBlastFamily(_blastAsset);

        NvBlastActorDesc actorDesc = new NvBlastActorDesc();

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

//        Debug.Log(actor.visibleChunkCount);

        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)));
    }
Ejemplo n.º 4
0
 static extern IntPtr NvBlastFamilyCreateFirstActor(IntPtr family, NvBlastActorDesc desc, IntPtr scratch, NvBlastWrapper.NvBlastLog logFn);