Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Geometry ahoy!

Sign in to follow this  


Ok, so I'm not happy with my geometry package. It's responsible for representing geometric objects, such as boxes, spheres and triangle meshes. Here's how you use geometry at the moment, creating a node rendered as a sphere, and collision geometry of the same shape:

geom = Sphere(1) # 1 is radius of the sphere
geomNode = Node()
# 20 and 20 are the amount of horizontal and vertical slices
geomNode.render = geom.createPrimitive(20, 20).render
geomNode.collisionGeometry = geom.createCollisionGeometry()

This has two problems: you can't change collision geometry after you've created it, and geometry has too many responsibilities (geometry classes should be low-level, not caring about graphics and physics). What I'm thinking now is to:
- Have geometry objects create only vertices; normals and texture coordinates can be created afterwards
- Have a factory function in the physics package for creating collision geometry, which would return instances of collision geometry classes

You would use it somewhat like this (I haven't designed the API yet, just pulling something out of my nonexistent hat):

geom = Sphere(1)
vertices = geom.generateMesh(20, 20)
normals = generateNormals(vertices, smooth=False)
texCoords = generateTexCoords(vertices, type="spherical")
primitive = RenderPrimitive(vertices, normals, texCoords)

geomNode = Node()
geomNode.render = primitive.render
geomNode.collisionGeometry = physics.createCollisionGeometry(geom)

More complicated? Yes. More flexible? Yes! Will I provide a higher level interface too? Yes! Will you use mostly use model loading anyway, instead of geometry objects? Yes! The smooth parameter to generateNormals() would dictate if we are creating vertex or face normals. The type parameter to generateTexCoords() specifies the type of projection (spherical, cylindrical, planar etc). Or there could be separate functions or classes for different projections. I dunno... as I said, haven't designed the interface yet.

Maybe geometry could also optionally create normals and indices, since it's already doing the necessary calculations when generating vertices. Like this: vertices, normals, indices = geom.generateMesh(20, 20, normals=True, indices=True)

Comments? Suggestions? Bestest ideas ever, just for me? Please? Pretty pretty please?

(Hmm... maybe I need to change node.render back to an object with a render method instead of a callable, since later I will need the bounding radius of renderables for frustum culling etc...)

Btw. I'll see how easy it would be to create a HTML/CSS TODO list generator with Python. :) I'll post the results or report of my failure later.

EDIT: Ok, I was truck with a Revelation about this, and I think it would be the cleanest way. I was just thinking... how often do you need to render geometry primitives, and does it make any sense to actually keep render geometry and collision geometry in a single class? I have the answer for you: no it doesn't. So, here's aboutish how it will work:

# Alternative 1
vertices, normals, texCoords = graphics.geometry.createSphere(1, normals=True, texCoords=True)

# Alternative 2
vertices = graphics.geometry.createSphere(1)
normals = graphics.geometry.generateNormals(vertices, smooth=True)
texCoords = graphics.geometry.generateTexCoords(vertices, "spherical")

primitive = RenderPrimitive(vertices, normals, texCoords)

geomNode = Node()
geomNode.render = primitive
geomNode.collisionGeometry = physics.geometry.Sphere(1)

Note that in this example, node.render is an object with a render() method again, not a callable.

Any comments on this? :P
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!