Exemplo n.º 1
0
 public RawDataResCache(IGraphicsInfra infra, IRawDataResource rawDataResource)
 {
     this.infra           = infra;
     this.rawDataResource = rawDataResource;
     dirty = true;
 }
Exemplo n.º 2
0
 public RawDataResSubrange([NotNull] IRawDataResource rawDataResource, int startOffset, int length)
 {
     RawDataResource = rawDataResource;
     StartOffset     = startOffset;
     Length          = length;
 }
Exemplo n.º 3
0
 public RawDataResSubrange([NotNull] IRawDataResource rawDataResource, int startOffset)
 {
     RawDataResource = rawDataResource;
     StartOffset     = startOffset;
     Length          = rawDataResource.Size - startOffset;
 }
        private unsafe IFlexibleModel CreateModel(IntSize3 size, float cellSize, int numParticles)
        {
            // todo: add a 'IResourceSource.AttachResource(resource)' method
            var vertexPosElemInfo = new [] { new VertexElementInfo(CommonVertexSemantic.Position, 0, CommonFormat.R32G32B32_SFLOAT, 0, sizeof(Vector3)) };
            var resourcePack      = new ResourcePack(ResourceVolatility.Immutable);

            // Bounds
            var bounds         = new Vector3(size.Width * cellSize, size.Height * cellSize, size.Depth * cellSize);
            var boundsVertices = new[]
            {
                new Vector3(0, 0, 0),
                new Vector3(0, bounds.Y, 0),
                new Vector3(bounds.X, bounds.Y, 0),
                new Vector3(bounds.X, 0, 0),
                new Vector3(0, 0, bounds.Z),
                new Vector3(0, bounds.Y, bounds.Z),
                new Vector3(bounds.X, bounds.Y, bounds.Z),
                new Vector3(bounds.X, 0, bounds.Z),
            };
            var boundsIndices = new ushort[]
            {
                0, 1, 1, 2, 2, 3, 3, 0,
                4, 5, 5, 6, 6, 7, 7, 4,
                0, 4, 1, 5, 2, 6, 3, 7
            };
            RawDataResource boundsVertexBuffer;

            fixed(Vector3 *pBoundsVertexData = boundsVertices)
            boundsVertexBuffer = new RawDataResource(ResourceVolatility.Immutable, (IntPtr)pBoundsVertexData, boundsVertices.Length * sizeof(Vector3));

            resourcePack.AddSubresource("BoundsVertexBuffer", boundsVertexBuffer);
            RawDataResource boundsIndexBuffer;

            fixed(ushort *pBoundsIndices = boundsIndices)
            boundsIndexBuffer = new RawDataResource(ResourceVolatility.Immutable, (IntPtr)pBoundsIndices, boundsIndices.Length * sizeof(ushort));

            resourcePack.AddSubresource("BoundsIndexBuffer", boundsIndexBuffer);
            var boundsVertexSet = new FlexibleModelVertexSet(ResourceVolatility.Immutable,
                                                             new [] { boundsVertexBuffer.AsSubrange(), boundsIndexBuffer.AsSubrange() },
                                                             vertexPosElemInfo,
                                                             new VertexIndicesInfo(1, CommonFormat.R16_UINT));

            resourcePack.AddSubresource("BoundsVertexSet", boundsVertexSet);
            var boundsModelPart = new FlexibleModelPart
            {
                VertexSetIndex    = 0,
                PrimitiveTopology = FlexibleModelPrimitiveTopology.LineList,
                ModelMaterialName = "BoundsMaterial",
                IndexCount        = boundsIndices.Length
            };

            // Particles
            particlesBuffer = new RawDataResource(ResourceVolatility.Volatile, numParticles * sizeof(Vector3));
            var pParticlePositions = (Vector3 *)particlesBuffer.Map();

            for (int i = 0; i < fluidSimulation.Particles.Length; i++)
            {
                pParticlePositions[i] = fluidSimulation.Particles[i].Position;
            }
            particlesBuffer.Unmap(true);
            resourcePack.AddSubresource("ParticlesBuffer", particlesBuffer);

            var particlesVertexSet = new FlexibleModelVertexSet(ResourceVolatility.Immutable,
                                                                new [] { particlesBuffer.AsSubrange() },
                                                                vertexPosElemInfo,
                                                                null);

            resourcePack.AddSubresource("ParticlesVertexSet", particlesVertexSet);

            var particlesModelPart = new FlexibleModelPart
            {
                VertexSetIndex    = 1,
                PrimitiveTopology = FlexibleModelPrimitiveTopology.PointList,
                ModelMaterialName = "ParticlesMaterial",
                IndexCount        = numParticles
            };

            var resultModel = new FlexibleModel(ResourceVolatility.Immutable,
                                                new [] { boundsVertexSet, particlesVertexSet },
                                                new [] { boundsModelPart, particlesModelPart },
                                                new Sphere(bounds / 2, bounds.Length() / 2));

            resourcePack.AddSubresource("Model", resultModel);
            return(resultModel);
        }
Exemplo n.º 5
0
 public static RawDataResSubrange GetSubrange(this IRawDataResource dataRes, int startOffset, int length) =>
 new RawDataResSubrange(dataRes, startOffset, length);
Exemplo n.º 6
0
 public static RawDataResSubrange AsSubrange(this IRawDataResource dataRes) =>
 new RawDataResSubrange(dataRes, 0);