private void writeRigidBodies(Document document) {
		for (int i = 0; i < rigidBodies.size(); i++) {
			RigidBody body = rigidBodies.get(i);
			Element rigidBody = document.createElement("rigid_body");
			String type = ((body.getDynamicsType() / 100) == 1) ? "dynamic"
					: ((body.getDynamicsType() / 100) == 2) ? "static"
							: "kinematic";
			rigidBody.setAttribute("type", type);
			Element position = document.createElement("position");
			position.appendChild(document.createTextNode(write3Tuple(body
					.getPosition())));
			Element rotation = document.createElement("rotation");
			rotation.appendChild(document.createTextNode(write4Tuple(body
					.getRotation())));
			Element linvel = document.createElement("linear_velocity");
			linvel.appendChild(document.createTextNode(write3Tuple(body
					.getLinearVelocity())));
			Element angvel = document.createElement("angular_velocity");
			angvel.appendChild(document.createTextNode(write3Tuple(body
					.getAngularVelocity())));
			Element restitution = document.createElement("restitution");
			restitution.appendChild(document.createTextNode(Double
					.toString(body.getRestitution())));
			Element friction = document.createElement("friction");
			friction.appendChild(document.createTextNode(Double.toString(body
					.getFriction())));
			Element mass = document.createElement("mass");
			mass.appendChild(document.createTextNode(Double.toString(body
					.getMass())));
			Element lifetime = document.createElement("life_time");
			lifetime.appendChild(document.createTextNode(Double.toString(body
					.getLifeTime())));
			// TODO other geometry types
			Element geometry = document.createElement("geometry");
			if (body.getCollisionObject() instanceof MeshObject) {
				geometry.setAttribute("type", "mesh");
				MeshObject meshObject = (MeshObject) body.getCollisionObject();
				Element assetID = document.createElement("asset_id");
				assetID.appendChild(document.createTextNode(""
						+ meshObject.getMeshAsset().getID()));
				geometry.appendChild(assetID);
			} else if (body.getCollisionObject() instanceof SphereObject) {
				geometry.setAttribute("type", "sphere");
				SphereObject sphereObject = (SphereObject) body
						.getCollisionObject();
				Element radius = document.createElement("radius");
				radius.appendChild(document.createTextNode(Double
						.toString(sphereObject.getRadius())));
				Element divisions = document.createElement("divisions");
				divisions.appendChild(document.createTextNode(Integer
						.toString(sphereObject.getDivisions())));
				geometry.appendChild(radius);
				geometry.appendChild(divisions);
			} else if (body.getCollisionObject() instanceof PlaneObject) {
    		    geometry.setAttribute("type", "plane");
    		    PlaneObject plane = (PlaneObject) body.getCollisionObject();
    		    Element dimensions = document.createElement("dimensions");
    		    dimensions.appendChild(document.createTextNode(writeArray(plane.getDimensions())));

			}
			
			Element effect = document.createElement("effect");
			if (body.getEffect() instanceof Vortex) {
				effect.setAttribute("type", "vortex");
				Vortex thisEffect = (Vortex) body.getEffect();
				Element strength = document.createElement("strength");
				strength.appendChild(document.createTextNode(Double.toString(thisEffect.getStrength())));
				Element innerRadius = document.createElement("inner_radius");
				innerRadius.appendChild(document.createTextNode(Double.toString(thisEffect.getInnerRadius())));
				Element outerRadius = document.createElement("outer_radius");
				outerRadius.appendChild(document.createTextNode(Double.toString(thisEffect.getOuterRadius())));
				Element localAxis = document.createElement("local_axis");
				localAxis.appendChild(document.createTextNode(write3Tuple(thisEffect.getLocalAxis())));
				effect.appendChild(strength);
				effect.appendChild(innerRadius);
				effect.appendChild(outerRadius);
				effect.appendChild(localAxis);
			} else if (body.getEffect() instanceof ForceField) {
				effect.setAttribute("type", "force_field");
				ForceField thisEffect = (ForceField) body.getEffect();
				Element strength = document.createElement("strength");
				strength.appendChild(document.createTextNode(Double.toString(thisEffect.getStrength())));
				Element innerRadius = document.createElement("inner_radius");
				innerRadius.appendChild(document.createTextNode(Double.toString(thisEffect.getInnerRadius())));
				Element outerRadius = document.createElement("outer_radius");
				effect.appendChild(strength);
				effect.appendChild(innerRadius);
				effect.appendChild(outerRadius);
			}

			rigidBody.appendChild(position);
			rigidBody.appendChild(rotation);
			rigidBody.appendChild(linvel);
			rigidBody.appendChild(angvel);
			rigidBody.appendChild(restitution);
			rigidBody.appendChild(friction);
			rigidBody.appendChild(mass);
			rigidBody.appendChild(lifetime);
			rigidBody.appendChild(geometry);
			rigidBody.appendChild(effect);
			document.getFirstChild().appendChild(rigidBody);
		}
	}