hjoykim / THREE

c# port of Three.js
MIT License
118 stars 20 forks source link

boneMatrices cannot be converted into a Bitmap #8

Open michaelsakharov opened 2 years ago

michaelsakharov commented 2 years ago

Trying to get Skeletons and SkinnedMesh's working, but ran into an issue. In the GLRenderer line 1576, it's trying to convert a Float array into a bitmap, this goes back to the issue before with LTC textures, I'm unsure if we can even store floats in a bitmap.

image

hjoykim commented 2 years ago

I found that float array can not convert to image directly. so, I will change this code lie as below, but I do not test this code

                        var data = new byte[ (int)(size * size * 4) ]; // 4 floats per RGBA pixel
                        for(var i = 0; i < size-4; i+=4)
                        {
                            data[i] = (byte)System.Math.Round(skeleton.BoneMatrices[i] * 255);
                            data[i+1] = (byte)System.Math.Round(skeleton.BoneMatrices[i+1] * 255);
                            data[i+2] = (byte)System.Math.Round(skeleton.BoneMatrices[i+2] * 255);
                            data[i+3] = 255;
                        }
                        unsafe
                        {
                            fixed (byte* ptr = data)
                            {
                                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(1, (int)size, (int)size, 
                                System.Drawing.Imaging.PixelFormat.Format32bppArgb, new IntPtr(ptr));

                                var boneTexture = new DataTexture(bitmap, (int)size, (int)size, (int)PixelFormat.Rgba, Constants.FloatType);
                                skeleton.BoneTexture = boneTexture;
                                skeleton.BoneTextureSize = (int)size;
                            }
                        }
michaelsakharov commented 2 years ago

It's not throwing any errors anymore but I'm still unable to get any Skinned Meshes to work. Their rendering is just fine, but the Bones are not functional.