helix-toolkit / helix-toolkit

Helix Toolkit is a collection of 3D components for .NET.

Home Page:http://helix-toolkit.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some questions aboat sharpdx

MichaelCHF opened this issue · comments

1.I have a function that needs to display other wpf Windows on a plane surface,I did this by generating a png image(writeablebitmap) of the wpf window and using this image as the texture map,when ui changed,I have to keep creating textures ,My question is how to efficiently generate materials using writeablebimap?
key code:

var mashModel = new MeshGeometryModel3D();
MeshBuilder mb = new MeshBuilder();
mb.AddQuad(p1,p2,p3,p4);
mashModel .Geometry = mb.ToMesh();

if (mWriteableBitmap != null)
                {
                    mWriteableBitmap.Changed -= Img_Changed;
                }
                mWriteableBitmap = service.GetImg(width, height);

                if (mWriteableBitmap != null)
                {
                    mWriteableBitmap.Changed += Img_Changed;
                    mDiffuseMaterial.DiffuseMap = new TextureModel((IntPtr)mWriteableBitmap.BackBuffer, SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb, (int)mWriteableBitmap.Width, (int)mWriteableBitmap.Height);
                    mashModel .Material = mDiffuseMaterial;
                }


private void Img_Changed(object sender, EventArgs e)
        {
            Debug.WriteLine($"imagerefresh:{DateTime.Now.ToString("HH:mm:ss fff")}");

            if (mDiffuseMaterial != null)
            {
                mDiffuseMaterial.DiffuseMap = new TextureModel((IntPtr)mWriteableBitmap.BackBuffer, SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb, (int)mWriteableBitmap.Width, (int)mWriteableBitmap.Height);;
            }
        }

you can see I have to keep creating TextureModel,is there a way to just update the TextureModel by mWriteableBitmap ??
Can i set the back face map uv(DiffuseMap)?

2.when i change the PerspectiveCamera to OrthographicCamera or OrthographicCamera to PerspectiveCamera,How do I calculate the relevant parameters(fov,width,position etc) to ensure that the 3d object remains the same size after switching?

Could you create a sample project for question 1? You probably will need to create your own texture loader to upload new bitmap data into texture object instead of creating new material in each frame.