use of net.drewke.tdme.engine.primitives.BoundingBox in project tdme by andreasdr.
the class EntityBoundingVolumeView method resetBoundingVolume.
/**
* Reset bounding volume
* @param entity
* @param idx
*/
public void resetBoundingVolume(LevelEditorEntity entity, int idx) {
// determine AABB
BoundingBox aabb = null;
// if we have a model we also have a AABB
if (entity.getModel() != null) {
aabb = entity.getModel().getBoundingBox();
} else {
// otherwise just create one for now
// this applies currently for particle systems
// TODO: check if particle system
aabb = new BoundingBox(new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 3f, 0.5f));
}
// set up oriented bounding box
OrientedBoundingBox obb = new OrientedBoundingBox(aabb);
// set up sphere
modelViewerScreenController.setupSphere(idx, obb.getCenter(), obb.getHalfExtension().computeLength());
// set up capsule
{
Vector3 a = new Vector3();
Vector3 b = new Vector3();
float radius = 0.0f;
float[] halfExtensionXYZ = obb.getHalfExtension().getArray();
// determine a, b
if (halfExtensionXYZ[0] > halfExtensionXYZ[1] && halfExtensionXYZ[0] > halfExtensionXYZ[2]) {
radius = (float) Math.sqrt(halfExtensionXYZ[1] * halfExtensionXYZ[1] + halfExtensionXYZ[2] * halfExtensionXYZ[2]);
a.set(obb.getAxes()[0]);
a.scale(-(halfExtensionXYZ[0] - radius));
a.add(obb.getCenter());
b.set(obb.getAxes()[0]);
b.scale(+(halfExtensionXYZ[0] - radius));
b.add(obb.getCenter());
} else if (halfExtensionXYZ[1] > halfExtensionXYZ[0] && halfExtensionXYZ[1] > halfExtensionXYZ[2]) {
radius = (float) Math.sqrt(halfExtensionXYZ[0] * halfExtensionXYZ[0] + halfExtensionXYZ[2] * halfExtensionXYZ[2]);
a.set(obb.getAxes()[1]);
a.scale(-(halfExtensionXYZ[1] - radius));
a.add(obb.getCenter());
b.set(obb.getAxes()[1]);
b.scale(+(halfExtensionXYZ[1] - radius));
b.add(obb.getCenter());
} else {
radius = (float) Math.sqrt(halfExtensionXYZ[0] * halfExtensionXYZ[0] + halfExtensionXYZ[1] * halfExtensionXYZ[1]);
a.set(obb.getAxes()[2]);
a.scale(-(halfExtensionXYZ[2] - radius));
a.add(obb.getCenter());
b.set(obb.getAxes()[2]);
b.scale(+(halfExtensionXYZ[2] - radius));
b.add(obb.getCenter());
}
// setup capsule
modelViewerScreenController.setupCapsule(idx, a, b, radius);
}
// set up AABB bounding box
modelViewerScreenController.setupBoundingBox(idx, aabb.getMin(), aabb.getMax());
// set up oriented bounding box
modelViewerScreenController.setupOrientedBoundingBox(idx, obb.getCenter(), obb.getAxes()[0], obb.getAxes()[1], obb.getAxes()[2], obb.getHalfExtension());
//
modelViewerScreenController.selectBoundingVolume(idx, EntityBoundingVolumeSubScreenController.BoundingVolumeType.NONE);
}
use of net.drewke.tdme.engine.primitives.BoundingBox in project tdme by andreasdr.
the class TMReader method read.
/**
* TDME model format reader
* @param path name
* @param file name
* @throws IOException
* @throws ModelIOException
* @return model
*/
public static Model read(String pathName, String fileName) throws IOException, ModelFileIOException {
InputStream is = null;
try {
is = FileSystem.getInstance().getInputStream(pathName, fileName);
// version major.minor = 1.0
String fileId = readString(is);
if (fileId == null || fileId.equals("TDME Model") == false) {
throw new ModelFileIOException("File is not a TDME model file, file id = '" + fileId + "'");
}
byte[] version = new byte[3];
version[0] = readByte(is);
version[1] = readByte(is);
version[2] = readByte(is);
if (version[0] != 1 || version[1] != 0 || version[2] != 0) {
throw new ModelFileIOException("Version mismatch, should be 1.0.0, but is " + version[0] + "." + version[1] + "." + version[2]);
}
// meta data
String name = readString(is);
// up vector, rotation order, bounding box
UpVector upVector = UpVector.valueOf(readString(is));
RotationOrder rotationOrder = RotationOrder.valueOf(readString(is));
BoundingBox boundingBox = new BoundingBox(new Vector3(readFloatArray(is)), new Vector3(readFloatArray(is)));
// create object
Model model = new Model(pathName + File.separator + fileName, fileName, upVector, rotationOrder, boundingBox);
// set additional data
model.setFPS(readFloat(is));
model.getImportTransformationsMatrix().set(readFloatArray(is));
// materials
int materialCount = readInt(is);
for (int i = 0; i < materialCount; i++) {
Material material = readMaterial(is);
model.getMaterials().put(material.getId(), material);
}
// sub groups
readSubGroups(is, model, null, model.getSubGroups());
//
return model;
} catch (IOException ioe) {
throw ioe;
} catch (ModelFileIOException mfioe) {
throw mfioe;
} finally {
if (is != null) {
is.close();
}
}
}
use of net.drewke.tdme.engine.primitives.BoundingBox in project tdme by andreasdr.
the class PartitionQuadTree method createPartition.
/**
* Creates a partition
* @param parent
* @param x
* @param y
* @param z
* @param partition size
* @return partition tree node
*/
public PartitionTreeNode createPartition(PartitionTreeNode parent, int x, int y, int z, float partitionSize) {
PartitionTreeNode node;
node = new PartitionTreeNode();
node.partitionSize = partitionSize;
node.x = x;
node.y = y;
node.z = z;
node.parent = parent;
node.bv = new BoundingBox(new Vector3(x * partitionSize, y * partitionSize, z * partitionSize), new Vector3(x * partitionSize + partitionSize, y * partitionSize + partitionSize, z * partitionSize + partitionSize));
// System.out.println(this.hashCode() + ":" + "FrumstumPartition::createPartition()::" + node.bv);
node.subNodes = null;
node.subNodesByCoordinate = null;
node.partitionObjects = null;
// register in parent sub nodes
if (parent.subNodes == null) {
parent.subNodes = new ArrayList<PartitionTreeNode>();
}
parent.subNodes.add(node);
// register in parent sub nodes by coordinate
if (parent.subNodesByCoordinate == null) {
parent.subNodesByCoordinate = new HashMap<Key, PartitionTreeNode>();
}
Key key = new Key();
key.reset();
key.append(node.x);
key.append(",");
key.append(node.y);
key.append(",");
key.append(node.z);
parent.subNodesByCoordinate.put(key, node);
// create sub nodes
if (partitionSize > PARTITION_SIZE_MIN) {
for (int _y = 0; _y < 2; _y++) for (int _x = 0; _x < 2; _x++) for (int _z = 0; _z < 2; _z++) {
createPartition(node, (int) ((x * partitionSize) / (partitionSize / 2f)) + _x, (int) ((y * partitionSize) / (partitionSize / 2f)) + _y, (int) ((z * partitionSize) / (partitionSize / 2f)) + _z, partitionSize / 2f);
}
} else {
node.partitionObjects = new ArrayList<Entity>();
}
//
return node;
}
Aggregations