Testing model loading.
This commit is contained in:
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar.entities;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
|
||||
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
|
||||
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPhongShader;
|
||||
@@ -30,27 +30,33 @@ import com.badlogic.gdx.graphics.Mesh;
|
||||
import com.badlogic.gdx.graphics.VertexAttribute;
|
||||
import com.badlogic.gdx.graphics.VertexAttributes;
|
||||
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.MeshBuilder;
|
||||
import com.badlogic.gdx.math.Matrix3;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.JsonReader;
|
||||
|
||||
public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
private static final String TAG = "MARKER_TEST_ENTITY_CREATOR";
|
||||
private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName();
|
||||
|
||||
private Mesh patchMesh, sphereMesh, boxMesh;
|
||||
private Mesh sphereMesh;
|
||||
private Mesh boxMesh;
|
||||
private Model bombModel;
|
||||
private CustomShaderBase phongShader;
|
||||
private Mesh bombMesh;
|
||||
|
||||
@Override
|
||||
public void createAllEntities() {
|
||||
MeshBuilder builder;
|
||||
Matrix3 identity = new Matrix3().idt();
|
||||
Entity patch, sphere, box;
|
||||
Entity bomb, sphere, box;
|
||||
G3dModelLoader loader;
|
||||
|
||||
// Create mesh.
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
|
||||
builder = new MeshBuilder();
|
||||
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
|
||||
/*builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
|
||||
builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
Vector3 v00 = new Vector3(-0.5f, -0.5f, 0.0f);
|
||||
Vector3 v10 = new Vector3(-0.5f, 0.5f, 0.0f);
|
||||
@@ -58,7 +64,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
Vector3 v01 = new Vector3( 0.5f, -0.5f, 0.0f);
|
||||
Vector3 n = new Vector3(0.0f, 1.0f, 0.0f);
|
||||
builder.patch(v00, v10, v11, v01, n, 10, 10);
|
||||
}patchMesh = builder.end();
|
||||
}patchMesh = builder.end();*/
|
||||
|
||||
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
|
||||
builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
@@ -70,6 +76,12 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
builder.box(0.5f, 0.5f, 6.0f);
|
||||
}boxMesh = builder.end();
|
||||
|
||||
loader = new G3dModelLoader(new JsonReader());
|
||||
bombModel = loader.loadModel(Gdx.files.internal("models/Bomb_test_1.g3dj"));
|
||||
|
||||
bombMesh = bombModel.meshes.get(0);
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): " + bombMesh.getVertexAttributes().toString());
|
||||
|
||||
// Load the phong shader.
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
|
||||
try{
|
||||
@@ -81,27 +93,28 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
|
||||
// Create the entities.
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
|
||||
patch = world.createEntity();
|
||||
patch.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||
patch.addComponent(new MeshComponent(patchMesh));
|
||||
patch.addComponent(new ShaderComponent(phongShader));
|
||||
patch.addComponent(new MarkerCodeComponent(213));
|
||||
bomb = world.createEntity();
|
||||
bomb.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||
bomb.addComponent(new MeshComponent(bombMesh));
|
||||
bomb.addComponent(new ShaderComponent(phongShader));
|
||||
bomb.addComponent(new MarkerCodeComponent(213));
|
||||
|
||||
sphere = world.createEntity();
|
||||
sphere.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||
sphere.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||
sphere.addComponent(new MeshComponent(sphereMesh));
|
||||
sphere.addComponent(new ShaderComponent(phongShader));
|
||||
sphere.addComponent(new MarkerCodeComponent(10));
|
||||
|
||||
box = world.createEntity();
|
||||
box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||
box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||
box.addComponent(new MeshComponent(boxMesh));
|
||||
box.addComponent(new ShaderComponent(phongShader));
|
||||
|
||||
// Add the entities to the world.
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
|
||||
//sphere.addToWorld();
|
||||
bomb.addToWorld();
|
||||
sphere.addToWorld();
|
||||
patch.addToWorld();
|
||||
box.addToWorld();
|
||||
}
|
||||
|
||||
@@ -110,13 +123,13 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
if(phongShader != null && phongShader.getShaderProgram() != null)
|
||||
phongShader.getShaderProgram().dispose();
|
||||
|
||||
if(patchMesh != null)
|
||||
patchMesh.dispose();
|
||||
|
||||
if(sphereMesh != null)
|
||||
sphereMesh.dispose();
|
||||
|
||||
if(boxMesh != null)
|
||||
boxMesh.dispose();
|
||||
|
||||
if(bombModel != null)
|
||||
bombModel.dispose();
|
||||
}
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ public class InGameState extends BaseState{
|
||||
private static final float FAR_PLUS_NEAR = FAR + NEAR;
|
||||
private static final float FAR_LESS_NEAR = FAR - NEAR;
|
||||
private static final Vector3 LIGHT_POSITION = new Vector3(2.0f, 2.0f, 4.0f);
|
||||
private static final Color AMBIENT_COLOR = new Color(0.0f, 0.1f, 0.2f, 1.0f);
|
||||
private static final Color AMBIENT_COLOR = new Color(0.0f, 0.1f, 0.3f, 1.0f);
|
||||
private static final Color DIFFUSE_COLOR = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
private static final Color SPECULAR_COLOR = new Color(1.0f, 0.8f, 0.0f, 1.0f);
|
||||
private static final float SHINYNESS = 50.0f;
|
||||
@@ -240,11 +240,6 @@ public class InGameState extends BaseState{
|
||||
perspectiveCamera.update();
|
||||
}
|
||||
|
||||
// Apply the undistortion method if the camera has been calibrated already.
|
||||
/*if(core.cvProc.isCameraCalibrated()){
|
||||
frame = core.cvProc.undistortFrame(frame);
|
||||
}*/
|
||||
|
||||
// Attempt to find the markers in the current video frame.
|
||||
data = core.cvProc.findMarkersInFrame(frame);
|
||||
|
||||
@@ -273,7 +268,6 @@ public class InGameState extends BaseState{
|
||||
// Set the 3D frame buffer for rendering.
|
||||
frameBuffer.begin();{
|
||||
// Set OpenGL state.
|
||||
Gdx.gl.glDisable(GL20.GL_CULL_FACE);
|
||||
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
|
||||
Gdx.gl.glClearColor(0, 0, 0, 0);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package ve.ucv.ciens.ccg.nxtar.systems;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
@@ -18,10 +18,10 @@ import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
|
||||
public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||
@Mapper ComponentMapper<MeshComponent> meshMapper;
|
||||
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||
@Mapper ComponentMapper<MeshComponent> meshMapper;
|
||||
|
||||
private static final String TAG = "MARKER_RENDERING_SYSTEM";
|
||||
private static final String CLASS_NAME = MarkerRenderingSystem.class.getSimpleName();
|
||||
@@ -53,9 +53,9 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, ShaderComponent.class, MeshComponent.class));
|
||||
|
||||
markers = null;
|
||||
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
||||
rotationMatrix = new Matrix4().idt();
|
||||
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
||||
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
||||
rotationMatrix = new Matrix4().idt();
|
||||
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
||||
combinedTransformationMatrix = new Matrix4();
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||
|
||||
@Override
|
||||
protected void process(Entity e) {
|
||||
MarkerCodeComponent marker;
|
||||
GeometryComponent geometry;
|
||||
ShaderComponent shaderComp;
|
||||
MeshComponent meshComp;
|
||||
MarkerCodeComponent marker;
|
||||
GeometryComponent geometry;
|
||||
ShaderComponent shaderComp;
|
||||
MeshComponent meshComp;
|
||||
|
||||
if(markers == null)
|
||||
return;
|
||||
@@ -82,29 +82,30 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
|
||||
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
|
||||
if(markers.markerCodes[i] != 1){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Checking marker code: " + Integer.toString(markers.markerCodes[i]));
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): This entity's code is: " + Integer.toString(marker.code));
|
||||
if(markers.markerCodes[i] == marker.code){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
||||
// Set the geometric transformations.
|
||||
translationMatrix.setToTranslation(geometry.position);
|
||||
|
||||
rotationMatrix.val[0] = geometry.rotation.val[0];
|
||||
rotationMatrix.val[1] = geometry.rotation.val[1];
|
||||
rotationMatrix.val[2] = geometry.rotation.val[2];
|
||||
rotationMatrix.val[3] = 0;
|
||||
rotationMatrix.val[4] = geometry.rotation.val[3];
|
||||
rotationMatrix.val[5] = geometry.rotation.val[4];
|
||||
rotationMatrix.val[6] = geometry.rotation.val[5];
|
||||
rotationMatrix.val[7] = 0;
|
||||
rotationMatrix.val[8] = geometry.rotation.val[6];
|
||||
rotationMatrix.val[9] = geometry.rotation.val[7];
|
||||
rotationMatrix.val[10] = geometry.rotation.val[8];
|
||||
rotationMatrix.val[11] = 0;
|
||||
rotationMatrix.val[12] = 0;
|
||||
rotationMatrix.val[13] = 0;
|
||||
rotationMatrix.val[14] = 0;
|
||||
rotationMatrix.val[15] = 1;
|
||||
rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
|
||||
rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
|
||||
rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
|
||||
rotationMatrix.val[Matrix4.M30] = 0;
|
||||
|
||||
rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
|
||||
rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
|
||||
rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
|
||||
rotationMatrix.val[Matrix4.M31] = 0;
|
||||
|
||||
rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
|
||||
rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
|
||||
rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
|
||||
rotationMatrix.val[Matrix4.M32] = 0;
|
||||
|
||||
rotationMatrix.val[Matrix4.M03] = 0;
|
||||
rotationMatrix.val[Matrix4.M13] = 0;
|
||||
rotationMatrix.val[Matrix4.M23] = 0;
|
||||
rotationMatrix.val[Matrix4.M33] = 1;
|
||||
|
||||
scalingMatrix.setToScaling(geometry.scaling);
|
||||
combinedTransformationMatrix.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
||||
@@ -115,11 +116,15 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||
shaderComp.shader.setUniforms();
|
||||
meshComp.model.render(shaderComp.shader.getShaderProgram(), GL20.GL_TRIANGLES);
|
||||
}shaderComp.shader.getShaderProgram().end();
|
||||
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
markers = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user