It’s time for comparing 3D technology again! That’s the second application I implemented using Kit3D and PaperVision3D.
The coding is very straight forward. It also includes a lot of useful references for modeling 3D objects like creating a texture mapped plane, transformation, rotation, alpha, double faced and camera moving.
Once again, I think Paper Vision 3D is better than Kit 3D. The main reason is that I think the coding in AS3 is much more easier to understand.
I am quite satisfied with the coding this time. It’s worth for you to keep a copy!!!
Images used in this sample are collected from Yuki Holland.
Comparison
Flash implementation: 45 minutes (Implemented First)
Silverlight implementation: 45 minutes
What’s the difference?
- Create Texture mapped plane [AS3] vs [C#]
Source codes
3D Image Cube [Flash 9, AS3] (908.3 KiB, 2,790 hits)
3D Image Cube [Silverlight 2, C#] (338 KiB, 2,982 hits)
Flash
Silverlight
Create Texture mapped plane [AS3] vs [C#]
Here I will show you how to create a textured mapped plane using PaperVision3D. You can also see how can I position the 3D object.
// AS3 // image is a exported image resources inside the fla var bitmapData : BitmapData = new image(0, 0); var bitmapMaterial : BitmapMaterial = new BitmapMaterial(bitmapData); bitmapMaterial.doubleSided = true; var plane : Plane = new Plane( bitmapMaterial, IMAGE_WIDTH, IMAGE_HEIGHT, SEGMENT, SEGMENT ); // position the plane plane.rotationX = rotationX; plane.rotationY = rotationY; plane.rotationZ = rotationZ; plane.x = newX; plane.y = newY; plane.z = newZ;
For Kit 3D, the coding is much more longer. Please let me know if you don’t understand what they are doing.
// C#
// create image brush resources
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(imagePath, UriKind.Relative));
// create bitmap material
GeometryModel3D model = new GeometryModel3D();
model.Geometry = generatePlaneMesh();
model.Material = new DiffuseMaterial(new Kit3DBrush(imageBrush, (int)IMAGE_WIDTH, (int)IMAGE_HEIGHT));
model.SeamSmoothing = 1;
model.BackMaterial = model.Material;
// Create the transform
Transform3DGroup tg = new Transform3DGroup();
tg.Children.Add(new TranslateTransform3D(x, y, z));
tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(rotationX, rotationY, rotationZ), 90), new Point3D(x, y, z)));
}
// create the model based on the material and transform
ModelVisual3D modvis = new ModelVisual3D();
modvis.Transform = tg;
modvis.Content = model;
// a standard texture mapping mesh
private MeshGeometry3D generatePlaneMesh()
{
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions = new Point3DCollection
{
new Point3D(-1, 1, 0),
new Point3D(1, 1, 0),
new Point3D(-1, -1, 0),
new Point3D(1, -1, 0)
};
mesh.TriangleIndices = new Int32Collection
{
0, 2, 1,
1, 2, 3
};
mesh.TextureCoordinates = new Kit3D.Windows.Media.PointCollection
{
new Point(0, 0),
new Point(1, 0),
new Point(0, 1),
new Point(1, 1)
};
return mesh;
}
