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

January 22nd, 2009 at 6:44 pm
Silverlight can’t be better: it lacks on non-affine matrix transformations!
(Cube faces are splitted into triangles - there’s no other way to texture a polygonal surface in SL - so they aren’t perfectly mapped as those made in flash)
Silverlight likely will be better, as its 3(r)d version will be released ;)
January 22nd, 2009 at 8:59 pm
This is one of the first examples where I can say there is a big difference between the two and the first time I can say that Flash is far better in this example. If you look at the center of the pictures in the Silverlight example it seems to dip in or something when it rotates to the front.
On a side note, please continue to do these demos between Flash and Silverlight. They are great at showing how similar and yet how different they really are.
January 22nd, 2009 at 10:44 pm
Let me add something here. Actually, the “dip in” Steve Buchok mentioned can be fixed with some modification of coding.
For the sample in flash, the SEGMENT value is set to 4. That’s why it looks very smooth.
While in Silverlight, the algorithm is a little bit differenet. Althought there is no Segement parameter when creating the plane, it is already defined in the method generatePlaneMesh().
You may create a more comlex point collection to increae the “segment”. However, I am too lazy (and also too complicated) to that.
January 23rd, 2009 at 11:34 am
Can’t test silverlight:
Microsoft Silverlight is not supported in your operating environment.
I assume this as however cool the features it can provide, it limit amount of viewers/visitors.
January 23rd, 2009 at 3:22 pm
i think the flash is much more like our think about the 3d worlds, but the silver light is much like a coder of 3d engine. silver light is much detialed and much more knowlege about the 3d mathmatic and theory. flash seams much object oriented. that is all.
January 23rd, 2009 at 8:00 pm
Hi,
the source code link for silverlight point to “ImageSpace3D_Silverlight.zip” (which BTW is also cool but not quite what I want to play with ;-)
February 3rd, 2009 at 1:42 pm
Hi Terence, Nice job. For a long time I have been finding some methods to 3D in flash.
March 7th, 2009 at 2:20 pm
[...] Papever Vision 3D and Kit 3D. This post is actually a minor modification of my previous article Image Rotating Cube. I suppose the Flash and Silverlight versions will look like more or less the same as in the last [...]
March 12th, 2009 at 9:33 am
I think Silverlight Image Rotating Cube moved deeper than Flash ones,so the speed looks like slower than Flash.
July 31st, 2009 at 9:50 pm
Flash is much better, I think it use a bilinear (or trilinear) interpolation for texture mapping, while Silverlight use a simple linear interpolation.
September 15th, 2009 at 8:03 am
It’d be nice to see you redo this example in Silverlight 3.
September 28th, 2009 at 8:22 am
[...] Terence Tsang used Kit3D to create an image rotating cube. Pretty interesting! [...]
December 19th, 2009 at 4:28 pm
Substantially, the article is in reality the greatest on this worthw hile topic. I fit in with your conclusions and will thirstily look forward to your incoming updates. Saying thanks will not just be adequate, for the phenomenal lucidity in your writing. I will directly grab your rss feed to stay informed of any updates. Authentic work and much success in your business enterprise!
June 6th, 2010 at 10:51 pm
Wow!!. it very cool. thankyou for this code.
September 2nd, 2010 at 9:07 am
Hey… I tried to show the flash version as an external swf in an other swf… and the it f..ked up… anyone tried this and got it to work?