No opacity after importing 3ds file

Nov 4, 2012 at 4:24 PM

Hi,

have some problems after importing transparent 3ds files, transparent objects didn't show transparency. Didn't found an entry for opacity within the studio importer. Are there some sub defines for edit_material something like MAT_OPACITY missing?

Would be thankful for response

mm

 

Nov 6, 2012 at 7:37 AM

Hi,

solve it as a first step, but there is still a problem with the correct opacity value (double), hope I can solve it later:

// add to enum ChunkID
// below sub defines of EDIT_MATERIAL
            MAT_TRANSPARENCY = 0xA050,

//add to function ReadMaterial

                    case ChunkID.MAT_TRANSPARENCY:
                        bytes = this.ReadData(reader, size - 6);
                        if (BitConverter.IsLittleEndian)
                            bytes = ReverseBytes(bytes);
                        opacity = BitConverter.ToDouble(bytes, 0);
                        break;

//change in function ReadMaterial (add opacity to brushes)
            if (texture != null)
            {
                string ext = Path.GetExtension(texture);
                if (ext != null)
                {
                    ext = ext.ToLower();
                }

                // TGA not supported - convert textures to .png!
                if (ext == ".tga")
                {
                    texture = Path.ChangeExtension(texture, ".png");
                }

                var actualTexturePath = this.TexturePath ?? string.Empty;
                string path = Path.Combine(actualTexturePath, texture);
                if (File.Exists(path))
                {
                    var img = new BitmapImage(new Uri(path, UriKind.Relative));
                    var textureBrush = new ImageBrush(img) { Opacity = opacity,  ViewportUnits = BrushMappingMode.Absolute, TileMode = TileMode.Tile };
                    mg.Children.Add(new DiffuseMaterial(textureBrush));
                }
                else
                {
                    Debug.WriteLine(string.Format("Texture not found: {0}", Path.GetFullPath(path)));
                    mg.Children.Add(new DiffuseMaterial(new SolidColorBrush(diffuse) { Opacity = opacity }));
                }
            }
            else
            {
                mg.Children.Add(new DiffuseMaterial(new SolidColorBrush(diffuse) { Opacity = opacity }));
            }

            mg.Children.Add(new SpecularMaterial(new SolidColorBrush(specular) { Opacity = opacity }, specularPower) );

// add function
        private static byte[] ReverseBytes(byte[] inArray)
        {
            int highCtr = inArray.Length - 1;

            for (int ctr = 0; ctr < inArray.Length / 2; ctr++)
            {
                byte temp = inArray[ctr];
                inArray[ctr] = inArray[highCtr];
                inArray[highCtr] = temp;
                highCtr -= 1;
            }
            return inArray;
        }
Coordinator
Nov 6, 2012 at 6:28 PM

thanks for sharing the code! Do you have a small example file we can use to test? Can you create a fork with your changes?

Nov 7, 2012 at 6:48 AM

Hi objo,

thanks for responding. Yes, we (Gregor (glgweeke) and me) want to make a branch end of month with some addings: we want to check in the last release of the VRML reader, the visibility problem and a box extension to multi material box. I will add a transparency sample for 3ds.

Best regards

Manfred

Von: objo [email removed]
Gesendet: Dienstag, 6. November 2012 20:29
An: mm@mm-ing.de
Betreff: Re: No opacity after importing 3ds file [helixToolkit:401840]

From: objo

thanks for sharing the code! Do you have a small example file we can use to test? Can you create a fork with your changes?

Feb 25, 2013 at 1:33 PM
Is this problem solved in the newest version?

I tried the newest version, the same problem occurs.

Can anybody tell me which file should be modified to introduce mmmmmm's contribution? Thank you!
Feb 25, 2013 at 2:48 PM
Still not solved completely. The file I had changed: StudioReader.cs in folder Importers.
Values were taken from Blender, but Meshlap seems to have better values. If you have some time, please search in Meshlap for opacity part and copy it into the StudioReader.