use of org.rajawali3d.loader.ParsingException in project Rajawali by Rajawali.
the class LoaderFBX method setMeshTextures.
private void setMeshTextures(Object3D o, String name) throws TextureException, ParsingException {
Stack<FBXValues.Objects.Texture> textures = mFbx.objects.textures;
Stack<Connect> connections = mFbx.connections.connections;
int numTex = textures.size();
int numCon = connections.size();
for (int i = 0; i < numTex; ++i) {
FBXValues.Objects.Texture tex = textures.get(i);
for (int j = 0; j < numCon; ++j) {
Connect conn = connections.get(j);
if (conn.object2.equals(name) && conn.object1.equals(tex.textureName)) {
// -- one texture for now
String textureName = tex.fileName;
Bitmap bitmap = null;
if (mFile == null) {
int identifier = mResources.getIdentifier(getFileNameWithoutExtension(textureName).toLowerCase(Locale.US), "drawable", mResources.getResourcePackageName(mResourceId));
bitmap = BitmapFactory.decodeResource(mResources, identifier);
} else {
try {
String filePath = mFile.getParent() + File.separatorChar + getOnlyFileName(textureName);
bitmap = BitmapFactory.decodeFile(filePath);
} catch (Exception e) {
throw new ParsingException("[" + getClass().getCanonicalName() + "] Could not find file " + getOnlyFileName(textureName));
}
}
o.getMaterial().setColorInfluence(0);
o.getMaterial().addTexture(new Texture(textureName.replaceAll("[\\W]|_", ""), bitmap));
return;
}
}
}
}
use of org.rajawali3d.loader.ParsingException in project Rajawali by Rajawali.
the class LoaderMD5Anim method parse.
public LoaderMD5Anim parse() throws ParsingException {
super.parse();
BufferedReader buffer = null;
if (mFile == null) {
InputStream fileIn = mResources.openRawResource(mResourceId);
buffer = new BufferedReader(new InputStreamReader(fileIn));
} else {
try {
buffer = new BufferedReader(new FileReader(mFile));
} catch (FileNotFoundException e) {
RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
e.printStackTrace();
}
}
mSequence = new SkeletalAnimationSequence(mAnimationName);
SkeletalAnimationFrame[] frames = null;
String line;
try {
while ((line = buffer.readLine()) != null) {
line = line.replace("\t", " ");
StringTokenizer parts = new StringTokenizer(line, " ");
int numTokens = parts.countTokens();
if (numTokens == 0)
continue;
String type = parts.nextToken();
if (type.equalsIgnoreCase(MD5_VERSION)) {
} else if (type.equalsIgnoreCase(COMMAND_LINE)) {
} else if (type.equalsIgnoreCase(NUM_JOINTS)) {
mNumJoints = Integer.parseInt(parts.nextToken());
mJoints = new SkeletonJoint[mNumJoints];
} else if (type.equalsIgnoreCase(NUM_FRAMES)) {
mSequence.setNumFrames(Integer.parseInt(parts.nextToken()));
frames = new SkeletalAnimationFrame[mSequence.getNumFrames()];
} else if (type.equalsIgnoreCase(FRAME_RATE)) {
mSequence.setFrameRate(Integer.parseInt(parts.nextToken()));
} else if (type.equalsIgnoreCase(NUM_ANIMATED_COMPONENTS)) {
mNumAnimatedComponents = Integer.parseInt(parts.nextToken());
} else if (type.equalsIgnoreCase(HIERARCHY)) {
parseHierarchy(buffer);
} else if (type.equalsIgnoreCase(BOUNDS)) {
parseBounds(frames, buffer);
} else if (type.equalsIgnoreCase(FRAME)) {
parseFrame(frames, Integer.parseInt(parts.nextToken()), buffer);
} else if (type.equalsIgnoreCase(BASEFRAME)) {
mBaseFrame = new SkeletonJoint[mNumJoints];
parseBaseFrame(buffer);
}
}
buffer.close();
} catch (Exception e) {
e.printStackTrace();
}
mSequence.setFrames(frames);
return this;
}
use of org.rajawali3d.loader.ParsingException in project Rajawali by Rajawali.
the class LoaderMD5Mesh method parse.
@Override
public LoaderMD5Mesh parse() throws ParsingException {
super.parse();
BufferedReader buffer = null;
if (mFile == null) {
InputStream fileIn = mResources.openRawResource(mResourceId);
buffer = new BufferedReader(new InputStreamReader(fileIn));
} else {
try {
buffer = new BufferedReader(new FileReader(mFile));
} catch (FileNotFoundException e) {
RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
throw new ParsingException(e);
}
}
String line;
try {
while ((line = buffer.readLine()) != null) {
StringTokenizer parts = new StringTokenizer(line, " ");
int numTokens = parts.countTokens();
if (numTokens == 0)
continue;
String type = parts.nextToken();
if (type.equalsIgnoreCase(MD5_VERSION)) {
if (RajLog.isDebugEnabled())
RajLog.d("MD5 Version: " + parts.nextToken());
} else if (type.equalsIgnoreCase(COMMAND_LINE)) {
} else if (type.equalsIgnoreCase(NUM_JOINTS)) {
mNumJoints = Integer.parseInt(parts.nextToken());
mJoints = new SkeletonJoint[mNumJoints];
} else if (type.equalsIgnoreCase(NUM_MESHES)) {
mNumMeshes = Integer.parseInt(parts.nextToken());
mMeshes = new SkeletonMeshData[mNumMeshes];
} else if (type.equalsIgnoreCase(JOINTS)) {
parseJoints(buffer);
} else if (type.equals(MESH)) {
parseMesh(buffer);
}
}
buffer.close();
buildBindPose();
buildMeshes();
calculateNormals();
createObjects();
} catch (Exception tme) {
try {
buffer.close();
} catch (Exception ex) {
}
throw new ParsingException(tme);
} finally {
mMeshes = null;
mJoints = null;
mBindPoseMatrix = null;
mInverseBindPoseMatrix = null;
}
return this;
}
use of org.rajawali3d.loader.ParsingException in project Rajawali by Rajawali.
the class BlockMeshInstance method parseBlock.
public void parseBlock(AWDLittleEndianDataInputStream dis, BlockHeader blockHeader) throws Exception {
// Parse scene block
RajLog.d("Parsing SceneGraph Block at position: " + dis.getPosition());
mSceneGraphBlock = new SceneGraphBlock();
mSceneGraphBlock.readGraphData(blockHeader, dis);
// Block id for geometry
mGeometryID = dis.readUnsignedInt();
// Lookup the geometry or create it if it does not exist.
final BlockHeader geomHeader = blockHeader.blockHeaders.get((short) mGeometryID);
if (geomHeader == null) {
mGeometry = new Object3D(mSceneGraphBlock.lookupName);
} else {
if (geomHeader.parser == null || !(geomHeader.parser instanceof ABaseObjectBlockParser))
throw new ParsingException("Invalid block reference.");
mGeometry = ((ABaseObjectBlockParser) geomHeader.parser).getBaseObject3D().clone(false, true);
mGeometry.setName(mSceneGraphBlock.lookupName);
}
// Apply the materials
final int materialCount = dis.readUnsignedShort();
final Material[] materials = new Material[materialCount];
for (int i = 0; i < materialCount; ++i) {
final long materialID = dis.readUnsignedInt();
if (materialID == 0) {
materials[i] = getDefaultMaterial();
materials[i].addTexture(getDefaultTexture());
} else {
final BlockHeader materialHeader = blockHeader.blockHeaders.get((short) materialID);
if (materialHeader == null || materialHeader.parser == null || !(materialHeader.parser instanceof ATextureBlockParser))
throw new ParsingException("Invalid block reference " + materialID);
materials[i] = ((ATextureBlockParser) materialHeader.parser).getMaterial();
}
}
// mesh instance properties; does it cast a shadow?
AwdProperties properties = dis.readProperties(EXPECTED_PROPS);
mCastsShadow = (boolean) properties.get(PROP_CASTS_SHADOW, true);
final Matrix4 matrix = new Matrix4(mSceneGraphBlock.transformMatrix);
// Set translation
mGeometry.setPosition(matrix.getTranslation());
// Set scale
final Vector3 scale = matrix.getScaling();
mGeometry.setScale(scale.y, scale.x, scale.z);
// Set rotation
mGeometry.setOrientation(new Quaternion().fromMatrix(matrix));
int m = 0;
if (!mGeometry.isContainer())
mGeometry.setMaterial(materials[m++]);
for (int i = 0; i < mGeometry.getNumChildren(); i++) mGeometry.getChildAt(i).setMaterial(materials[Math.min(materials.length - 1, m++)]);
// ignore user properties, skip to end of block
dis.skip(blockHeader.blockEnd - dis.getPosition());
}
use of org.rajawali3d.loader.ParsingException in project Rajawali by Rajawali.
the class BlockPrimitiveGeometry method parseBlock.
@SuppressWarnings("unused")
public void parseBlock(AWDLittleEndianDataInputStream dis, BlockHeader blockHeader) throws Exception {
// FIXME The primitive type requires more features than what the Rajawali primitives provide.
// Lookup name, not sure why this is useful.
mLookupName = dis.readVarString();
// Read the primitive type
mPrimitiveType = dis.readUnsignedByte();
if (RajLog.isDebugEnabled()) {
RajLog.d(" Lookup Name: " + mLookupName);
RajLog.d(" Primitive Type: " + mPrimitiveType);
}
// Read primitive properties and construct a new base object determined by the primitive type
switch(PrimitiveType.values()[mPrimitiveType - 1]) {
case CUBE:
{
final float width = dis.readFloat();
final float height = dis.readFloat();
final float depth = dis.readFloat();
final int segmentsW = dis.readUnsignedShort();
final int segmentsH = dis.readUnsignedShort();
final int segmentsD = dis.readUnsignedShort();
final boolean tile6 = dis.readBoolean();
throw new ParsingException("Type of Cube is not yet supported!");
}
case CAPSULE:
throw new ParsingException("Type of Capsule is not yet supported!");
case CONE:
throw new ParsingException("Type of Cone is not yet supported!");
case CYLINDER:
{
final float radiusTop = dis.readFloat();
final float radiusBottom = dis.readFloat();
final float height = dis.readFloat();
final int segmentsW = dis.readUnsignedShort();
final int segmentsH = dis.readUnsignedShort();
final boolean topClosed = dis.readBoolean();
final boolean bottomClosed = dis.readBoolean();
final boolean yUp = dis.readBoolean();
final boolean surfaceClosed = dis.readBoolean();
throw new ParsingException("Type of Cylinder is not yet supported!");
}
case PLANE:
{
final float width = dis.readFloat();
final float height = dis.readFloat();
final int segmentsW = dis.readUnsignedShort();
final int segmentsH = dis.readUnsignedShort();
final boolean yUp = dis.readBoolean();
final boolean doubleSided = dis.readBoolean();
throw new ParsingException("Type of Plane is not yet supported!");
}
case SPHERE:
{
final float radius = dis.readFloat();
final int segmentsW = dis.readUnsignedShort();
final int segmentsH = dis.readUnsignedShort();
final boolean yUp = dis.readBoolean();
throw new ParsingException("Type of Cylinder is not yet supported!");
}
case TORUS:
throw new ParsingException("Type of Torus is not yet supported!");
}
}
Aggregations