I’ve been waiting for a torus primitive to magically appear in Papervision since version 1.7. And it didn’t happen – so I wrote one. Or better yet, I ported the Away3D torus over to Papervision. Thanks Away3D! I’ve always thought that Away3D had a more advanced approach to their primitive set (than Papervision) and this torus port proves it.
The port is actually (almost) set up so it can be generalized to accept any set of parametric equations with two parameters. I have not generalized it, but with a few lines of code you’re there.
I have to thank Gabriel Putnam once again, he had created the geodesic sphere (shown in the previous post) in both Papervision and Away3D and I was able to look at what he did and do the same thing for the torus.
Here are the steps you need to take to port the Away3D torus over to Papervision:
- Place the Away3D Torus primitive in the Papervision 0rg/papervision3d/objects/primitives folder
- Change the package statement to package org.papervision3d.objects.primitives
- Replace the Sand3D imports with the appropriate Papervision imports
- Delete use namespace arcane
- Add super(material, new Array(), new Array(), null); to the constructor method
- Add to the buildTorus method the following lines of code:
this.geometry.ready = true;
var aVertice:Array = this.geometry.vertices;
var aFace:Array = this.geometry.faces;
var aUV:Array = new Array();
- Add aVertice.push(grid[i][j]); to the parametric vertex generation under the if (yUp) statement
- Change createVertex to Vertex3D
- Change all Vertex Type declarations to Vertex3D
- Change all UV Type declarations to NumberUV
addFace(createFace(a, b, c, null, uva, uvb, uvc));
addFace(createFace(d, c, b, null, uvd, uvc, uvb));
aFace.push( new Triangle3D( this, [a, b, c], material, [uva, uvb, uvc])); aFace.push( new Triangle3D( this, [d, c, b], material, [uvd, uvc, uvb]));
- Delete all non-contributing statements (this is pretty easy if you are editing in Flex – just delete the statements that give you an error when you run the torus program)
This post demonstrates how easy it is to port from Away3D, and sets the framework for creating a generalized parametric primitive.
To see the entire torus primitive and its wrapper, click the more button below