-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0ca2c2
commit 79af16c
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
apps/src/main/java/com/github/stephengold/vsport/test/AssimpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
Copyright (c) 2023, Stephen Gold | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.github.stephengold.vsport.test; | ||
|
||
import com.github.stephengold.vsport.AssimpUtils; | ||
import com.github.stephengold.vsport.BaseApplication; | ||
import com.github.stephengold.vsport.Camera; | ||
import com.github.stephengold.vsport.Geometry; | ||
import com.github.stephengold.vsport.Mesh; | ||
import com.github.stephengold.vsport.TextureKey; | ||
import com.github.stephengold.vsport.Vertex; | ||
import com.github.stephengold.vsport.input.CameraInputProcessor; | ||
import com.github.stephengold.vsport.input.RotateMode; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.joml.Matrix3f; | ||
import org.joml.Matrix3fc; | ||
import org.joml.Vector3f; | ||
import org.joml.Vector3fc; | ||
|
||
/** | ||
* Test loading a 3-D mesh using Assimp. | ||
* | ||
* @author Stephen Gold sgold@sonic.net | ||
*/ | ||
public class AssimpTest extends BaseApplication { | ||
// ************************************************************************* | ||
// constants | ||
|
||
/** | ||
* rotation matrix to transform Z-up coordinates to Y-up coordinates | ||
*/ | ||
final private static Matrix3fc zupToYup = new Matrix3f( | ||
0f, 1f, 0f, | ||
0f, 0f, 1f, | ||
1f, 0f, 0f); | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Main entry point for the AssimpTest application. | ||
* | ||
* @param arguments the array of command-line arguments (not null) | ||
*/ | ||
public static void main(String[] arguments) { | ||
AssimpTest application = new AssimpTest(); | ||
application.start(); | ||
} | ||
// ************************************************************************* | ||
// BaseApplication methods | ||
|
||
/** | ||
* Callback invoked by V-Sport after the main update loop terminates. | ||
*/ | ||
@Override | ||
public void cleanUp() { | ||
// do nothing | ||
} | ||
|
||
/** | ||
* Initialize the application. | ||
*/ | ||
@Override | ||
public void initialize() { | ||
// Load the viking_room model using Assimp: | ||
String modelName = "/Models/viking_room/viking_room.obj"; | ||
int postFlags = 0x0; | ||
List<Integer> indices = null; | ||
List<Vertex> vertices = new ArrayList<>(); | ||
AssimpUtils.extractTriangles(modelName, postFlags, indices, vertices); | ||
|
||
// The 3-D model is Z-up, but the camera is Y-up, so rotate each vertex: | ||
for (Vertex v : vertices) { | ||
v.rotate(zupToYup); | ||
} | ||
|
||
// De-duplicate the list of vertices as we create the mesh: | ||
Mesh roomMesh = Mesh.newInstance(vertices); | ||
|
||
TextureKey roomKey = new TextureKey( | ||
"classpath:/Models/viking_room/viking_room.png"); | ||
|
||
Geometry room = new Geometry(roomMesh); | ||
room.setProgram("Unshaded/Texture"); | ||
room.setTexture(roomKey); | ||
|
||
// Configure the camera: | ||
Camera camera = getCamera(); | ||
camera.setZClip(0.1f, 10f); | ||
|
||
Vector3fc eye = new Vector3f(2f, 2f, 2f); | ||
Vector3fc target = new Vector3f(0f, 0f, 0f); | ||
camera.reposition(eye, target); | ||
|
||
CameraInputProcessor cip = getCameraInputProcessor(); | ||
cip.setMoveSpeed(2f); | ||
cip.setRotationMode(RotateMode.DragLMB); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters