本文整理了Java中org.lwjglb.engine.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:org.lwjglb.engine.Utils
类名称:Utils
暂无
代码示例来源:origin: lwjglgamedev/lwjglbook
public static MD5Model parse(String meshModelFile) throws Exception {
List<String> lines = Utils.readAllLines(meshModelFile);
代码示例来源:origin: lwjglgamedev/lwjglbook
public static MD5Frame parse(String blockId, List<String> blockBody) throws Exception {
MD5Frame result = new MD5Frame();
String[] tokens = blockId.trim().split("\\s+");
if (tokens != null && tokens.length >= 2) {
result.setId(Integer.parseInt(tokens[1]));
} else {
throw new Exception("Wrong frame definition: " + blockId);
}
List<Float> data = new ArrayList<>();
for (String line : blockBody) {
List<Float> lineData = parseLine(line);
if (lineData != null) {
data.addAll(lineData);
}
}
float[] dataArr = Utils.listToArray(data);
result.setFrameData(dataArr);
return result;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials, List<Bone> boneList) {
List<Float> vertices = new ArrayList<>();
List<Float> textures = new ArrayList<>();
List<Float> normals = new ArrayList<>();
List<Integer> indices = new ArrayList<>();
List<Integer> boneIds = new ArrayList<>();
List<Float> weights = new ArrayList<>();
processVertices(aiMesh, vertices);
processNormals(aiMesh, normals);
processTextCoords(aiMesh, textures);
processIndices(aiMesh, indices);
processBones(aiMesh, boneList, boneIds, weights);
Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures),
Utils.listToArray(normals), Utils.listIntToArray(indices),
Utils.listIntToArray(boneIds), Utils.listToArray(weights));
Material material;
int materialIdx = aiMesh.mMaterialIndex();
if (materialIdx >= 0 && materialIdx < materials.size()) {
material = materials.get(materialIdx);
} else {
material = new Material();
}
mesh.setMaterial(material);
return mesh;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void setupDepthShader() throws Exception {
depthShaderProgram = new ShaderProgram();
depthShaderProgram.createVertexShader(Utils.loadResource("/shaders/depth_vertex.vs"));
depthShaderProgram.createFragmentShader(Utils.loadResource("/shaders/depth_fragment.fs"));
depthShaderProgram.link();
depthShaderProgram.createUniform("orthoProjectionMatrix");
depthShaderProgram.createUniform("modelLightViewMatrix");
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static void handleTexture(Mesh mesh, MD5Mesh md5Mesh, Vector4f defaultColour) throws Exception {
String texturePath = md5Mesh.getTexture();
if (texturePath != null && texturePath.length() > 0) {
Texture texture = new Texture(texturePath);
Material material = new Material(texture);
// Handle normal Maps;
int pos = texturePath.lastIndexOf(".");
if (pos > 0) {
String basePath = texturePath.substring(0, pos);
String extension = texturePath.substring(pos, texturePath.length());
String normalMapFileName = basePath + "_local" + extension;
if (Utils.existsResourceFile(normalMapFileName)) {
Texture normalMap = new Texture(normalMapFileName);
material.setNormalMap(normalMap);
}
}
mesh.setMaterial(material);
} else {
mesh.setMaterial(new Material(defaultColour, 1));
}
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
List<Vector3f> normList, List<Face> facesList) {
List<Integer> indices = new ArrayList();
// Create position array in the order it has been declared
float[] posArr = new float[posList.size() * 3];
int i = 0;
for (Vector3f pos : posList) {
posArr[i * 3] = pos.x;
posArr[i * 3 + 1] = pos.y;
posArr[i * 3 + 2] = pos.z;
i++;
}
float[] textCoordArr = new float[posList.size() * 2];
float[] normArr = new float[posList.size() * 3];
for (Face face : facesList) {
IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
for (IdxGroup indValue : faceVertexIndices) {
processFaceVertex(indValue, textCoordList, normList,
indices, textCoordArr, normArr);
}
}
int[] indicesArr = Utils.listIntToArray(indices);
Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
return mesh;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public Texture(String fileName) throws Exception {
this(Utils.ioResourceToByteBuffer(fileName, 1024));
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
ByteBuffer buffer;
Path path = Paths.get(resource);
if (Files.isReadable(path)) {
try (SeekableByteChannel fc = Files.newByteChannel(path)) {
buffer = BufferUtils.createByteBuffer((int) fc.size() + 1);
while (fc.read(buffer) != -1) ;
}
} else {
try (
InputStream source = Utils.class.getResourceAsStream(resource);
ReadableByteChannel rbc = Channels.newChannel(source)) {
buffer = createByteBuffer(bufferSize);
while (true) {
int bytes = rbc.read(buffer);
if (bytes == -1) {
break;
}
if (buffer.remaining() == 0) {
buffer = resizeBuffer(buffer, buffer.capacity() * 2);
}
}
}
}
buffer.flip();
return buffer;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void setupHudShader() throws Exception {
hudShaderProgram = new ShaderProgram();
hudShaderProgram.createVertexShader(Utils.loadResource("/shaders/hud_vertex.vs"));
hudShaderProgram.createFragmentShader(Utils.loadResource("/shaders/hud_fragment.fs"));
hudShaderProgram.link();
// Create uniforms for Ortographic-model projection matrix and base colour
hudShaderProgram.createUniform("projModelMatrix");
hudShaderProgram.createUniform("colour");
hudShaderProgram.createUniform("hasTexture");
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static void handleTexture(Mesh mesh, MD5Mesh md5Mesh, Vector4f defaultColour) throws Exception {
String texturePath = md5Mesh.getTexture();
if (texturePath != null && texturePath.length() > 0) {
Texture texture = new Texture(texturePath);
Material material = new Material(texture);
// Handle normal Maps;
int pos = texturePath.lastIndexOf(".");
if (pos > 0) {
String basePath = texturePath.substring(0, pos);
String extension = texturePath.substring(pos, texturePath.length());
String normalMapFileName = basePath + "_local" + extension;
if (Utils.existsResourceFile(normalMapFileName)) {
Texture normalMap = new Texture(normalMapFileName);
material.setNormalMap(normalMap);
}
}
mesh.setMaterial(material);
} else {
mesh.setMaterial(new Material(defaultColour, 1));
}
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
List<Vector3f> normList, List<Face> facesList) {
List<Integer> indices = new ArrayList();
// Create position array in the order it has been declared
float[] posArr = new float[posList.size() * 3];
int i = 0;
for (Vector3f pos : posList) {
posArr[i * 3] = pos.x;
posArr[i * 3 + 1] = pos.y;
posArr[i * 3 + 2] = pos.z;
i++;
}
float[] textCoordArr = new float[posList.size() * 2];
float[] normArr = new float[posList.size() * 3];
for (Face face : facesList) {
IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
for (IdxGroup indValue : faceVertexIndices) {
processFaceVertex(indValue, textCoordList, normList,
indices, textCoordArr, normArr);
}
}
int[] indicesArr = Utils.listIntToArray(indices);
Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
return mesh;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public Texture(String fileName) throws Exception {
this(Utils.ioResourceToByteBuffer(fileName, 1024));
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
ByteBuffer buffer;
Path path = Paths.get(resource);
if (Files.isReadable(path)) {
try (SeekableByteChannel fc = Files.newByteChannel(path)) {
buffer = BufferUtils.createByteBuffer((int) fc.size() + 1);
while (fc.read(buffer) != -1) ;
}
} else {
try (
InputStream source = Utils.class.getResourceAsStream(resource);
ReadableByteChannel rbc = Channels.newChannel(source)) {
buffer = createByteBuffer(bufferSize);
while (true) {
int bytes = rbc.read(buffer);
if (bytes == -1) {
break;
}
if (buffer.remaining() == 0) {
buffer = resizeBuffer(buffer, buffer.capacity() * 2);
}
}
}
}
buffer.flip();
return buffer;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private void setupDepthShader() throws Exception {
depthShaderProgram = new ShaderProgram();
depthShaderProgram.createVertexShader(Utils.loadResource("/shaders/depth_vertex.vs"));
depthShaderProgram.createFragmentShader(Utils.loadResource("/shaders/depth_fragment.fs"));
depthShaderProgram.link();
depthShaderProgram.createUniform("orthoProjectionMatrix");
depthShaderProgram.createUniform("modelLightViewMatrix");
// Create uniform for joint matrices
depthShaderProgram.createUniform("jointsMatrix");
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public static MD5Model parse(String meshModelFile) throws Exception {
List<String> lines = Utils.readAllLines(meshModelFile);
代码示例来源:origin: lwjglgamedev/lwjglbook
public static MD5Frame parse(String blockId, List<String> blockBody) throws Exception {
MD5Frame result = new MD5Frame();
String[] tokens = blockId.trim().split("\\s+");
if (tokens != null && tokens.length >= 2) {
result.setId(Integer.parseInt(tokens[1]));
} else {
throw new Exception("Wrong frame definition: " + blockId);
}
List<Float> data = new ArrayList<>();
for (String line : blockBody) {
List<Float> lineData = parseLine(line);
if (lineData != null) {
data.addAll(lineData);
}
}
float[] dataArr = Utils.listToArray(data);
result.setFrameData(dataArr);
return result;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials, List<Bone> boneList) {
List<Float> vertices = new ArrayList<>();
List<Float> textures = new ArrayList<>();
List<Float> normals = new ArrayList<>();
List<Integer> indices = new ArrayList<>();
List<Integer> boneIds = new ArrayList<>();
List<Float> weights = new ArrayList<>();
processVertices(aiMesh, vertices);
processNormals(aiMesh, normals);
processTextCoords(aiMesh, textures);
processIndices(aiMesh, indices);
processBones(aiMesh, boneList, boneIds, weights);
Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures),
Utils.listToArray(normals), Utils.listIntToArray(indices),
Utils.listIntToArray(boneIds), Utils.listToArray(weights));
Material material;
int materialIdx = aiMesh.mMaterialIndex();
if (materialIdx >= 0 && materialIdx < materials.size()) {
material = materials.get(materialIdx);
} else {
material = new Material();
}
mesh.setMaterial(material);
return mesh;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static void handleTexture(Mesh mesh, MD5Mesh md5Mesh, Vector4f defaultColour) throws Exception {
String texturePath = md5Mesh.getTexture();
if (texturePath != null && texturePath.length() > 0) {
Texture texture = new Texture(texturePath);
Material material = new Material(texture);
// Handle normal Maps;
int pos = texturePath.lastIndexOf(".");
if (pos > 0) {
String basePath = texturePath.substring(0, pos);
String extension = texturePath.substring(pos, texturePath.length());
String normalMapFileName = basePath + "_local" + extension;
if (Utils.existsResourceFile(normalMapFileName)) {
Texture normalMap = new Texture(normalMapFileName);
material.setNormalMap(normalMap);
}
}
mesh.setMaterial(material);
} else {
mesh.setMaterial(new Material(defaultColour, 1));
}
}
}
代码示例来源:origin: lwjglgamedev/lwjglbook
private static Mesh reorderLists(List<Vector3f> posList, List<Vector2f> textCoordList,
List<Vector3f> normList, List<Face> facesList) {
List<Integer> indices = new ArrayList();
// Create position array in the order it has been declared
float[] posArr = new float[posList.size() * 3];
int i = 0;
for (Vector3f pos : posList) {
posArr[i * 3] = pos.x;
posArr[i * 3 + 1] = pos.y;
posArr[i * 3 + 2] = pos.z;
i++;
}
float[] textCoordArr = new float[posList.size() * 2];
float[] normArr = new float[posList.size() * 3];
for (Face face : facesList) {
IdxGroup[] faceVertexIndices = face.getFaceVertexIndices();
for (IdxGroup indValue : faceVertexIndices) {
processFaceVertex(indValue, textCoordList, normList,
indices, textCoordArr, normArr);
}
}
int[] indicesArr = Utils.listIntToArray(indices);
Mesh mesh = new Mesh(posArr, textCoordArr, normArr, indicesArr);
return mesh;
}
代码示例来源:origin: lwjglgamedev/lwjglbook
public Texture(String fileName) throws Exception {
this(Utils.ioResourceToByteBuffer(fileName, 1024));
}
内容来源于网络,如有侵权,请联系作者删除!