how to create complex 3D model in Balder

Jun 24, 2010 at 9:22 AM

I do not want to Load .ASE file to create complex 3D model. Can you tell me how to use Balder to create complex 3D model  in Game class.

I have one car.xaml file, source code as below:

    <Grid x:Name="grdGrid" KeyDown="Grid_KeyDown" Focusable="True">

     <Viewport3D x;name="car"..................>

    <Viewort3D.Camera>

              .......................................

    </Viewort3D.Camera>

    <ModelVisual3D .....................>

    </ModelVisual3D>

   </Grid>

So I want to know ,how to use this xaml in balder to create 3D model

Thanks a lot

Coordinator
Jun 24, 2010 at 11:49 AM

There is no Xaml way of defining 3D models right now.  Its something I've been wanting to do for quite a while, and have been thinking about doing something similar to WPF, or maybe even create a WPF like wrapper for it. 

If you don't want to go with ASE but need a way of doing it programmatically, the following thread might be of interest : 

http://balder.codeplex.com/Thread/View.aspx?ThreadId=216345

Jun 24, 2010 at 11:56 AM

U must download the latest version source code...

I have several Nodes in my project like this:

        <Canvas x:Name="gameHolder" Opacity="1" Grid.Row="0" Grid.Column="1">
            <Execution:Game x:Name="_game" Width="1000" Height="1000" Background="Black"   Canvas.Top="-10"  >
                <Execution:Game.Camera >
                    <View:Camera Position="0,50,-350" Target="0,0,0"/>
                </Execution:Game.Camera>

                <Lighting:OmniLight x:Name="_omni" Position="-100,1700,-400" Ambient="Green" Diffuse="Green" Specular="Blue"/>
                <Geometries:Mesh x:Name="mshPyrUp"   Scale="0.001,0,0.001" Position="-220,-20,0"  Rotation="0,0,0"  Material="{StaticResource logoMaterial3}" AssetName="Portfolio;component//Assets/pirup.ase" IsVisible="False" />
                <Geometries:Mesh x:Name="mshPyrDown" Scale="0.001,0,0.001" Position="-220,-20,0" Rotation="0,0,0"  Material="{StaticResource logoMaterial3}" AssetName="Portfolio;component//Assets/pirdown.ase" IsVisible="False"/>
                <Geometries:Mesh x:Name="mshSphere" Scale="0.001,0,0.001"   Position="-340,-20,150" Rotation="60,0,0"  Material="{StaticResource earthMaterial}" AssetName="Portfolio;component//Assets/sphere.ase" IsVisible="True"/>

                <Geometries:Box  x:Name="mshEvolve1" Dimension="300,75,64" Position="150,-10,40" Rotation="0,0,0"  IsVisible="True"/>

                <Geometries:Box  x:Name="mshMorph"  Dimension="75,100,80" Scale="0.001,0.001,0.001"   Position="-280,-20,90" Rotation="0,0,0"  Material="{StaticResource morphMaterial}"  IsVisible="True"/>

                <!--<Geometries:Mesh x:Name="mshMorph"  Scale="0.001,0,0.001"  Position="-240,-20,30" Rotation="0,0,0"  Material="{StaticResource morphMaterial}" AssetName="Portfolio;component//Assets/morph.ase" IsVisible="True"/>-->
                
                <Geometries:Mesh x:Name="mshRing1" Scale="0.001,0,0.001" Position="-300,-20,50" Rotation="0,0,0"    Material="{StaticResource ringMaterial}" AssetName="Portfolio;component//Assets/ring.ase" IsVisible="True" />
                <Geometries:Mesh x:Name="mshRing2" Scale="0.001,0,0.001"  Position="-300,-20,50" Rotation="0,90,0"    Material="{StaticResource ringMaterial}" AssetName="Portfolio;component//Assets/ring.ase" IsVisible="True"/>
                <Geometries:Mesh x:Name="mshRing3" Scale="0.001,0,0.001"  Position="-300,-20,50" Rotation="0,45,0"   Material="{StaticResource ringMaterial}" AssetName="Portfolio;component/Assets/ring.ase" IsVisible="True"/>
                <Geometries:Mesh x:Name="mshRing4" Scale="0.001,0,0.001"  Position="-300,-20,50" Rotation="0,135,0"   Material="{StaticResource ringMaterial}" AssetName="Portfolio;component/Assets/ring.ase" IsVisible="True"/>


            </Execution:Game>
        </Canvas>

 

And as u can see i've ase files along with balder own geometries, and u can even place nodes inside nodes like this: 

                <Geometries:Geometry >
                    <Geometries:Box  x:Name="mshEvolve1" Dimension="300,75,64" Position="150,-10,40" Rotation="0,0,0"  IsVisible="True"/>

                    <Geometries:Box  x:Name="mshMorph"  Dimension="75,100,80" Scale="0.001,0.001,0.001"   Position="-280,-20,90" Rotation="0,0,0"  Material="{StaticResource morphMaterial}"  IsVisible="True"/>
                </Geometries:Geometry>

 

Include also the namespaces in XAML:

     xmlns:Execution="clr-namespace:Balder.Core.Execution;assembly=Balder.Core"
     xmlns:Geometries="clr-namespace:Balder.Core.Objects.Geometries;assembly=Balder.Core"
     xmlns:Lighting="clr-namespace:Balder.Core.Lighting;assembly=Balder.Core"
     xmlns:View="clr-namespace:Balder.Core.View;assembly=Balder.Core"
     xmlns:Materials="clr-namespace:Balder.Core.Materials;assembly=Balder.Core"         

and of course the DLL's:

Balder.Core.SilverLight, Balder.SilverLight, and Ninject,Core.

Balder as its own primitives like Box, Ring, Sphere and others.

But i rather use 3DSMAX to build complex structures and then export them as ase files..

Good luck, it worths the effort...    
            

 

Jun 25, 2010 at 3:32 AM

Thanks for all your quick reply!

So that is to say, if I want to create my own complex 3D model(not using ase file), the only way is to create a class that inherits from Balder.Core.Objects.Geometry,

And use property called FullDetailLevel to draw the 3D model. Is it right?

If so, can you give me some simple code or tell me detail information about this class function to draw 3D model, because I find that Balder.Documentation.Silverlight.chm is so simple, I can not get enough information to use these class(for example GeometryDetailLevel,GeometryContext............)

For example:

I want draw a 3D car model. I only have the Car.xaml file that contains the xaml element such as Viewort3D, ModelVisual3D and so on.

First, I should create a class:

    public class Car: Geometry

And then what I should do in this class?

thanks.

 

Coordinator
Jun 25, 2010 at 5:28 AM

The easiest thing to do would probably go and see whats being done in Box.cs in Balder.Core.Objects.Geometries. 

Basically, you allocate the amount of vertices, faces and possibly texture coordinates you need, then you set them all.
You have a property called FullDetailLevel when you inherit from GeometryContext, so you don't need to go get it.

Then its just to override the Prepare() method (remember to call the base one when you're done).

FullDetailLevel has AllocateVertices(), AllocateFaces(), AllocateTextureCoordinates(), then you have SetVertex(), SetFace() and SetTextureCoordinate() 

 

The CHM file is way to limited at the moment, I see I have tons of work for documentation that needs to be done. :)

 

Hope that helps. 

Jun 25, 2010 at 12:10 PM

Ur confused man,   u cant use Car.Xaml, cause that is WPF, its not implemented in silverlight...

So therefore u should follow Einari advise and see the Box.cs in geometry as a good template for your own geometry.

Jun 26, 2010 at 3:05 AM

thank you for all of your help. It is very useful.

Coordinator
Aug 1, 2010 at 8:10 AM
Edited Aug 1, 2010 at 8:11 AM

I've created a tutorial for generating a mesh programmatically : http://www.ingebrigtsen.info/post/2010/08/01/Balder-Tutorial-Creating-a-Mesh-programatically.aspx

Aug 3, 2010 at 11:58 AM
Hi adept, May I set the size or color of the vertex?
Aug 3, 2010 at 12:25 PM
A second question: Is there different between FullDetailLevel.SetFace(0, new Face(2, 1, 0)) and FullDetailLevel.SetFace(0, new Face(0, 1, 2)) ?
Coordinator
Aug 3, 2010 at 12:50 PM
Edited Aug 3, 2010 at 12:51 PM
zeyoo wrote:
Hi adept, May I set the size or color of the vertex?

Setting the color of the vertex has no effect at this point. It is something that has been planned to be done, but haven't gotten around to yet. 

 

As for size - what do you mean?

Coordinator
Aug 3, 2010 at 12:52 PM
zeyoo wrote:
A second question: Is there different between FullDetailLevel.SetFace(0, new Face(2, 1, 0)) and FullDetailLevel.SetFace(0, new Face(0, 1, 2)) ?

There might be - depends on how the vertices are defined.

The vertex indexes has to be in a counter clockwize order in order for it to be displayed properly - as mentioned in the tutorial : http://www.ingebrigtsen.info/post/2010/08/01/Balder-Tutorial-Creating-a-Mesh-programatically.aspx