Skip to content

Commit

Permalink
Merge remote-tracking branch 'official/v3.8' into #2279-screenshot-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTingle committed Dec 31, 2024
2 parents 63d97c1 + 36aac25 commit e346cb9
Show file tree
Hide file tree
Showing 31 changed files with 282 additions and 241 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,16 @@ jobs:
- name: Build Engine
shell: bash
run: |
# Build
./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true build
# Normal build plus ZIP distribution and merged javadoc
./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true \
build createZipDistribution mergedJavadoc
if [ "${{ matrix.deploy }}" = "true" ];
then
# We are going to need "zip"
sudo apt-get update
sudo apt-get install -y zip
# Create the zip release and the javadoc
./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true mergedJavadoc createZipDistribution
# We prepare the release for deploy
mkdir -p ./dist/release/
mv build/distributions/*.zip dist/release/
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,25 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e
subprojects.each {project ->
if(!project.hasProperty('mainClassName')){
project.tasks.withType(Jar).each {archiveTask ->
if(archiveTask.archiveClassifier == "sources"){
String classifier = archiveTask.archiveClassifier.get()
String ext = archiveTask.archiveExtension.get()
if (classifier == "sources") {
copy {
from archiveTask.archivePath
into sourceFolder
rename {project.name + '-' + archiveTask.archiveClassifier +'.'+ archiveTask.archiveExtension}
rename {project.name + '-' + classifier + '.' + ext}
}
} else if(archiveTask.archiveClassifier == "javadoc"){
} else if (classifier == "javadoc") {
copy {
from archiveTask.archivePath
into javadocFolder
rename {project.name + '-' + archiveTask.archiveClassifier +'.'+ archiveTask.archiveExtension}
rename {project.name + '-' + classifier + '.' + ext}
}
} else{
copy {
from archiveTask.archivePath
into libFolder
rename {project.name + '.' + archiveTask.archiveExtension}
rename {project.name + '.' + ext}
}
}
}
Expand Down
145 changes: 13 additions & 132 deletions jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
import java.util.logging.Logger;

/**
*
* @deprecated This is an outdated and non-standard method. Please use @{link MikktspaceTangentGenerator}
* instead.
* @author Lex (Aleksey Nikiforov)
*/
@Deprecated
public class TangentBinormalGenerator {

private static final Logger log = Logger.getLogger(TangentBinormalGenerator.class.getName());
Expand Down Expand Up @@ -860,142 +862,21 @@ private static int parity(Vector3f n1, Vector3f n) {
}
}

/**
* @deprecated Use {@link TangentUtils#genTbnLines(com.jme3.scene.Mesh, float) } instead.
*/
@Deprecated
public static Mesh genTbnLines(Mesh mesh, float scale) {
if (mesh.getBuffer(Type.Tangent) == null) {
return genNormalLines(mesh, scale);
} else {
return genTangentLines(mesh, scale);
}
return TangentUtils.genTbnLines(mesh, scale);
}

/**
* @deprecated Use {@link TangentUtils#genNormalLines(com.jme3.scene.Mesh, float) } instead.
*/
@Deprecated
public static Mesh genNormalLines(Mesh mesh, float scale) {
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();

ColorRGBA originColor = ColorRGBA.White;
ColorRGBA normalColor = ColorRGBA.Blue;

Mesh lineMesh = new Mesh();
lineMesh.setMode(Mesh.Mode.Lines);

Vector3f origin = new Vector3f();
Vector3f point = new Vector3f();

FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 2);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 2);

for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
populateFromBuffer(origin, vertexBuffer, i);
populateFromBuffer(point, normalBuffer, i);

int index = i * 2;

setInBuffer(origin, lineVertex, index);
setInBuffer(originColor, lineColor, index);

point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 1);
setInBuffer(normalColor, lineColor, index + 1);
}

lineMesh.setBuffer(Type.Position, 3, lineVertex);
lineMesh.setBuffer(Type.Color, 4, lineColor);

lineMesh.setStatic();
//lineMesh.setInterleaved();
return lineMesh;
return TangentUtils.genNormalLines(mesh, scale);
}

private static Mesh genTangentLines(Mesh mesh, float scale) {
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();
FloatBuffer tangentBuffer = (FloatBuffer) mesh.getBuffer(Type.Tangent).getData();

FloatBuffer binormalBuffer = null;
if (mesh.getBuffer(Type.Binormal) != null) {
binormalBuffer = (FloatBuffer) mesh.getBuffer(Type.Binormal).getData();
}

ColorRGBA originColor = ColorRGBA.White;
ColorRGBA tangentColor = ColorRGBA.Red;
ColorRGBA binormalColor = ColorRGBA.Green;
ColorRGBA normalColor = ColorRGBA.Blue;

Mesh lineMesh = new Mesh();
lineMesh.setMode(Mesh.Mode.Lines);

Vector3f origin = new Vector3f();
Vector3f point = new Vector3f();
Vector3f tangent = new Vector3f();
Vector3f normal = new Vector3f();

IntBuffer lineIndex = BufferUtils.createIntBuffer(vertexBuffer.limit() / 3 * 6);
FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 4);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 4);

boolean hasParity = mesh.getBuffer(Type.Tangent).getNumComponents() == 4;
float tangentW = 1;

for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
populateFromBuffer(origin, vertexBuffer, i);
populateFromBuffer(normal, normalBuffer, i);

if (hasParity) {
tangent.x = tangentBuffer.get(i * 4);
tangent.y = tangentBuffer.get(i * 4 + 1);
tangent.z = tangentBuffer.get(i * 4 + 2);
tangentW = tangentBuffer.get(i * 4 + 3);
} else {
populateFromBuffer(tangent, tangentBuffer, i);
}

int index = i * 4;

int id = i * 6;
lineIndex.put(id, index);
lineIndex.put(id + 1, index + 1);
lineIndex.put(id + 2, index);
lineIndex.put(id + 3, index + 2);
lineIndex.put(id + 4, index);
lineIndex.put(id + 5, index + 3);

setInBuffer(origin, lineVertex, index);
setInBuffer(originColor, lineColor, index);

point.set(tangent);
point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 1);
setInBuffer(tangentColor, lineColor, index + 1);

// wvBinormal = cross(wvNormal, wvTangent) * -inTangent.w
if (binormalBuffer == null) {
normal.cross(tangent, point);
point.multLocal(-tangentW);
point.normalizeLocal();
} else {
populateFromBuffer(point, binormalBuffer, i);
}

point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 2);
setInBuffer(binormalColor, lineColor, index + 2);

point.set(normal);
point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 3);
setInBuffer(normalColor, lineColor, index + 3);
}

lineMesh.setBuffer(Type.Index, 1, lineIndex);
lineMesh.setBuffer(Type.Position, 3, lineVertex);
lineMesh.setBuffer(Type.Color, 4, lineColor);

lineMesh.setStatic();
//lineMesh.setInterleaved();
return lineMesh;
}
}
148 changes: 148 additions & 0 deletions jme3-core/src/main/java/com/jme3/util/TangentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
*/
package com.jme3.util;

import static com.jme3.util.BufferUtils.populateFromBuffer;
import static com.jme3.util.BufferUtils.setInBuffer;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.*;
import com.jme3.scene.VertexBuffer.Type;

/**
* Created by Nehon on 03/10/2016.
Expand Down Expand Up @@ -63,4 +72,143 @@ public static void generateBindPoseTangentsIfNecessary(Mesh mesh){
}
}
}

public static Mesh genTbnLines(Mesh mesh, float scale) {
if (mesh.getBuffer(Type.Tangent) == null) {
return genNormalLines(mesh, scale);
} else {
return genTangentLines(mesh, scale);
}
}

public static Mesh genNormalLines(Mesh mesh, float scale) {
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();

ColorRGBA originColor = ColorRGBA.White;
ColorRGBA normalColor = ColorRGBA.Blue;

Mesh lineMesh = new Mesh();
lineMesh.setMode(Mesh.Mode.Lines);

Vector3f origin = new Vector3f();
Vector3f point = new Vector3f();

FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 2);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 2);

for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
populateFromBuffer(origin, vertexBuffer, i);
populateFromBuffer(point, normalBuffer, i);

int index = i * 2;

setInBuffer(origin, lineVertex, index);
setInBuffer(originColor, lineColor, index);

point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 1);
setInBuffer(normalColor, lineColor, index + 1);
}

lineMesh.setBuffer(Type.Position, 3, lineVertex);
lineMesh.setBuffer(Type.Color, 4, lineColor);

lineMesh.setStatic();
// lineMesh.setInterleaved();
return lineMesh;
}

public static Mesh genTangentLines(Mesh mesh, float scale) {
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();
FloatBuffer tangentBuffer = (FloatBuffer) mesh.getBuffer(Type.Tangent).getData();

FloatBuffer binormalBuffer = null;
if (mesh.getBuffer(Type.Binormal) != null) {
binormalBuffer = (FloatBuffer) mesh.getBuffer(Type.Binormal).getData();
}

ColorRGBA originColor = ColorRGBA.White;
ColorRGBA tangentColor = ColorRGBA.Red;
ColorRGBA binormalColor = ColorRGBA.Green;
ColorRGBA normalColor = ColorRGBA.Blue;

Mesh lineMesh = new Mesh();
lineMesh.setMode(Mesh.Mode.Lines);

Vector3f origin = new Vector3f();
Vector3f point = new Vector3f();
Vector3f tangent = new Vector3f();
Vector3f normal = new Vector3f();

IntBuffer lineIndex = BufferUtils.createIntBuffer(vertexBuffer.limit() / 3 * 6);
FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 4);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 4);

boolean hasParity = mesh.getBuffer(Type.Tangent).getNumComponents() == 4;
float tangentW = 1;

for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
populateFromBuffer(origin, vertexBuffer, i);
populateFromBuffer(normal, normalBuffer, i);

if (hasParity) {
tangent.x = tangentBuffer.get(i * 4);
tangent.y = tangentBuffer.get(i * 4 + 1);
tangent.z = tangentBuffer.get(i * 4 + 2);
tangentW = tangentBuffer.get(i * 4 + 3);
} else {
populateFromBuffer(tangent, tangentBuffer, i);
}

int index = i * 4;

int id = i * 6;
lineIndex.put(id, index);
lineIndex.put(id + 1, index + 1);
lineIndex.put(id + 2, index);
lineIndex.put(id + 3, index + 2);
lineIndex.put(id + 4, index);
lineIndex.put(id + 5, index + 3);

setInBuffer(origin, lineVertex, index);
setInBuffer(originColor, lineColor, index);

point.set(tangent);
point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 1);
setInBuffer(tangentColor, lineColor, index + 1);

// wvBinormal = cross(wvNormal, wvTangent) * -inTangent.w
if (binormalBuffer == null) {
normal.cross(tangent, point);
point.multLocal(-tangentW);
point.normalizeLocal();
} else {
populateFromBuffer(point, binormalBuffer, i);
}

point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 2);
setInBuffer(binormalColor, lineColor, index + 2);

point.set(normal);
point.multLocal(scale);
point.addLocal(origin);
setInBuffer(point, lineVertex, index + 3);
setInBuffer(normalColor, lineColor, index + 3);
}

lineMesh.setBuffer(Type.Index, 1, lineIndex);
lineMesh.setBuffer(Type.Position, 3, lineVertex);
lineMesh.setBuffer(Type.Color, 4, lineColor);

lineMesh.setStatic();
// lineMesh.setInterleaved();
return lineMesh;
}
}
Loading

0 comments on commit e346cb9

Please sign in to comment.