
Do you remember LEGO? The "LEGO paradigma" is: you have a group of pieces and, puting them together you construct many toys, sceneries etc.
Look the figure:
Here we have the image of an unfinished "vista" (this word, used in the new Windows means "scenery", something to be viewed) created using Avalon. And we have 3 "pieces" or 3 objects: a floor, a wall-having-a-door and an avatar. We will create our scenes puting together many pieces that can be reused. Something like an "Object Oriented 3D Programming"...
Our "walldoor", by example, will have this .XAML definition:
<MaterialGroup x:Key="walldoorM"> <DiffuseMaterial> <DiffuseMaterial.Brush> <ImageBrush ImageSource="walldoor.png" TileMode="None" ViewportUnits="Absolute" Viewport="0 0 1 1" AlignmentX="Left" AlignmentY="Top" Opacity="1.000000" /> </DiffuseMaterial.Brush> </DiffuseMaterial> <SpecularMaterial SpecularPower="29.8667"> <SpecularMaterial.Brush> <SolidColorBrush Color="#000000" Opacity="1.000000"/> </SpecularMaterial.Brush> </SpecularMaterial> </MaterialGroup> <Transform3DGroup x:Key="walldoorT"> <ScaleTransform3D ScaleX="0.1" ScaleY="0.1" ScaleZ="0.1" /> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Angle="0" Axis="0 1 0"/> </RotateTransform3D.Rotation> </RotateTransform3D> <TranslateTransform3D OOffsetX="0" OffsetY="0" OffsetZ="0" /> </Transform3DGroup> <MeshGeometry3D x:Key="walldoorG" TriangleIndices="0,1,2 3,4,5 6,7,8 9,10,11 12,13,14 15,16,17 18,19,20 21,22,23 24,25,26 27,28,29 30,31,32 33,34,35 36,37,38 39,40,41 42,43,44 45,46,47 48,49,50 51,52,53 54,55,56 57,58,59 60,61,62 63,64,65 66,67,68 69,70,71 72,73,74 75,76,77 78,79,80 81,82,83 " Normals="0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 0,1,0 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 0,-1,-2.22045e-016 9.29428e-008,-1,0 9.29428e-008,-1,0 9.29428e-008,-1,0 9.29428e-008,-1,0 9.29428e-008,-1,0 9.29428e-008,-1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 1,0,0 " TextureCoordinates="1.58615,0.9995 0.88936,0.9995 1.08615,0.9995 1.08615,0.9995 1.38936,0.9995 1.58615,0.9995 0.876388,0.000499547 0.88936,0.000499547 0.88936,0.9995 0.876388,0.851134 0.876388,0.000499547 0.88936,0.9995 0.7828,0.851134 0.876388,0.851134 0.88936,0.9995 0.7828,0.851134 0.88936,0.9995 0.58615,0.9995 0.58615,0.9995 0.58615,0.000499547 0.7828,0.000499547 0.7828,0.851134 0.58615,0.9995 0.7828,0.000499547 0.88936,0.000499547 1.08615,0.000499547 1.08615,0.9995 1.08615,0.9995 0.88936,0.9995 0.88936,0.000499547 0.215341,0.000499547 0.38936,0.000499547 0.38936,0.9995 0.215341,0.851134 0.215341,0.000499547 0.38936,0.9995 0.215341,0.851134 0.38936,0.9995 0.0861497,0.9995 0.102364,0.851134 0.215341,0.851134 0.0861497,0.9995 0.0861497,0.9995 0.0861497,0.000499547 0.102364,0.000499547 0.102364,0.851134 0.0861497,0.9995 0.102364,0.000499547 0.38936,0.000499547 0.58615,0.000499547 0.58615,0.9995 0.58615,0.9995 0.38936,0.9995 0.38936,0.000499547 0.876388,0.000499547 1.10236,0.000499547 1.08615,0.000499547 1.08615,0.000499547 0.88936,0.000499547 0.876388,0.000499547 -0.2172,0.000499547 -0.41385,0.000499547 -0.61064,0.000499547 -0.61064,0.000499547 0.215341,0.000499547 -0.2172,0.000499547 0.7828,0.851134 1.21534,0.851134 1.10236,0.851134 1.10236,0.851134 0.876388,0.851134 0.7828,0.851134 -0.123612,0.851134 0.102364,0.851134 0.102364,0.000499547 0.102364,0.000499547 -0.123612,0.000499547 -0.123612,0.851134 -0.2172,0.000499547 0.215341,0.000499547 0.215341,0.851134 0.215341,0.851134 -0.2172,0.851134 -0.2172,0.000499547 " Positions="-90.7826,70.2609,6.26087 30.9565,70.2609,6.26087 30.9565,70.2609,-3.47826 30.9565,70.2609,-3.47826 -90.7826,70.2609,-3.47826 -90.7826,70.2609,6.26087 20.5217,-1.39019e-015,6.26087 30.9565,-1.39019e-015,6.26087 30.9565,70.2609,6.26087 20.5217,59.8261,6.26087 20.5217,-1.39019e-015,6.26087 30.9565,70.2609,6.26087 -20.5217,59.8261,6.26087 20.5217,59.8261,6.26087 30.9565,70.2609,6.26087 -20.5217,59.8261,6.26087 30.9565,70.2609,6.26087 -90.7826,70.2609,6.26087 -90.7826,70.2609,6.26087 -90.7826,-1.39019e-015,6.26087 -20.5217,-1.39019e-015,6.26087 -20.5217,59.8261,6.26087 -90.7826,70.2609,6.26087 -20.5217,-1.39019e-015,6.26087 30.9565,-1.39019e-015,6.26087 30.9565,7.72329e-016,-3.47826 30.9565,70.2609,-3.47826 30.9565,70.2609,-3.47826 30.9565,70.2609,6.26087 30.9565,-1.39019e-015,6.26087 -20.5217,7.72329e-016,-3.47826 -90.7826,7.72329e-016,-3.47826 -90.7826,70.2609,-3.47826 -20.5217,59.8261,-3.47826 -20.5217,7.72329e-016,-3.47826 -90.7826,70.2609,-3.47826 -20.5217,59.8261,-3.47826 -90.7826,70.2609,-3.47826 30.9565,70.2609,-3.47826 20.5217,59.8261,-3.47826 -20.5217,59.8261,-3.47826 30.9565,70.2609,-3.47826 30.9565,70.2609,-3.47826 30.9565,7.72329e-016,-3.47826 20.5217,7.72329e-016,-3.47826 20.5217,59.8261,-3.47826 30.9565,70.2609,-3.47826 20.5217,7.72329e-016,-3.47826 -90.7826,7.72329e-016,-3.47826 -90.7826,-1.39019e-015,6.26087 -90.7826,70.2609,6.26087 -90.7826,70.2609,6.26087 -90.7826,70.2609,-3.47826 -90.7826,7.72329e-016,-3.47826 20.5217,-1.39019e-015,6.26087 20.5217,7.72329e-016,-3.47826 30.9565,7.72329e-016,-3.47826 30.9565,7.72329e-016,-3.47826 30.9565,-1.39019e-015,6.26087 20.5217,-1.39019e-015,6.26087 -20.5217,-1.39019e-015,6.26087 -90.7826,-1.39019e-015,6.26087 -90.7826,7.72329e-016,-3.47826 -90.7826,7.72329e-016,-3.47826 -20.5217,7.72329e-016,-3.47826 -20.5217,-1.39019e-015,6.26087 -20.5217,59.8261,6.26087 -20.5217,59.8261,-3.47826 20.5217,59.8261,-3.47826 20.5217,59.8261,-3.47826 20.5217,59.8261,6.26087 -20.5217,59.8261,6.26087 20.5217,59.8261,6.26087 20.5217,59.8261,-3.47826 20.5217,7.72329e-016,-3.47826 20.5217,7.72329e-016,-3.47826 20.5217,-1.39019e-015,6.26087 20.5217,59.8261,6.26087 -20.5217,-1.39019e-015,6.26087 -20.5217,7.72329e-016,-3.47826 -20.5217,59.8261,-3.47826 -20.5217,59.8261,-3.47826 -20.5217,59.8261,6.26087 -20.5217,-1.39019e-015,6.26087 " />
WOW! We have lots of numbers! It's impossible to create a piece more complex than a plane not using some tools - we will talk about this soon.
Important to note that a piece (in .XAML format) has 3 basic parts (bold faced above):
1 - a MaterialGroup ;
2 - a Transform3DGroup and
3 - a MeshGeometry3D.
Now, to enhance your culture (ha, ha,ha) we will show how to define a plane "by hand". It will be the floor of some of our exercices.
The plane has 32 x 32 units (we will talk about Avalon "units" soon) and its center is at the point 0,0,0 - the center of the virtual space. The definition of our floor will be:
<MaterialGroup x:Key="floorM">
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ImageSource="floor.png" TileMode="None" ViewportUnits="Absolute" Viewport="0 0 1 1" AlignmentX="Left" AlignmentY="Top" Opacity="1.000000" />
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
<Transform3DGroup x:Key="floorT">
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1" />
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0" />
</Transform3DGroup>
<MeshGeometry3D x:Key="floorG"
Positions="-16 0 16 16 0 16 -16 0 -16 16 0 -16"
Normals="0 1 0 0 1 0 0 1 0 0 1 0"
TextureCoordinates="0 1 1 1 0 0 1 0"
TriangleIndices="0 1 2 1 3 2"
/>
In the MaterialGroup part we assign a name for this part("floorM") and declare the file of the texture (floor.png). The Opacity is: 1.
To the Transform3DGroup part we also assign a name. The scale of our plane will be 1 for each axis. The plane will have a rotation of 0 degrees based in he axis Y (defined by the vector: 0 1 0). And a translation of 0 for X, 0 for Y and 0 for Z.
For the MeshGeometry3D part we have also a name. Look the figure; for Positions we are assigning the points of the vertices.
A mesh is created by many triangles. Look that there are a correspondance between the declaration of the Positions and the 2 triangles defined in the TriangleIndices.
The Normal at each Position is the Y axis (0 1 0). This will be not so easy for a complex mesh. These normal are important, by example, for the ilumination of the piece.
OK. OK. Let's go to stop here.I know that these ideas are a little complicate and (thanks God!) you will not need to create any other piece "by hand".
In the next lesson we will learn how to put our "floor" at the "vista".
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
