importing Geometry3D

Apr 23, 2012 at 3:56 PM
Edited Apr 23, 2012 at 4:08 PM

 

Hey there,

first of all, i want to thank you for providing such an awesome Toolkit!

Second I have a question concerning the ModelImporter. I was using the beta (helixToolkit-release) for some time now and it was possible to import Geometry3D data by:

  private Geometry3D LoadGeoFromFile(string objPath)
        {
            Model3DGroup group = ModelImporter.Load(objPath);
            GeometryModel3D model = group.Children[0] as GeometryModel3D;
           
            return model.Geometry;

        }

I could afterwards bind the Geometry in Wpf like

 <helix:HelixViewport3D>
                <ModelVisual3D>
                    <helix:DefaultLights/>
                    <ModelVisual3D.Content>
                        <GeometryModel3D Geometry="{Binding TestFile}" Changed="GeometryModel3D_Changed">
                            <GeometryModel3D.Material>
                                <DiffuseMaterial>
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush Color="Gray"/>
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                        
                    </ModelVisual3D.Content>
                </ModelVisual3D>
            </helix:HelixViewport3D> 

and was therefore able to display the geometry just with a plain brush (to improve performance). Right now I tried
the newest source code (to check if loading times etc. improved) but the described procedure isn't working anymore.
The ViewPort only shows parts of the whole model at best.
Did something substantial change which could forbid this way of doing it or is it just a minor thing which I am not seeing ('cause
I am still starting to learn programming)?

Cheers

Mede

 
Coordinator
Apr 25, 2012 at 5:08 AM

What kind of file are you importing? It should still be possible to extract the geometry from the returned Model3D, but I don't think you should depend on this being in Children[0] (an imported file could contain more than one GeometryModel3D).

Apr 25, 2012 at 11:19 AM
Edited Apr 25, 2012 at 1:14 PM

 

Obj.-Files exportet by blender. And you are, of course, completely right concerning the number of geometries in the file. Which is most likely the problem of most models not be shown correctly . For me it seemed to be the easiest way to include lots of models/geometries and be able to transform them in relation to each other by binding (in Wpf), like moving an arm for example. Somehow it was working just fine for the beta-release of helix toolkit.

Seems that I have to find out how I can bind to different models and transform them the correct way =)

 

EDIT: I found a workaround:

 

private Geometry3D LoadFromFile(string objPath)
        {
            Model3DGroup group = ModelImporter.Load(objPath);
            MeshBuilder TestMesh = new MeshBuilder(false, false);


            foreach (var m in group.Children)
            {
                var mGeo = m as GeometryModel3D;
                var mesh = (MeshGeometry3D)((Geometry3D)mGeo.Geometry);
                if (mesh!=null) TestMesh.Append(mesh);
            }
            return TestMesh.ToMesh();

        }

Seems to work fine. Or am I again missing something?

 

Btw. Again: this toolkit is just great! Whenever I think I just don't now how the hell I should accomplish something I find again some nice method to help. =)