예제 #1
0
        public void tryb_Podstawowy(Collection <Collection <long> > pozycje)
        {
            sprawdzLiczbeMonitorow();
            Surface        s  = sc.CaptureScreen();
            GraphicsStream gs = s.LockRectangle(LockFlags.None);

            kolory.Clear();
            for (int k = 0; k < pozycje.Count; k++)
            {
                kolory.Add(avcs(gs, pozycje[k]));
            }
        }
예제 #2
0
        // --------------------------------------------------------------
        public D3DQuad(bool identity)
        {
            if (!identity)
            {
                if (s_QuadVBNotId == null)
                {
                    VertexTypes.Pos_uv0_uv1[] vertices = new VertexTypes.Pos_uv0_uv1[]
                    {
                        new VertexTypes.Pos_uv0_uv1(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f),
                        new VertexTypes.Pos_uv0_uv1(1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f),
                        new VertexTypes.Pos_uv0_uv1(1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f),

                        new VertexTypes.Pos_uv0_uv1(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f),
                        new VertexTypes.Pos_uv0_uv1(1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f),
                        new VertexTypes.Pos_uv0_uv1(-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f),
                    };

                    int mNumVerts = vertices.Length;

                    s_QuadVBNotId = new VertexBuffer(typeof(VertexTypes.Pos_uv0_uv1), vertices.Length, BRenderDevice.getDevice(), Usage.None, VertexTypes.Pos_uv0_uv1.FVF_Flags, Pool.Managed);

                    GraphicsStream gStream = s_QuadVBNotId.Lock(0, 0, LockFlags.None);
                    gStream.Write(vertices);
                    s_QuadVBNotId.Unlock();
                }
                m_QuadVB = s_QuadVBNotId;
            }
            else
            {
                if (s_QuadVBId == null)
                {
                    VertexTypes.Pos_uv0_uv1[] vertices = new VertexTypes.Pos_uv0_uv1[]
                    {
                        new VertexTypes.Pos_uv0_uv1(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f),
                        new VertexTypes.Pos_uv0_uv1(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f),
                        new VertexTypes.Pos_uv0_uv1(1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f),

                        new VertexTypes.Pos_uv0_uv1(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f),
                        new VertexTypes.Pos_uv0_uv1(1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f),
                        new VertexTypes.Pos_uv0_uv1(0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f),
                    };

                    int mNumVerts = vertices.Length;

                    s_QuadVBId = new VertexBuffer(typeof(VertexTypes.Pos_uv0_uv1), vertices.Length, BRenderDevice.getDevice(), Usage.None, VertexTypes.Pos_uv0_uv1.FVF_Flags, Pool.Managed);

                    GraphicsStream gStream = s_QuadVBId.Lock(0, 0, LockFlags.None);
                    gStream.Write(vertices);
                    s_QuadVBId.Unlock();
                }
                m_QuadVB = s_QuadVBId;
            }
        }
예제 #3
0
        /// <summary>
        /// Crear vertices para la cara Down
        /// </summary>
        private void cargarVerticesDown(GraphicsStream data, int color)
        {
            TgcSceneLoader.DiffuseMapVertex v;
            Vector3 n = new Vector3(0, -1, 0);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X - size.X / 2 - skyEpsilon,
                center.Y - size.Y / 2,
                center.Z + size.Z / 2 + skyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 0;
            v.Tv     = 1;
            data.Write(v);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X - size.X / 2 - skyEpsilon,
                center.Y - size.Y / 2,
                center.Z - size.Z / 2 - skyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 1;
            v.Tv     = 1;
            data.Write(v);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X + size.X / 2 + skyEpsilon,
                center.Y - size.Y / 2,
                center.Z - size.Z / 2 - skyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 1;
            v.Tv     = 0;
            data.Write(v);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X + size.X / 2 + skyEpsilon,
                center.Y - size.Y / 2,
                center.Z + size.Z / 2 + skyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 0;
            v.Tv     = 0;
            data.Write(v);
        }
예제 #4
0
        private static void CopyTextureData(GraphicsStream srcData, int srcWidth, int srcHeight, OpsFormatHelper formatHelp, int srcPitch, GraphicsStream dstData, int dstPitch)
        {
            Byte[] rowData = new Byte[srcWidth * formatHelp.SizeInBytes];
            for (int row = 0; row < srcHeight; row++)
            {
                srcData.Position = row * srcPitch;
                dstData.Position = row * dstPitch;

                srcData.Read(rowData, 0, rowData.Length);
                dstData.Write(rowData, 0, rowData.Length);
            }
        }
예제 #5
0
        static private void OnVertexBufferUpdate(object sender, EventArgs e)
        {
            VertexBuffer   vb   = (VertexBuffer)sender;
            GraphicsStream data = vb.Lock(0, 0, LockFlags.None);

            for (int v = 0; v < billboardVerts.Length; v++)
            {
                data.Write(billboardVerts[v]);
            }

            vb.Unlock();
        }
예제 #6
0
        /// <summary>
        /// Render the textured polygon
        /// </summary>
        /// <param name="device">Device to render onto</param>
        public override void Render(Device device)
        {
            // Get the vertices we will draw
            List <Vector2> vertices = Vertices;

            // Ensure we have at least a triangle
            if (vertices.Count < 3)
            {
                return;
            }

            // Ensure the number of vertices and textures are the same
            System.Diagnostics.Debug.Assert(textureC.Count == vertices.Count);

            if (verticesV == null)
            {
                verticesV = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), // Type
                                             vertices.Count,                               // How many
                                             device,                                       // What device
                                             0,                                            // No special usage
                                             CustomVertex.PositionColoredTextured.Format,
                                             Pool.Managed);
            }

            GraphicsStream gs  = verticesV.Lock(0, 0, 0);    // Lock the background vertex list
            int            clr = color.ToArgb();

            for (int i = 0; i < vertices.Count; i++)
            {
                Vector2 v = vertices[i];
                Vector2 t = textureC[i];
                gs.Write(new CustomVertex.PositionColoredTextured(v.X, v.Y, 0, clr, t.X, t.Y));
            }

            verticesV.Unlock();

            if (transparent)
            {
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend      = Blend.SourceAlpha;
                device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
            }
            device.SetTexture(0, texture);
            device.SetStreamSource(0, verticesV, 0);
            device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            device.DrawPrimitives(PrimitiveType.TriangleFan, 0, vertices.Count - 2);
            device.SetTexture(0, null);

            if (transparent)
            {
                device.RenderState.AlphaBlendEnable = false;
            }
        }
예제 #7
0
 /// <summary>
 /// Override this method to fill the vertex buffer with the appropriate data.  Most nodes
 /// that extend P3Node will need to override this method since their number and type of
 /// vertices will vary.
 /// </summary>
 /// <remarks>
 /// It is not safe to call GetValidVertexBuffer() here, since that method may call
 /// FillVertexBuffer().
 /// </remarks>
 /// <param name="vb">The vertex buffer to fill.</param>
 protected virtual void FillVertexBuffer(VertexBuffer vb)
 {
     // Only fill the vertex buffer if the brush is not null.
     if (Brush != null)
     {
         GraphicsStream stm = vb.Lock(0, 0, 0);
         CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT];
         P3Util.CreateColoredRectangle(colVerts, 0, Bounds, (Brush as SolidBrush).Color.ToArgb());
         stm.Write(colVerts);
         vb.Unlock();
     }
 }
예제 #8
0
 public BonsaiMeshContainer(string xFilePath, string name, MeshData meshData, ExtendedMaterial[] materials,
                            EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
     : base()
 {
     this.Name     = name;
     this.MeshData = meshData;
     this.SetMaterials(materials);
     this.SetEffectInstances(effectInstances);
     this.SetAdjacency(adjacency);
     this.SkinInformation = skinInfo;
     this.xFilePath       = xFilePath;
 }
예제 #9
0
        /// <summary>
        /// This function recreates the buffer automatically following a device reset.
        /// </summary>
        /// <param name="sender">VertexBuffer object is the sender.</param>
        /// <param name="e">Not Used.</param>
        private static void OnVertexBufferCreate(object sender, EventArgs e)
        {
            VertexBuffer   vb   = (VertexBuffer)sender;
            GraphicsStream data = vb.Lock(0, 0, LockFlags.None);

            for (int v = 0; v < 8; v++)
            {
                data.Write(m_BoundingBoxVerts[v]);
            }

            vb.Unlock();
        }
예제 #10
0
        private void OnVertexBufferCreate(object sender, EventArgs e)
        {
            VertexBuffer   vb   = (VertexBuffer)sender;
            GraphicsStream data = vb.Lock(0, 0, LockFlags.Discard);

            for (int v = 0; v < VERTS.Length; v++)
            {
                data.Write(VERTS[v].dxv);
            }

            vb.Unlock();
        }
예제 #11
0
 protected override void LoadFromMicrocode(GraphicsStream microcode)
 {
     // create the new vertex shader
     try
     {
         vertexShader = new VertexShader(device, microcode);
     }
     catch (Exception)
     {
         LogManager.Instance.Write("Error loading microcode for vertex program: {0}", Name);
     }
 }
예제 #12
0
        public void CopyFromRaster(DsRGB565Raster i_raster)
        {
            Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
            int            pitch;
            GraphicsStream gs = this._surface.LockRectangle(this.m_src_rect, LockFlags.None, out pitch);

            Marshal.Copy((short[])i_raster.getBuffer(), 0, (IntPtr)((int)gs.InternalData), this._width * 2 * this._height);

            this._surface.UnlockRectangle();

            return;
        }
예제 #13
0
        /// <summary>
        ///     Crear vertices para la cara Left
        /// </summary>
        private void cargarVerticesLeft(GraphicsStream data, int color)
        {
            TgcSceneLoader.DiffuseMapVertex v;
            var n = new Vector3(0, -1, 0);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                Center.X - Size.X / 2,
                Center.Y + Size.Y / 2 + SkyEpsilon,
                Center.Z - Size.Z / 2 - SkyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 0;
            v.Tv     = 0;
            data.Write(v);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                Center.X - Size.X / 2,
                Center.Y - Size.Y / 2 - SkyEpsilon,
                Center.Z - Size.Z / 2 - SkyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 0;
            v.Tv     = 1;
            data.Write(v);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                Center.X - Size.X / 2,
                Center.Y - Size.Y / 2 - SkyEpsilon,
                Center.Z + Size.Z / 2 + SkyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 1;
            v.Tv     = 1;
            data.Write(v);

            v          = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                Center.X - Size.X / 2,
                Center.Y + Size.Y / 2 + SkyEpsilon,
                Center.Z + Size.Z / 2 + SkyEpsilon
                );
            v.Normal = n;
            v.Color  = color;
            v.Tu     = 1;
            v.Tv     = 0;
            data.Write(v);
        }
예제 #14
0
        public Color GetLightmapTexelColor(int LightmapTextureIndex, int LightmapSubIndex, float u, float v)
        {
            Color clr = Color.HotPink;

            //validate texture indices
            if ((LightmapTextureIndex >= 0) && (LightmapTextureIndex < m_LookupCount))
            {
                if ((LightmapSubIndex >= 0) && (LightmapSubIndex < m_LookupTable[LightmapTextureIndex].TextureList.Length))
                {
                    TextureWithFormat t_data = m_LookupTable[LightmapTextureIndex].TextureList[LightmapSubIndex];

                    int u_index = (int)Math.Round(u * (t_data.Width - 1));
                    int v_index = (int)Math.Round(v * (t_data.Height - 1));
                    //int seekpos = (v_index*t_data.Height + u_index)*2;
                    //int seekpos = (u_index*t_data.Height + v_index)*2;
                    //int seekpos = (u_index*t_data.Width + v_index)*2;
                    int seekpos = (v_index * t_data.Width + u_index) * 2;

                    if ((seekpos > (t_data.TextureDataLength - 2)) || (seekpos < 0))
                    {
                        Trace.WriteLine("tried to find a lightmap pixel outside bounds of texture");
                    }
                    else
                    {
                        if (t_data.Format == 6) //lightmap format is R5G6B5
                        {
                            ushort         pixel;
                            GraphicsStream gs = t_data.texture.LockRectangle(0, LockFlags.None);
                            BinaryReader   br = new BinaryReader(gs);
                            BinaryWriter   bw = new BinaryWriter(gs);
                            br.BaseStream.Seek(seekpos, SeekOrigin.Begin);
                            pixel = br.ReadUInt16();
                            //br.BaseStream.Seek(seekpos, SeekOrigin.Begin);
                            //ushort taco = 0;
                            //bw.Write(taco);
                            t_data.texture.UnlockRectangle(0);
                            //MdxRender.Dev.UpdateTexture(t_data.texture, t_data.texture);

                            //Trace.WriteLine(string.Format("u_index = {0}  v_index = {1}  pixel = {2:X}", u_index, v_index, pixel));

                            //convert pixel into Color
                            int red   = (int)((((pixel & 0xF800) >> 11) / 32f) * 255);
                            int green = (int)((((pixel & 0x07E0) >> 5) / 64f) * 255);
                            int blue  = (int)(((pixel & 0x001F) / 32f) * 255);
                            clr = Color.FromArgb(red, green, blue);
                        }
                    }
                }
            }

            return(clr);
        }
예제 #15
0
        private void CaculateBoundSphere()
        {
            Vector3 center;             //包络球体的中心位置将被抛弃

            GraphicsStream vertexData = vexbuf.Lock(0, 0, LockFlags.NoOverwrite);

            radius = Geometry.ComputeBoundingSphere(
                vertexData,
                vexarray.Length,
                CustomVertex.PositionColoredTextured.Format,
                out center);
            vexbuf.Unlock();
        }
예제 #16
0
 public Bitmap SaveToBitmap(Device device)
 {
     using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono))
     {
         if (bufferSurface == null)
         {
             CreateBufferSurface(device, backbuffer.Description);
         }
         device.GetRenderTargetData(backbuffer, bufferSurface);
     }
     using (GraphicsStream gStr = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, bufferSurface))
         return((Bitmap)Bitmap.FromStream(gStr));
 }
예제 #17
0
        void lightPreviewControl2_OnNewPreview(object sender, EventArgs e)
        {
            // put texture onto side image preview
            Texture        tex    = (Texture)sender;
            GraphicsStream stream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, tex.GetSurfaceLevel(0));

            Image img = Bitmap.FromStream(stream);

            pictureBox7.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox7.Image    = img;

            tex.Dispose();
        }
예제 #18
0
 WriteCurtainCells(CurtainGrid grid, GraphicsStream grStream)
 {
     foreach (CurtainCell cell in grid.GetCurtainCells())
     {
         foreach (CurveArray crvArray in cell.CurveLoops)
         {
             foreach (Curve crv in crvArray)
             {
                 grStream.Stream(crv);
             }
         }
     }
 }
예제 #19
0
        public void OnCreateVertexBuffer(object sender, EventArgs e)
        {
            VertexBuffer   vb  = (VertexBuffer)sender;
            GraphicsStream stm = vb.Lock(0, 0, 0);

            CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];

            verts[0].X = TriangleTopX; verts[0].Y = TriangleTopY; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Tomato.ToArgb();
            verts[1].X = TriangleRightX; verts[1].Y = TriangleRightY; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Tomato.ToArgb();
            verts[2].X = TriangleLeftX; verts[2].Y = TriangleLeftY; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.Tomato.ToArgb();
            stm.Write(verts);
            vb.Unlock();
        }
예제 #20
0
        public void OnCreateVertexBuffer(object sender, EventArgs e)
        {
            VertexBuffer   vb  = (VertexBuffer)sender;
            GraphicsStream stm = vb.Lock(0, 0, 0);

            CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];

            verts[0].X = 150; verts[0].Y = 50; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
            verts[1].X = 250; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Brown.ToArgb();
            verts[2].X = 50; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.LightPink.ToArgb();
            stm.Write(verts);
            vb.Unlock();
        }
예제 #21
0
        public override PixelBuffer ReadPixels(PixelFormat format, Rectangle rect)
        {
            Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0);

            rect.X += mSrcRect.X;
            rect.Y += mSrcRect.Y;

            int stride;
            int pixelPitch = mDisplay.GetPixelPitch(surf.Description.Format);

            PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format);

            if (format == PixelFormat.Any)
            {
                format = pixelFormat;
            }

            GraphicsStream stm = surf.LockRectangle(
                new Drawing.Rectangle(0, 0, mTextureSize.Width, mTextureSize.Height),
                LockFlags.ReadOnly, out stride);

            byte[] array  = new byte[SurfaceWidth * SurfaceHeight * pixelPitch];
            int    length = SurfaceWidth * pixelPitch;
            int    index  = 0;

            unsafe
            {
                byte *ptr = (byte *)stm.InternalDataPointer;

                for (int i = rect.Top; i < rect.Bottom; i++)
                {
                    // hack if the size requested is too large.
                    if (i >= mTextureSize.Height)
                    {
                        break;
                    }

                    //IntPtr ptr = (IntPtr)((int)stm.InternalData + i * stride + rect.Left * pixelPitch);
                    IntPtr mptr = (IntPtr)(ptr + i * stride + rect.Left * pixelPitch);

                    Marshal.Copy(mptr, array, index, length);

                    index += length;
                }
            }

            surf.UnlockRectangle();
            surf.Dispose();

            return(new PixelBuffer(format, rect.Size, array, pixelFormat));
        }
예제 #22
0
        public int Push(byte[] buffer, int vertexCount, bool unlock)
        {
            int vertexBufferOffset;

            if (this.m_VertexBufferLength >= (this.m_VertexBufferOffset + vertexCount))
            {
                if (this.m_Stream == null)
                {
                    if (unlock)
                    {
                        this.m_Stream = this.m_Buffer.Lock(this.m_VertexBufferOffset * this.m_SizePerVertex, vertexCount * this.m_SizePerVertex, 0x1000);
                    }
                    else
                    {
                        this.m_Stream = this.m_Buffer.Lock(this.m_VertexBufferOffset * this.m_SizePerVertex, (this.m_VertexBufferLength - this.m_VertexBufferOffset) * this.m_SizePerVertex, 0x1000);
                    }
                }
                this.m_Stream.Write(buffer, 0, vertexCount * this.m_SizePerVertex);
                vertexBufferOffset         = this.m_VertexBufferOffset;
                this.m_VertexBufferOffset += vertexCount;
                if (unlock)
                {
                    this.Unlock();
                }
                return(vertexBufferOffset);
            }
            if (vertexCount < this.m_VertexBufferLength)
            {
                this.Unlock();
                if (this.m_Stream == null)
                {
                    if (unlock)
                    {
                        this.m_Stream = this.m_Buffer.Lock(0, vertexCount * this.m_SizePerVertex, 0x2000);
                    }
                    else
                    {
                        this.m_Stream = this.m_Buffer.Lock(0, this.m_VertexBufferLength * this.m_SizePerVertex, 0x2000);
                    }
                }
                this.m_Stream.Write(buffer, 0, vertexCount * this.m_SizePerVertex);
                vertexBufferOffset        = 0;
                this.m_VertexBufferOffset = vertexCount;
                if (unlock)
                {
                    this.Unlock();
                }
                return(vertexBufferOffset);
            }
            return(-1);
        }
예제 #23
0
        public Texture giveEntireTerrainInTexture()
        {
            try
            {
                int     width   = TerrainGlobals.getTerrain().getNumXVerts();
                int     height  = TerrainGlobals.getTerrain().getNumXVerts();
                Texture mainTex = new Texture(BRenderDevice.getDevice(), width, height, 1, Usage.None, Format.A32B32G32R32F, Pool.Managed);

                Vector3[] details = TerrainGlobals.getEditor().getDetailPoints();
                unsafe
                {
                    GraphicsStream streamPos = mainTex.LockRectangle(0, LockFlags.None);
                    Vector4 *      pos       = (Vector4 *)streamPos.InternalDataPointer;

                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            int     srcIndex = x * width + y;
                            int     dstIndex = x * width + y;
                            Vector3 input    = details[srcIndex];
                            pos[dstIndex].X = input.X;
                            pos[dstIndex].Y = input.Y;
                            pos[dstIndex].Z = input.Z;
                            pos[dstIndex].W = 1;
                        }
                    }

                    mainTex.UnlockRectangle(0);
                }

                return(mainTex);
            }
            catch (OutOfVideoMemoryException eGPU)
            {
                if (!CoreGlobals.IsBatchExport)
                {
                    MessageBox.Show("giveEntireTerrainInTexture: You've run out of graphics card memory... Talk to the editor guys..");
                }
                return(null);
            }
            catch (OutOfMemoryException eCPU)
            {
                if (!CoreGlobals.IsBatchExport)
                {
                    MessageBox.Show("giveEntireTerrainInTexture: You've run out of memory... Talk to the editor guys..");
                }
                return(null);
            }
            return(null);
        }
예제 #24
0
파일: D3DUtil.cs 프로젝트: asdlei99/DX9SDK
    /// <summary>
    /// Assembles and creates a file-based vertex shader
    /// </summary>
    public static VertexShader CreateVertexShader(Device device, string filename)
    {
        GraphicsStream code = null;
        string         path = null;

        // Get the path to the vertex shader file
        path = DXUtil.FindMediaFile(null, filename);

        // Assemble the vertex shader file
        code = ShaderLoader.FromFile(path, null, 0);

        // Create the vertex shader
        return(new VertexShader(device, code));
    }
예제 #25
0
        void DrawPoly()
        {
            GraphicsStream stm = vertexBuffer.Lock(0, 0, 0);

            stm.Write(polys.ToArray());
            vertexBuffer.Unlock();
            int ix = 0;

            for (int i = 0; i < primitives.Count; i++)
            {
                device.DrawPrimitives(PrimitiveType.TriangleFan, ix, primitives[i]);
                ix += primitives[i] + 2;
            }
        }
        public void CaptureScreen()
        {
            if (CapturedSurface != null) {
                CapturedSurface.Dispose();
            }
            if (Graphics != null) {
                Graphics.Dispose();
            }

            CapturedSurface = d.CreateOffscreenPlainSurface(Screen.PrimaryScreen.Bounds.Width,
                        Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
            d.GetFrontBufferData(0, CapturedSurface);
            Graphics = CapturedSurface.LockRectangle(LockFlags.None);
        }
예제 #27
0
 public int Push(byte[] buffer, int vertexCount, bool unlock)
 {
     int vertexBufferOffset;
     if (this.m_VertexBufferLength >= (this.m_VertexBufferOffset + vertexCount))
     {
         if (this.m_Stream == null)
         {
             if (unlock)
             {
                 this.m_Stream = this.m_Buffer.Lock(this.m_VertexBufferOffset * this.m_SizePerVertex, vertexCount * this.m_SizePerVertex, 0x1000);
             }
             else
             {
                 this.m_Stream = this.m_Buffer.Lock(this.m_VertexBufferOffset * this.m_SizePerVertex, (this.m_VertexBufferLength - this.m_VertexBufferOffset) * this.m_SizePerVertex, 0x1000);
             }
         }
         this.m_Stream.Write(buffer, 0, vertexCount * this.m_SizePerVertex);
         vertexBufferOffset = this.m_VertexBufferOffset;
         this.m_VertexBufferOffset += vertexCount;
         if (unlock)
         {
             this.Unlock();
         }
         return vertexBufferOffset;
     }
     if (vertexCount < this.m_VertexBufferLength)
     {
         this.Unlock();
         if (this.m_Stream == null)
         {
             if (unlock)
             {
                 this.m_Stream = this.m_Buffer.Lock(0, vertexCount * this.m_SizePerVertex, 0x2000);
             }
             else
             {
                 this.m_Stream = this.m_Buffer.Lock(0, this.m_VertexBufferLength * this.m_SizePerVertex, 0x2000);
             }
         }
         this.m_Stream.Write(buffer, 0, vertexCount * this.m_SizePerVertex);
         vertexBufferOffset = 0;
         this.m_VertexBufferOffset = vertexCount;
         if (unlock)
         {
             this.Unlock();
         }
         return vertexBufferOffset;
     }
     return -1;
 }
예제 #28
0
 public StaticMesh(StaticMesh rhs) : base(rhs)
 {
     this.originMesh  = rhs.originMesh;
     this.mesh        = rhs.mesh;
     this.adjacency   = rhs.adjacency;
     this.materials   = rhs.materials;
     this.textures    = rhs.textures;
     this.subsetCount = rhs.subsetCount;
     this.vertices    = rhs.vertices;
     this.indices     = rhs.indices;
     this.vertexSize  = rhs.vertexSize;
     this.vertexCount = rhs.vertexCount;
     this.faceCount   = rhs.faceCount;
 }
예제 #29
0
        ////////////////////////////////////////////////////////////////////////////////////
        public float CaculateBoundSphere(out Vector3 center)
        {
            GraphicsStream gs = mesh.LockVertexBuffer(LockFlags.None);

            float radius = Geometry.ComputeBoundingSphere(
                gs,
                mesh.NumberVertices,
                mesh.VertexFormat,
                out center);

            mesh.UnlockVertexBuffer();

            return(radius);
        }
예제 #30
0
        /// <summary>
        /// Cargar malla de DirectX.
        /// Una malla de DirectX posee varios Subset, que son distintos grupos
        /// de triángulos. Cada grupo puede tener su propia textura y material.
        /// </summary>
        /// <param name="path"></param>
        private void loadMesh(string path)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            ExtendedMaterial[] mtrl;

            //Cargar mesh con utilidad de DirectX
            mesh = Mesh.FromFile(path, MeshFlags.Managed, d3dDevice, out mtrl);

            //Analizar todos los subset de la malla
            if ((mtrl != null) && (mtrl.Length > 0))
            {
                meshMaterials = new Material[mtrl.Length];
                meshTextures  = new Texture[mtrl.Length];

                //Cargar los material y texturas en un array
                for (int i = 0; i < mtrl.Length; i++)
                {
                    //Cargar material
                    meshMaterials[i] = mtrl[i].Material3D;

                    //Si hay textura, intentar cargarla
                    if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename !=
                                                              string.Empty))
                    {
                        //Cargar textura con TextureLoader
                        meshTextures[i] = TextureLoader.FromFile(d3dDevice, GuiController.Instance.ExamplesMediaDir + "ModelosX" + "\\" +
                                                                 mtrl[i].TextureFilename);
                    }
                }
            }


            //Crear Bounding Sphere con herramienta de Geometry DirectX
            float   objectRadius = 0.0f;
            Vector3 objectCenter = new Vector3();

            using (VertexBuffer vb = mesh.VertexBuffer)
            {
                GraphicsStream vertexData = vb.Lock(0, 0, LockFlags.None);
                objectRadius = Geometry.ComputeBoundingSphere(vertexData,
                                                              mesh.NumberVertices,
                                                              mesh.VertexFormat,
                                                              out objectCenter);
                vb.Unlock();
            }

            //Alejar camara rotacional, respecto de su Bounding Sphere
            GuiController.Instance.RotCamera.setCamera(new Vector3(0, 0, 0), objectRadius * 4, 5f / objectRadius);
        }
예제 #31
0
파일: Ngon.cs 프로젝트: klugaman/CSE471
        public override void Render(Device device)
        {
            //List<Vector2> vertices = Vertices;

            //// Ensure we have at least a triangle
            //if (vertices.Count < 3)
            //    return;

            if (verticesV == null)
            {
                verticesV = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), // Type of vertex
                                             verticesB.Count,                              // How many
                                             device,                                       // What device
                                             0,                                            // No special usage
                                             CustomVertex.PositionColoredTextured.Format,
                                             Pool.Managed);

                //Tex = TextureLoader.FromFile(device, "../../../QuestionCoin.png");
            }

            GraphicsStream gs  = verticesV.Lock(0, 0, 0);                   // Lock the background vertex list
            int            clr = System.Drawing.Color.Transparent.ToArgb(); // Don't you love all those color names?

            foreach (Vector2 v in verticesB)
            {
                float tu = 0.5f + v.X / .5f;
                float tv = 1 - (v.Y - (-0.8f)) / .5f;
                gs.Write(new CustomVertex.PositionColoredTextured(v.X + p.X, v.Y + p.Y, 0, clr, tu, tv));
            }

            verticesV.Unlock();

            if (Transparent)
            {
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend      = Blend.SourceAlpha;
                device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
            }

            device.SetTexture(0, Tex);
            device.SetStreamSource(0, verticesV, 0);
            device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            device.DrawPrimitives(PrimitiveType.TriangleFan, 0, Vertices.Count - 2);
            device.SetTexture(0, null);

            if (Transparent)
            {
                device.RenderState.AlphaBlendEnable = false;
            }
        }
예제 #32
0
        private void использоватьGPUToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null)
            {
                return;
            }
            Surface newbb = dr.CreateRenderTarget(bmhm.Width, bmhm.Height, Format.A8R8G8B8, MultiSampleType.None, 0, true);
            Surface oldbb = dr.GetRenderTarget(0);

            dr.SetRenderTarget(0, newbb);
            dr.BeginScene();
            dr.Clear(ClearFlags.Target, Color.Black, 1f, 0); //Очистка фона
            eff.SetValue("w", Matrix.Scaling(2.0f, 2.0f, 2.0f));
            eff.SetValue("v", Matrix.RotationX(0));
            eff.SetValue("p", Matrix.RotationX(0));
            eff.SetValue("txh", txh);
            eff.SetValue("h", himax);
            eff.Begin(FX.None);
            eff.BeginPass(2);
            dr.VertexFormat = CustomVertex.PositionNormalTextured.Format;
            dr.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, dp);
            eff.EndPass();
            eff.End();
            dr.EndScene();

            if (pictureBox2.Image != null)
            {
                pictureBox2.Image.Dispose();
            }
            if (gstr != null)
            {
                gstr.Dispose();
            }
            gstr = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, newbb);
            if (bmnm != null)
            {
                bmnm.Dispose();
            }
            bmnm = (Bitmap)Image.FromStream(gstr);
            pictureBox2.Image = (Image)bmnm;
            hdv = (float)bmnm.Width / (float)bmnm.Height;
            if (txn != null)
            {
                txn.Dispose();
            }
            txn = Texture.FromBitmap(dr, bmnm, Usage.None, Pool.Managed);
            dr.SetRenderTarget(0, oldbb);
            newbb.Dispose();
            oldbb.Dispose();
        }
예제 #33
0
        /// <summary>
        /// Read a Matrix from an XFile node
        /// </summary>
        /// <param name="stream">GraphicsStream obtained from locking the Xfile data object</param>
        public Matrix MatrixFromXFile(GraphicsStream stream)
        {
            float v = 0;													// elements are floats
            Matrix m = Matrix.Identity;

            m.M11 = (float)stream.Read(v.GetType());		// read the matrix
            m.M12 = (float)stream.Read(v.GetType());
            m.M13 = (float)stream.Read(v.GetType());
            m.M14 = (float)stream.Read(v.GetType());
            m.M21 = (float)stream.Read(v.GetType());
            m.M22 = (float)stream.Read(v.GetType());
            m.M23 = (float)stream.Read(v.GetType());
            m.M24 = (float)stream.Read(v.GetType());
            m.M31 = (float)stream.Read(v.GetType());
            m.M32 = (float)stream.Read(v.GetType());
            m.M33 = (float)stream.Read(v.GetType());
            m.M34 = (float)stream.Read(v.GetType());
            m.M41 = (float)stream.Read(v.GetType());
            m.M42 = (float)stream.Read(v.GetType());
            m.M43 = (float)stream.Read(v.GetType());
            m.M44 = (float)stream.Read(v.GetType());

            return m;
        }
예제 #34
0
        private static void CopyTextureData(GraphicsStream srcData, int srcWidth, int srcHeight, OpsFormatHelper formatHelp, int srcPitch, GraphicsStream dstData, int dstPitch)
        {
            Byte[] rowData = new Byte[srcWidth * formatHelp.SizeInBytes];
            for (int row = 0; row < srcHeight; row++)
            {
                srcData.Position = row * srcPitch;
                dstData.Position = row * dstPitch;

                srcData.Read(rowData, 0, rowData.Length);
                dstData.Write(rowData, 0, rowData.Length);
            }
        }
예제 #35
0
 public void RemapSkin( GraphicsStream vertexRemapStream )
 {
     if(SkinInformation != null && vertexRemapStream != null)
     {
         int[] vertexRemap= vertexRemap= vertexRemapStream.Read( typeof(int), new int[]{ MeshData.Mesh.NumberVertices } ) as int[];
         SkinInformation.Remap(vertexRemap);
     }
 }
예제 #36
0
 /// <summary>
 /// Crear Vertices segun la cara pedida
 /// </summary>
 private void cargarVertices(SkyFaces face, GraphicsStream data, int color)
 {
     switch (face)
     {
         case SkyFaces.Up: cargarVerticesUp(data, color); break;
         case SkyFaces.Down: cargarVerticesDown(data, color); break;
         case SkyFaces.Front: cargarVerticesFront(data, color); break;
         case SkyFaces.Back: cargarVerticesBack(data, color); break;
         case SkyFaces.Right: cargarVerticesRight(data, color); break;
         case SkyFaces.Left: cargarVerticesLeft(data, color); break;
     }
 }
예제 #37
0
 /// <summary>
 /// Read a vector from open xfile stream
 /// </summary>
 /// <param name="stream"></param>
 /// <returns></returns>
 private static Vector3 ReadVector(GraphicsStream stream)
 {
     Vector3 v = new Vector3();
     //			v = (Vector3)stream.Read(v.GetType());
     v.X = (float)stream.Read(v.X.GetType());
     v.Y = (float)stream.Read(v.X.GetType());
     v.Z = (float)stream.Read(v.X.GetType());
     return v;
 }
예제 #38
0
            //AllocateHierarchy
            public override MeshContainer CreateMeshContainer(
                string name,
                MeshData meshData,
                ExtendedMaterial[] materials,
                EffectInstance[] effectInstances,
                GraphicsStream adjacency,
                SkinInformation skinInfo)
            { 
                if(meshData.Mesh == null )
                    throw new OpsException("Expecting Microsoft.DirectX.Direct3D.Mesh not Microsoft.DirectX.Direct3D.ProgressiveMesh or Microsoft.DirectX.Direct3D.PatchMesh.");

                OpsMeshContainer mc= new OpsMeshContainer();
                mc.Name= name;
                mc.MeshData= meshData;
                mc.SetMaterials(materials);
                mc.SetEffectInstances(effectInstances);
                mc.SetAdjacency(adjacency);
                mc.SkinInformation = skinInfo;

                return mc;
            }    
        private void GenericDrawBondSolidBlended(Vector3 start, Vector3 end,
                                                 IMoleculeMaterial matA, IMoleculeMaterial matB,
                                                 GraphicsStream data, ref long pos, int stride,
                                                 int positionPos, int diffusePos)
        {
            if (positionPos != -1)
            {
                data.Seek(pos + positionPos, SeekOrigin.Begin);
                data.Write(start.X);
                data.Write(start.Y);
                data.Write(start.Z);

                data.Seek(pos + stride + positionPos, SeekOrigin.Begin);
                data.Write(end.X);
                data.Write(end.Y);
                data.Write(end.Z);
            }
            if (diffusePos != -1)
            {
                data.Seek(pos + diffusePos, SeekOrigin.Begin);
                data.Write(matA.BaseColor.ToArgb());

                data.Seek(pos + stride + diffusePos, SeekOrigin.Begin);
                data.Write(matB.BaseColor.ToArgb());
            }
            pos += stride * 2;
        }
예제 #40
0
 public void Unlock()
 {
     if (this.m_Stream != null)
     {
         try
         {
             this.m_Stream.Close();
             this.m_Buffer.Unlock();
         }
         catch
         {
         }
         this.m_Stream = null;
     }
 }
예제 #41
0
 public void Unlock()
 {
     Texture texture = this.CoreGetSurface();
     if (texture != null)
     {
         if (this.m_LockStream != null)
         {
             this.m_LockStream.Close();
         }
         this.m_LockStream = null;
         texture.UnlockRectangle(0);
     }
 }
예제 #42
0
 public void load_image(string DDS)
 {
     if (this.gs != null)
     {
         this.gs.Dispose();
     }
     try
     {
         PresentParameters presentParameters = new PresentParameters();
         presentParameters.SwapEffect = SwapEffect.Discard;
         Format format = Manager.Adapters[0].CurrentDisplayMode.Format;
         presentParameters.Windowed = true;
         Device device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, new PresentParameters[]
         {
             presentParameters
         });
         Texture texture = TextureLoader.FromFile(device, DDS);
         this.gs = TextureLoader.SaveToStream(ImageFileFormat.Png, texture);
         texture.Dispose();
         this.pictureBox.Image = Image.FromStream(this.gs);
         device.Dispose();
         this.gs.Close();
     }
     catch (Exception var_4_B4)
     {
     }
 }
예제 #43
0
파일: Effect.cs 프로젝트: zpconn/Gas
 public void SetValue( string name, GraphicsStream val )
 {
     effect.SetValue( GetHandle( name ), val );
 }
        private void DrawSolidBondDistinct(Vector3[] tCylinderPoints, Vector3[] tCylinderNormals,
                                           int[] tCylinderTris, IMoleculeMaterial matA,
                                           IMoleculeMaterial matB, Matrix final,
                                           GraphicsStream data, float xyScale, float bLen2, Matrix rotation,
                                           Vector3 bondInstance1, Vector3 directionUV, float midPos,
                                           int positionPos, int normalPos, int diffusePos, ref long pos,
                                           int stride)
        {
            // side 1
            Vector4[] tfTriangles = Vector3.Transform(tCylinderPoints, final);
            //Vector4[] rtNormals = Vector3.Transform(tCylinderNormals, rotation);
            for (int point = 0; point < tCylinderTris.Length; point++)
            {
                int pointIdx = tCylinderTris[point];
                if (positionPos != -1)
                {
                    data.Seek(pos + positionPos, SeekOrigin.Begin);
                    data.Write(tfTriangles[pointIdx].X);
                    data.Write(tfTriangles[pointIdx].Y);
                    data.Write(tfTriangles[pointIdx].Z);
                }
                if (normalPos != -1)
                {
                    data.Seek(pos + normalPos, SeekOrigin.Begin);
                    data.Write(tCylinderNormals[pointIdx].X);
                    data.Write(tCylinderNormals[pointIdx].Y);
                    data.Write(tCylinderNormals[pointIdx].Z);
                    //bondsVerts[vertsIdx].Normal = new Vector3(rtNormals[pointIdx].X,
                    //                                          rtNormals[pointIdx].Y,
                    //                                          rtNormals[pointIdx].Z);
                    //bondsVerts[vertsIdx].Normal.Normalize();
                }
                if (diffusePos != -1)
                {
                    data.Seek(pos + diffusePos, SeekOrigin.Begin);
                    data.Write(matA.BaseColor.ToArgb());
                }
                pos += stride;
            }

            // side 2
            final = Matrix.Scaling(xyScale, xyScale, bLen2) * rotation *
                    Matrix.Translation(bondInstance1 + (directionUV * midPos));
            tfTriangles = Vector3.Transform(tCylinderPoints, final);
            for (int point = 0; point < tCylinderTris.Length; point++)
            {
                int pointIdx = tCylinderTris[point];
                if (positionPos != -1)
                {
                    data.Seek(pos + positionPos, SeekOrigin.Begin);
                    data.Write(tfTriangles[pointIdx].X);
                    data.Write(tfTriangles[pointIdx].Y);
                    data.Write(tfTriangles[pointIdx].Z);
                }
                if (normalPos != -1)
                {
                    data.Seek(pos + normalPos, SeekOrigin.Begin);
                    data.Write(tCylinderNormals[pointIdx].X);
                    data.Write(tCylinderNormals[pointIdx].Y);
                    data.Write(tCylinderNormals[pointIdx].Z);
                    //bondsVerts[vertsIdx].Normal = new Vector3(rtNormals[pointIdx].X,
                    //                                          rtNormals[pointIdx].Y,
                    //                                          rtNormals[pointIdx].Z);
                    //bondsVerts[vertsIdx].Normal.Normalize();
                }
                if (diffusePos != -1)
                {
                    data.Seek(pos + diffusePos, SeekOrigin.Begin);
                    data.Write(matB.BaseColor.ToArgb());
                }
                pos += stride;
            }
        }
 private void DrawSolidBondBlended(Vector3[] tCylinderPoints, Vector3[] tCylinderNormals,
                                   int[] tCylinderTris, IMoleculeMaterial matA,
                                   IMoleculeMaterial matB, Matrix final, GraphicsStream data,
                                   int positionPos, int normalPos, int diffusePos,
                                   ref long pos, int stride, Matrix rotation)
 {
     // write transformed template to buffer
     Vector4[] tfTriangles = Vector3.Transform(tCylinderPoints, final);
     //Vector4[] rtNormals = Vector3.Transform(tCylinderNormals, rotation);
     int halfWay = tfTriangles.Length / 2;
     for (int point = 0; point < tCylinderTris.Length; point++)
     {
         int pointIdx = tCylinderTris[point];
         if (positionPos != -1)
         {
             data.Seek(pos + positionPos, SeekOrigin.Begin);
             data.Write(tfTriangles[pointIdx].X);
             data.Write(tfTriangles[pointIdx].Y);
             data.Write(tfTriangles[pointIdx].Z);
         }
         if (normalPos != -1)
         {
             data.Seek(pos + normalPos, SeekOrigin.Begin);
             data.Write(tCylinderNormals[pointIdx].X);
             data.Write(tCylinderNormals[pointIdx].Y);
             data.Write(tCylinderNormals[pointIdx].Z);
             //bondsVerts[vertsIdx].Normal = new Vector3(rtNormals[pointIdx].X,
             //                                          rtNormals[pointIdx].Y,
             //                                          rtNormals[pointIdx].Z);
         }
         if (diffusePos != -1)
         {
             data.Seek(pos + diffusePos, SeekOrigin.Begin);
             if (pointIdx < halfWay)
                 data.Write(matA.BaseColor.ToArgb());
             else
                 data.Write(matB.BaseColor.ToArgb());
         }
         pos += stride;
     }
 }
예제 #46
0
        /// <summary>
        /// Constructor, called by HierarchyAllocator
        /// </summary>
        /// <param name="subfolder">textures are found in ../Cells/subfolder, where subfolder is the cell group name</param>
        /// <param name="name">mesh name (read from the X file)</param>
        /// <param name="mesh">the source mesh (as a standard mesh)</param>
        /// <param name="extmaterials">Materials and texture filenames</param>
        /// <param name="effectInstances">Effects</param>
        /// <param name="adjacency">Mesh adjacency data</param>
        /// <param name="skinInfo">Skin information for the mesh</param>
        public Cytoplasm(
            string subfolder,
            string name,
            Mesh mesh,
            ExtendedMaterial[] extmaterials,
            EffectInstance[] effectInstances,
            GraphicsStream adjacency,
            SkinInformation skinInfo)
        {
            // Store the name
            Name = name;

            // Keep the original mesh because this is needed for MousePick()
            // (ProgressiveMeshes don't have a .Intersect() method)
            originalMesh = mesh;

            // Store the materials
            int matlength = 0;
            if (extmaterials != null)
                matlength = extmaterials.Length;
            materials = new Material[matlength];
            textures = new Texture[matlength];
            bumps = new Texture[matlength];
            for (int i = 0; i < matlength; i++)
            {
                materials[i] = extmaterials[i].Material3D;
                // TRUESPACE HACK: Truespace doesn't allow me to set any ambient values in materials,
                // which means that everything comes out black if it isn't lit by the diffuse light.
                // So add a default ambient value here for any black cells, to simulate reflection from terrain
                if ((materials[i].Ambient.R + materials[i].Ambient.G + materials[i].Ambient.B) == 0)
                    materials[i].Ambient = Color.FromArgb(68, 68, 68);

                if ((extmaterials[i].TextureFilename != null) && (extmaterials[i].TextureFilename !=
                    string.Empty))
                {
                    try
                    {
                        // We have a texture file, rather than an inline texture, so try to load it from ./cells/group/type
                        textures[i] = TextureLoader.FromFile(Engine.Device,
                            FileResource.Fsp(subfolder, extmaterials[i].TextureFilename));
                        // Also attempt to load a normal map, if any
                        try
                        {
                            string filename = System.IO.Path.GetFileNameWithoutExtension(extmaterials[i].TextureFilename) + " Normal.PNG";
                            bumps[i] = TextureLoader.FromFile(Engine.Device,
                                FileResource.Fsp(subfolder, filename));
                        }
                        catch { }
                    }
                    catch
                    {
                        throw new SDKException("Failed to load texture " + FileResource.Fsp(subfolder, extmaterials[i].TextureFilename));
                    }
                }
            }

            // Get access to the vertices to allow various operations
            // get the input vertices as an array (in case I want to modify them)
            VertexBuffer vb = mesh.VertexBuffer;						// Retrieve the vertex buffer data
            System.Array vert = null;                                   // We don't know if array will be PositionNormal or PositionNormalTextured, so use generic type

            if (mesh.VertexFormat == VertexFormats.PositionNormal)
            {
                vert = vb.Lock(0,
                    typeof(CustomVertex.PositionNormal),
                    LockFlags.ReadOnly,
                    mesh.NumberVertices);
            }
            else
            {
                vert = vb.Lock(0,
                    typeof(CustomVertex.PositionNormalTextured),
                    LockFlags.ReadOnly,
                    mesh.NumberVertices);
            }

            // compute the bounding sphere radius & centre from the vertices
            // NOTE: THIS VALUE IS FOR THE UNSCALED VERTICES and needs to be transformed by the combined transformation matrix
            boundRadius = Geometry.ComputeBoundingSphere(vert,
                                                            mesh.VertexFormat,
                                                            out boundCentre);

            // Calculate a bounding box for fine collision detection
            // NOTE: THIS VALUE IS FOR THE UNSCALED VERTICES and needs to be transformed by the combined transformation matrix
            Geometry.ComputeBoundingBox(vert, mesh.VertexFormat, out minOBB, out maxOBB);

            // gather useful debug info while we have the vertices
            //			Debug.WriteLine(String.Format("		Loaded mesh [{0}] from disk. {1} vertices, {2} textures, {3} materials",
            //											name,md.Mesh.NumberVertices,textures.Length, materials.Length));
            //						Debug.WriteLine(String.Format("Mesh is centred on {0} with bound radius {1}; OBB is {2}:{3}",
            //											boundcentre, boundradius, OBBmin, OBBmax));

            vb.Unlock();
            vb.Dispose();														// vertices no longer needed

            // create a cleaned progressive mesh from the input
            using (Mesh clean = Mesh.Clean(CleanType.Optimization, mesh, adjacency, adjacency))
            {
                // From the cleaned mesh, create one that has binormals and tangents as well as normals
                // (ThreeDee.BinormalVertex). These are needed for normal mapping in the shader
                using (Mesh clone = clean.Clone(MeshFlags.Managed, BinormalVertex.VertexElements, Engine.Device))
                {
                    // Add tangents and binormals
                    clone.ComputeTangent(0, 0, 0, 0);
                    //clone.ComputeTangentFrame(0);

                    // Create a new progressive mesh from the clean version
                    MeshData md = new MeshData();
                    md.ProgressiveMesh = new ProgressiveMesh(clone,
                                                                adjacency,
                                                                null,
                                                                12,					// min acceptable # faces
                                                                MeshFlags.SimplifyFace);
                    this.MeshData = md;
                }

            }

            // Add a device reset handler to reload resources (if required)
            /////Engine.Device.DeviceReset += new System.EventHandler(OnReset);
        }
예제 #47
0
        // TODO: Create with XOF
        /// <summary>Create the materials for the mesh</summary>
        public void CreateMaterials(string folder, Device device, GraphicsStream adjacency, ExtendedMaterial[] materials)
        {
            // Does the mesh have materials?
            if ((materials != null) && (materials.Length > 0))
            {
                // Allocate the arrays for the materials
                meshMaterials = new Material[materials.Length];
                meshTextures = new BaseTexture[materials.Length];

                // Copy each material and create it's texture
                for(int i = 0; i < materials.Length; i++)
                {
                    // Copy the material first
                    meshMaterials[i] = materials[i].Material3D;

                    // Is there a texture for this material?
                    if ((materials[i].TextureFilename == null) || (materials[i].TextureFilename.Length == 0) )
                        continue; // No, just continue now

                    ImageInformation info = new ImageInformation();
                    string textureFile = folder + materials[i].TextureFilename;
                    try
                    {
                        // First look for the texture in the same folder as the input folder
                        info = TextureLoader.ImageInformationFromFile(textureFile);
                    }
                    catch
                    {
                        try
                        {
                            // Couldn't find it, look in the media folder
                            textureFile = Utility.FindMediaFile(materials[i].TextureFilename);
                            info = TextureLoader.ImageInformationFromFile(textureFile);
                        }
                        catch (MediaNotFoundException)
                        {
                            // Couldn't find it anywhere, skip it
                            continue;
                        }
                    }
                    switch (info.ResourceType)
                    {
                        case ResourceType.Textures:
                            meshTextures[i] = TextureLoader.FromFile(device, textureFile);
                            break;
                        case ResourceType.CubeTexture:
                            meshTextures[i] = TextureLoader.FromCubeFile(device, textureFile);
                            break;
                        case ResourceType.VolumeTexture:
                            meshTextures[i] = TextureLoader.FromVolumeFile(device, textureFile);
                            break;
                    }
                }
            }
        }
예제 #48
0
        private void DeskCapture()
        {
            int redL = 0, greenL = 0, blueL = 0;
            int redR = 0, greenR = 0, blueR = 0;
            int redT = 0, greenT = 0, blueT = 0;
            int CounterL = 0, CounterR = 0, CounterT = 0;
            bool read = false;
            bool CaptureScreen = false;

            Color c = Color.Black;

            if ((CaptureEvery.Checked == false) || (CaptureEvery.Checked == true && CyclesInt == 0))
            {
                CaptureScreen = true;
            }
            if (CaptureEvery.Checked == true)
            {
                CyclesInt = CyclesInt + 1;
            }

            if (CaptureScreen == true)
            {

                device.GetFrontBufferData(0, s);
                //s = device.GetBackBuffer(0, 0, BackBufferType.Mono); //doesn't work

                gsx = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s);
                b = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(gsx);

                //SurfaceLoader.Save("temp2.jpg", ImageFileFormat.Jpg, s); //save surface to file
                //b = new Bitmap(SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, s)); // memory leak so used alternate method

            }

            swidth = b.Width;
            sheight = b.Height;

            // b.Save("temp.jpg", ImageFormat.Jpeg);

            int divide = (int)DivideLevel.Value;
            GlobalVariables.Offset = (int)OffsetLevel.Value;
            if (GlobalVariables.mode == 1)
            {
                divide = 32;
                GlobalVariables.Offset = 0;
            }

            int dx = swidth / divide;
            int dy = sheight / divide;

            int offsetx = dx / 3 * GlobalVariables.Offset;
            int offsety = dy / 3 * GlobalVariables.Offset;

            if (this.WindowState != FormWindowState.Minimized)
            {
                label60.Text = dx.ToString();
                label62.Text = dy.ToString();

                label66.Text = swidth.ToString();
                label69.Text = sheight.ToString();

                label64.Text = "~" + divide.ToString();
                label65.Text = "~" + divide.ToString();

                label74.Text = offsetx.ToString();
                label72.Text = offsety.ToString();
            }

            for (int PixelY = offsety; PixelY < sheight; PixelY += dy)
                {
                for (int PixelX = offsetx; PixelX < swidth; PixelX += swidth / divide)
                {

                    {
                        read = false;

                        if (PixelX >= swidth * LeftBegin.Value / 100 && PixelX <= swidth * LeftEnd.Value / 100)
                        {
                            if (read == false)
                            {
                                c = b.GetPixel(PixelX, PixelY);
                                read = true;
                            }
                            redL += c.R;
                            greenL += c.G;
                            blueL += c.B;
                            CounterL++;
                        }
                        if (PixelX >= swidth * RightBegin.Value / 100 && PixelX <= swidth * RightEnd.Value / 100)
                        {
                            if (read == false)
                            {
                                c = b.GetPixel(PixelX, PixelY);
                                read = true;
                            }
                            redR += c.R;
                            greenR += c.G;
                            blueR += c.B;
                            CounterR++;
                        }
                        if (PixelY >= sheight * TopBegin.Value / 100 && PixelY <= sheight * TopEnd.Value / 100)
                        {
                            if (read == false)
                            {
                                c = b.GetPixel(PixelX, PixelY);
                                read = true;
                            }
                            redT += c.R;
                            greenT += c.G;
                            blueT += c.B;
                            CounterT++;
                        }

                    }
                }
            }

            if (CounterL > 0)
            {
                redL /= CounterL;
                greenL /= CounterL;
                blueL /= CounterL;
            }
            if (CounterR > 0)
            {
                redR /= CounterR;
                greenR /= CounterR;
                blueR /= CounterR;
            }
            if (CounterT > 0)
            {
                redT /= CounterT;
                greenT /= CounterT;
                blueT /= CounterT;
            }
            if (redL > 0 || greenL > 0 || blueL > 0 || redR > 0 || greenR > 0 || blueR > 0 || redT > 0 || greenT > 0 || blueT > 0 || GlobalVariables.blackframe)
            {
                GlobalVariables.blackframe = false;
                Array.Copy(GlobalVariables.PreviousColor29, GlobalVariables.PreviousColor30, 9);
                Array.Copy(GlobalVariables.PreviousColor28, GlobalVariables.PreviousColor29, 9);
                Array.Copy(GlobalVariables.PreviousColor27, GlobalVariables.PreviousColor28, 9);
                Array.Copy(GlobalVariables.PreviousColor26, GlobalVariables.PreviousColor27, 9);
                Array.Copy(GlobalVariables.PreviousColor25, GlobalVariables.PreviousColor26, 9);
                Array.Copy(GlobalVariables.PreviousColor24, GlobalVariables.PreviousColor25, 9);
                Array.Copy(GlobalVariables.PreviousColor23, GlobalVariables.PreviousColor24, 9);
                Array.Copy(GlobalVariables.PreviousColor22, GlobalVariables.PreviousColor23, 9);
                Array.Copy(GlobalVariables.PreviousColor21, GlobalVariables.PreviousColor22, 9);
                Array.Copy(GlobalVariables.PreviousColor20, GlobalVariables.PreviousColor21, 9);
                Array.Copy(GlobalVariables.PreviousColor19, GlobalVariables.PreviousColor20, 9);
                Array.Copy(GlobalVariables.PreviousColor18, GlobalVariables.PreviousColor19, 9);
                Array.Copy(GlobalVariables.PreviousColor17, GlobalVariables.PreviousColor18, 9);
                Array.Copy(GlobalVariables.PreviousColor16, GlobalVariables.PreviousColor17, 9);
                Array.Copy(GlobalVariables.PreviousColor15, GlobalVariables.PreviousColor16, 9);
                Array.Copy(GlobalVariables.PreviousColor14, GlobalVariables.PreviousColor15, 9);
                Array.Copy(GlobalVariables.PreviousColor13, GlobalVariables.PreviousColor14, 9);
                Array.Copy(GlobalVariables.PreviousColor12, GlobalVariables.PreviousColor13, 9);
                Array.Copy(GlobalVariables.PreviousColor11, GlobalVariables.PreviousColor12, 9);
                Array.Copy(GlobalVariables.PreviousColor10, GlobalVariables.PreviousColor11, 9);
                Array.Copy(GlobalVariables.PreviousColor9, GlobalVariables.PreviousColor10, 9);
                Array.Copy(GlobalVariables.PreviousColor8, GlobalVariables.PreviousColor9, 9);
                Array.Copy(GlobalVariables.PreviousColor7, GlobalVariables.PreviousColor8, 9);
                Array.Copy(GlobalVariables.PreviousColor6, GlobalVariables.PreviousColor7, 9);
                Array.Copy(GlobalVariables.PreviousColor5, GlobalVariables.PreviousColor6, 9);
                Array.Copy(GlobalVariables.PreviousColor4, GlobalVariables.PreviousColor5, 9);
                Array.Copy(GlobalVariables.PreviousColor3, GlobalVariables.PreviousColor4, 9);
                Array.Copy(GlobalVariables.PreviousColor2, GlobalVariables.PreviousColor3, 9);
                Array.Copy(GlobalVariables.PreviousColor, GlobalVariables.PreviousColor2, 9);
                Array.Copy(GlobalVariables.CurrentColor, GlobalVariables.PreviousColor, 9);

                GlobalVariables.CurrentColor[0] = redL;
                GlobalVariables.CurrentColor[3] = greenL;
                GlobalVariables.CurrentColor[6] = blueL;
                GlobalVariables.CurrentColor[2] = redR;
                GlobalVariables.CurrentColor[5] = greenR;
                GlobalVariables.CurrentColor[8] = blueR;
                GlobalVariables.CurrentColor[1] = redT;
                GlobalVariables.CurrentColor[4] = greenT;
                GlobalVariables.CurrentColor[7] = blueT;

                //if (checkBox1.Checked)
                if (radioButton2.Checked)
                {
                    int[] Highest = new int[3] { 0, 0, 0 };
                    for (int I = 0; I < 9; I += 3)
                    {
                        if (Highest[0] < GlobalVariables.CurrentColor[I]) Highest[0] = GlobalVariables.CurrentColor[I];
                        if (Highest[1] < GlobalVariables.CurrentColor[I + 1]) Highest[1] = GlobalVariables.CurrentColor[I + 1];
                        if (Highest[2] < GlobalVariables.CurrentColor[I + 2]) Highest[2] = GlobalVariables.CurrentColor[I + 2];
                    }
                    float[] Multiply = new float[3];
                    for (int I = 0; I < 3; I++)
                    {
                        Multiply[I] = 255.0F / (float)Highest[I];
                        if (Multiply[I] > (float)numericUpDown1.Value) Multiply[I] = (float)numericUpDown1.Value;
                    }
                    for (int I = 0; I < 9; I += 3)
                    {
                        GlobalVariables.CurrentColor[I] = (int)((float)GlobalVariables.CurrentColor[I] * Multiply[0]);
                        GlobalVariables.CurrentColor[I + 1] = (int)((float)GlobalVariables.CurrentColor[I + 1] * Multiply[1]);
                        GlobalVariables.CurrentColor[I + 2] = (int)((float)GlobalVariables.CurrentColor[I + 2] * Multiply[2]);
                    }
                }

                if (radioButton3.Checked)
                {
                    int Highest = 0;
                    for (int I = 0; I < 9; I++)
                    {
                        if (Highest < GlobalVariables.CurrentColor[I])
                            Highest = GlobalVariables.CurrentColor[I];
                    }
                    float Multiply = 255.0F / (float)Highest;
                    if (Multiply > (float)numericUpDown1.Value)
                    {
                        Multiply = (float)numericUpDown1.Value;
                    }
                    for (int I = 0; I < 9; I++)
                    {
                        GlobalVariables.CurrentColor[I] = (int)((float)GlobalVariables.CurrentColor[I] * Multiply);
                    }
                }
                GlobalVariables.Offset++;
                if (GlobalVariables.Offset == 3)
                {
                    GlobalVariables.Offset = 0;
                }
            }
            else
            {
                GlobalVariables.blackframe = true;
            }

            if (CaptureScreen == true)
            {
            }

            if ((CyclesInt > CaptureCycles.Value) || (CaptureEvery.Checked == false))
            {
                CyclesInt = 0;
                s.ReleaseGraphics();

                gsx.Close();
                gsx.Dispose();

                b.Dispose();
            }

            //g.Dispose();
            //device.Reset(presentParams);
        }
 ///<summary>
 ///    Util functions to convert a D3D LockedBox to a pixel box
 ///</summary>
 protected static void FromD3DLock(PixelBox rval, D3D.LockedBox lbox, GraphicsStream stream)
 {
     rval.RowPitch = lbox.RowPitch / PixelUtil.GetNumElemBytes(rval.Format);
     rval.SlicePitch = lbox.SlicePitch / PixelUtil.GetNumElemBytes(rval.Format);
     Debug.Assert((lbox.RowPitch % PixelUtil.GetNumElemBytes(rval.Format)) == 0);
     Debug.Assert((lbox.SlicePitch % PixelUtil.GetNumElemBytes(rval.Format)) == 0);
     rval.Data = stream.InternalData;
 }
예제 #50
0
        public Texture GenerateTexture(Size size, DataArea area, Device gDevice, GDALReader dataSrc)
        {
            Texture texture = new Texture(gDevice, size.Width, size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);
            lock (this)
            {
                // find bands to use
                int r, g, b;
                dataSrc.Info.GetRGABands(out r, out g, out b);
                Size nativeSz = dataSrc.Info.Resolution;

                Band rBand = dataSrc.GetRasterBand(r + 1);
                Band gBand = dataSrc.GetRasterBand(g + 1);
                Band bBand = dataSrc.GetRasterBand(b + 1);

                rData = new byte[nativeSz.Width * nativeSz.Height];
                gData = new byte[nativeSz.Width * nativeSz.Height];
                bData = new byte[nativeSz.Width * nativeSz.Height];
                rBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, rData, nativeSz.Width, nativeSz.Height, 0, 0);
                gBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, gData, nativeSz.Width, nativeSz.Height, 0, 0);
                bBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, bData, nativeSz.Width, nativeSz.Height, 0, 0);

                /*ftScaleTemp = new SizeF(1, 1);// (float)area.Area.Width / area.DataSize.Width, (float)area.Area.Height / area.DataSize.Height);
                ftScaleTemp = new SizeF(ftScaleTemp.Width * area.Area.Width, ftScaleTemp.Height * area.Area.Height);
                ftShiftTemp = new Size(area.Area.Location);
                ftNativeSz = nativeSz;*/
                ftScaleTemp = new SizeF((float)area.Area.Width / size.Width, (float)area.Area.Height / size.Height);
                ftShiftTemp = new Size(area.Area.Location);
                if (area.Data is byte[])
                {
                    // to heights
                    //TextureLoader.FillTexture(texture, FillTextureByteToHeights);
                    // generate normal acc
                    ftTexSz = size;
                    //texStream = texture.LockRectangle(0, LockFlags.None);
                    /*Texture normalTex = new Texture(gDevice, size.Width, size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);
                    TextureLoader.FillTexture(normalTex, FillTextureByteToNormalAcc);*/
                    heights = new float[size.Width * size.Height];
                    int index = 0;
                    //SizeF nativeScale = new SizeF((float)nativeSz.Width / size.Width, (float)nativeSz.Height / size.Height);
                    for (int y = 0; y < size.Height; y++)
                    {
                        int yNative = (int)(ftShiftTemp.Height + (y * ftScaleTemp.Width));
                        for (int x = 0; x < size.Width; x++)
                        {
                            int xNative = (int)(ftShiftTemp.Width + (x * ftScaleTemp.Width));
                            int indexNative = (yNative * nativeSz.Width) + xNative;

                            float rValue = rData[indexNative] / 255f;
                            float gValue = gData[indexNative] / 255f;
                            float bValue = bData[indexNative] / 255f;

                            heights[index++] = (rValue + gValue + bValue) / 3f;
                        }
                    }
                    /*texture.UnlockRectangle(0);
                    texture.Dispose();*/

                    // calculate normals
                    Vector3[] normals;
                    GenerateMap(heights, size, out normals);

                    // write to texture
                    texStream = texture.LockRectangle(0, LockFlags.None);
                    foreach (Vector3 normal in normals)
                    {
                        texStream.WriteByte((byte)(((normal.Z / 2) + 0.5f) * 255));
                        texStream.WriteByte((byte)(((-normal.Y / 2) + 0.5f) * 255));
                        texStream.WriteByte((byte)(((normal.X / 2) + 0.5f) * 255));
                        texStream.WriteByte(255);
                    }
                    /*foreach (float height in heights)
                    {
                        texStream.WriteByte(0);
                        texStream.WriteByte((byte)(height * 255));
                        texStream.WriteByte(0);
                        texStream.WriteByte(255);
                    }*/
                    texture.UnlockRectangle(0);
                }
                return texture;
            }
        }
예제 #51
0
 /// <summary>
 /// Read a quaternion from open xfile stream
 /// </summary>
 /// <param name="stream"></param>
 /// <returns></returns>
 private static Quaternion ReadQuaternion(GraphicsStream stream)
 {
     Quaternion q = new Quaternion();
     q.W = (float)stream.Read(q.W.GetType());				// must read element by element to get WXYZ order
     q.X = (float)stream.Read(q.X.GetType());
     q.Y = (float)stream.Read(q.Y.GetType());
     q.Z = (float)stream.Read(q.Z.GetType());
     q.Normalize();
     //Debug.WriteLine(ThreeDee.DecodeQuaternion(q));
     return q;
 }
예제 #52
0
        /// <summary>
        /// Write myself to a vertex buffer as a pair of triangles
        /// </summary>
        /// <param name="stream"></param>
        private void Write(GraphicsStream stream)
        {
            // Get a local copy of the untransformed quad
            CustomVertex.PositionNormalTextured[] quad = new CustomVertex.PositionNormalTextured[4];
            for (int v=0; v<4; v++)
            {
                quad[v] = info.quad[v];
            }

            // calculate frame number
            if (info.frameRate!=0)							// if no frame rate, frame represents an unanimated variant
            {
                frame += info.frameRate * Scene.ElapsedTime;
                frame %= info.numFrames;
            }
            float wholeFrame = (int)frame;

            // define the part of the texture to display this frame, in texture coordinates
            float left = wholeFrame * info.width / texWidth;		// fraction of the texture at which this frame starts
            float right = (wholeFrame+1.0f) * info.width / texWidth;
            float top = info.top / texHeight;						// fraction of the texture at which this row starts
            float bot = (info.top + info.height) / texHeight;

            const float border = 0.001f;					// close in a little, to prevent overrunning sprite edges
            left += border;
            right -= border;
            top += border;
            bot -= border;

            quad[0].Tu = left;
            quad[0].Tv = top;
            quad[1].Tu = right;
            quad[1].Tv = top;
            quad[2].Tu = left;
            quad[2].Tv = bot;
            quad[3].Tu = right;
            quad[3].Tv = bot;

            // Get a matrix that will rotate to face camera (around yaw axis only) and then translate into world coordinates
            Matrix trans = facingMatrix * Matrix.Translation(location);

            // We have to transform the vertices ourselves, since there are many sprites in each vertex buffer
            for (int v=0; v<4; v++)
            {
                // Transform the vertex
                quad[v].Position = Vector3.TransformCoordinate(quad[v].Position,trans);
                // Transform the normal
                quad[v].Normal = Vector3.TransformNormal(quad[v].Normal,trans);
            }

            // Add this quad's two triangles to the vertex buffer
            stream.Write(quad[0]);
            stream.Write(quad[1]);
            stream.Write(quad[2]);
            stream.Write(quad[3]);
            stream.Write(quad[2]);
            stream.Write(quad[1]);
        }
 protected override void LoadFromMicrocode(GraphicsStream microcode)
 {
     // create the new vertex shader
     try
     {
         vertexShader = new VertexShader(device, microcode);
     }
     catch (Exception)
     {
         LogManager.Instance.Write("Error loading microcode for vertex program: {0}", Name);
     }
 }
 protected override void LoadFromMicrocode(GraphicsStream microcode)
 {
     // create a new pixel shader
     pixelShader = new PixelShader(device, microcode);
 }
예제 #55
0
 public unsafe virtual LockData Lock(LockFlags flags)
 {
     Texture texture = this.CoreGetSurface();
     if (texture == null)
     {
         return new LockData();
     }
     LockFlags flags2 = 0x800;
     if (flags == LockFlags.ReadOnly)
     {
         flags2 |= 0x10;
     }
     int num = 0;
     GraphicsStream stream = texture.LockRectangle(0, flags2, ref num);
     LockData data = new LockData {
         Pitch = num,
         pvSrc = (void*) stream.get_InternalData(),
         Height = this.Height,
         Width = this.Width
     };
     this.m_LockStream = stream;
     return data;
 }
예제 #56
0
        /// <summary>
        /// Crear vertices para la cara Up
        /// </summary>
        private void cargarVerticesUp(GraphicsStream data, int color)
        {
            TgcSceneLoader.DiffuseMapVertex v;
            Vector3 n = new Vector3(0, 1, 0);

            v = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X - size.X / 2 - skyEpsilon,
                center.Y + size.Y / 2,
                center.Z - size.Z / 2 - skyEpsilon
                );
            v.Normal = n;
            v.Color = color;
            v.Tu = 1;
            v.Tv = 0;
            data.Write(v);

            v = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X - size.X / 2 - skyEpsilon,
                center.Y + size.Y / 2,
                center.Z + size.Z / 2 + skyEpsilon
                );
            v.Normal = n;
            v.Color = color;
            v.Tu = 0;
            v.Tv = 0;
            data.Write(v);

            v = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X + size.X / 2 + skyEpsilon,
                center.Y + size.Y / 2,
                center.Z + size.Z / 2 + skyEpsilon
                );
            v.Normal = n;
            v.Color = color;
            v.Tu = 0;
            v.Tv = 1;
            data.Write(v);

            v = new TgcSceneLoader.DiffuseMapVertex();
            v.Position = new Vector3(
                center.X + size.X / 2 + skyEpsilon,
                center.Y + size.Y / 2,
                center.Z - size.Z / 2 - skyEpsilon
                );
            v.Normal = n;
            v.Color = color;
            v.Tu = 1;
            v.Tv = 1;
            data.Write(v);
        }
 ///<summary>
 ///    Util functions to convert a D3D locked rectangle to a pixel box
 ///</summary>
 protected static void FromD3DLock(PixelBox rval, int pitch, GraphicsStream stream)
 {
     rval.RowPitch = pitch / PixelUtil.GetNumElemBytes(rval.Format);
     rval.SlicePitch = rval.RowPitch * rval.Height;
     Debug.Assert((pitch % PixelUtil.GetNumElemBytes(rval.Format)) == 0);
     rval.Data = stream.InternalData;
 }