If you think the Android project Schooner-3D listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2012 Dan Mercer/*fromwww.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.supermercerbros.gameengine.parsers;
import java.io.IOException;
import java.util.HashMap;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.util.Log;
import com.supermercerbros.gameengine.armature.Action;
import com.supermercerbros.gameengine.armature.Skeleton;
import com.supermercerbros.gameengine.engine.shaders.Material;
import com.supermercerbros.gameengine.motion.CurveMovement;
import com.supermercerbros.gameengine.objects.BonedObject;
import com.supermercerbros.gameengine.objects.GameObject;
/**
* Creates Movements and GameObjects, including BonedObjects.
*/publicclass GameFactory {
privatestaticfinal String TAG = GameFactory.class.getSimpleName();
privatefinal AssetManager am;
privatefinal Resources res;
private HashMap<String, Action> actions;
private PreObjectData data;
private Skeleton skeleton;
private Material material;
/**
* Creates a new GameFactory for the given Context.
*
* @param context
*/public GameFactory(Context context) {
this.am = context.getAssets();
this.res = context.getResources();
}
protectedvoid setActions(HashMap<String, Action> actions) {
this.actions = actions;
}
/**
* @param fileName
* The asset path of the file to read.
* @return A HashMap of movements and their names
* @throws IOException
* If an error occurs opening or reading the file, i.e. if it
* does not exist or is corrupt.
*/public HashMap<String, CurveMovement> getMovements(String fileName)
throws IOException {
return Sch3D.parseMovements(am.open(fileName));
}
publicvoid setObjectData(String filename) throws IOException {
data = Sch3D.parseMesh(am.open(filename));
}
publicvoid setObjectData(int resId) throws IOException {
data = Sch3D.parseMesh(res.openRawResource(resId));
}
public Skeleton setSkeleton(String filename) throws IOException {
if (filename != null) {
skeleton = Sch3D.parseSkeleton(this, am.open(filename), "@a:"
+ filename);
} else {
skeleton = null;
}
return skeleton;
}
publicvoid setMatrixSource(GameObject obj) {
if (obj != null) {
data.matrix = obj.modelMatrix;
} else {
data.matrix = null;
}
}
publicvoid setMaterial(Material material) {
this.material = material;
}
/**
* Bakes the data in the GameFactory into a GameObject.
*
* @return The GameObject created from the data. This is a
* {@link BonedObject} if a skeleton was provided and the mesh data
* includes bone weights and indices.
*/public GameObject bakeGameObject() {
if (skeleton != null && data.boneIndices != null) {
Log.i(TAG, "Baking BonedObject");
BonedObject object = new BonedObject(data, material, skeleton);
material.makeProgram();
return object;
} else {
Log.i(TAG, "Baking GameObject");
if (skeleton == null) {
Log.i(TAG, "Skeleton == null");
}
if (data.boneIndices == null) {
Log.i(TAG, "data.boneIndices == null");
}
GameObject object = new GameObject(data, material);
material.makeProgram();
return object;
}
}
public HashMap<String, Action> getActions() {
return actions;
}
publicvoid clear() {
data = null;
material = null;
actions = null;
skeleton = null;
}
/**
* Closes the GameFactory
*/publicvoid close() {
clear();
}
}