use of org.rajawali3d.materials.plugins.VertexAnimationMaterialPlugin in project Rajawali by Rajawali.
the class LoaderMD2 method parse.
public LoaderMD2 parse() throws ParsingException {
super.parse();
BufferedInputStream stream = null;
if (mFile == null) {
InputStream fileIn = mResources.openRawResource(mResourceId);
stream = new BufferedInputStream(fileIn);
} else {
try {
stream = new BufferedInputStream(new FileInputStream(mFile));
} catch (FileNotFoundException e) {
RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
throw new ParsingException(e);
}
}
mObject = new VertexAnimationObject3D();
mObject.setFps(10);
mHeader = new MD2Header();
try {
mHeader.parse(stream);
mFrames = new Stack<IAnimationFrame>();
for (int i = 0; i < mHeader.numFrames; ++i) mFrames.add(new VertexAnimationFrame());
byte[] bytes = new byte[mHeader.offsetEnd - 68];
stream.read(bytes);
getMaterials(stream, bytes);
float[] texCoords = getTexCoords(stream, bytes);
getFrames(stream, bytes);
getTriangles(stream, bytes, texCoords);
mObject.setFrames(mFrames);
IAnimationFrame firstFrame = mFrames.get(0);
Material material = new Material();
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.addPlugin(new VertexAnimationMaterialPlugin());
mObject.getGeometry().copyFromGeometry3D(firstFrame.getGeometry());
mObject.setData(firstFrame.getGeometry().getVertexBufferInfo(), firstFrame.getGeometry().getNormalBufferInfo(), mTextureCoords, null, mIndices, false);
mObject.setMaterial(material);
mObject.setColor(0xffffffff);
if (mTexture != null) {
material.addTexture(new Texture(mCurrentTextureName, mTexture));
material.setColorInfluence(0);
}
stream.close();
} catch (Exception e) {
throw new ParsingException(e);
}
mObject.isContainer(false);
mRootObject = mObject;
return this;
}
use of org.rajawali3d.materials.plugins.VertexAnimationMaterialPlugin in project Rajawali by Rajawali.
the class VertexAnimationObject3D method setMaterial.
@Override
public void setMaterial(Material material) {
super.setMaterial(material);
IMaterialPlugin plugin = material.getPlugin(VertexAnimationMaterialPlugin.class);
if (plugin == null) {
mMaterialPlugin = new VertexAnimationMaterialPlugin();
material.addPlugin(mMaterialPlugin);
} else {
mMaterialPlugin = (VertexAnimationMaterialPlugin) plugin;
}
}
Aggregations