No opacity after importing 3ds file

Anonymous 10 years ago 0
This discussion was imported from CodePlex

mmmmmm wrote at 2012-11-04 17:24:


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



mmmmmm wrote at 2012-11-06 08:37:


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);

//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));
                    Debug.WriteLine(string.Format("Texture not found: {0}", Path.GetFullPath(path)));
                    mg.Children.Add(new DiffuseMaterial(new SolidColorBrush(diffuse) { Opacity = opacity }));
                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;

objo wrote at 2012-11-06 19:28:

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?

mmmmmm wrote at 2012-11-07 07:48:

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


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?

musicxpg wrote at 2013-02-25 14:33:

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!

mmmmmm wrote at 2013-02-25 15:48:

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.