Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some questions aboat sharpdx #2137

Open
MichaelCHF opened this issue Feb 7, 2024 · 1 comment
Open

some questions aboat sharpdx #2137

MichaelCHF opened this issue Feb 7, 2024 · 1 comment

Comments

@MichaelCHF
Copy link

MichaelCHF commented Feb 7, 2024

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?

@MichaelCHF MichaelCHF changed the title some questions a boat sharpdx some questions aboat sharpdx Feb 18, 2024
@holance
Copy link
Member

holance commented Mar 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants