Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TRS+matrix floating-point precision to double #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,274 changes: 637 additions & 637 deletions jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Node.java

Large diffs are not rendered by default.

398 changes: 199 additions & 199 deletions jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Skin.java

Large diffs are not rendered by default.

1,162 changes: 581 additions & 581 deletions jgltf-impl-v2/src/main/java/de/javagl/jgltf/impl/v2/Node.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ private static GltfModel createGltfModel()

// Add the same mesh to the scene twice
DefaultNodeModel nodeModel0 = new DefaultNodeModel();
nodeModel0.setTranslation(new float[] { -1.0f, 0, 0 });
nodeModel0.setTranslation(new double[] { -1.0, 0, 0 });
nodeModel0.addMeshModel(meshModel);
sceneModel.addNode(nodeModel0);

DefaultNodeModel nodeModel1 = new DefaultNodeModel();
nodeModel1.setTranslation(new float[] { 1.0f, 0, 0 });
nodeModel1.setTranslation(new double[] { 1.0, 0, 0 });
nodeModel1.addMeshModel(meshModel);
sceneModel.addNode(nodeModel1);

Expand Down
48 changes: 24 additions & 24 deletions jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ class BoundingBox
/**
* The minimum x coordinate
*/
private float minX;
private double minX;

/**
* The minimum y coordinate
*/
private float minY;
private double minY;

/**
* The minimum z coordinate
*/
private float minZ;
private double minZ;

/**
* The maximum x coordinate
*/
private float maxX;
private double maxX;

/**
* The maximum y coordinate
*/
private float maxY;
private double maxY;

/**
* The maximum z coordinate
*/
private float maxZ;
private double maxZ;

/**
* Creates a bounding box
*/
BoundingBox()
{
minX = Float.MAX_VALUE;
minY = Float.MAX_VALUE;
minZ = Float.MAX_VALUE;
maxX = -Float.MAX_VALUE;
maxY = -Float.MAX_VALUE;
maxZ = -Float.MAX_VALUE;
minX = Double.MAX_VALUE;
minY = Double.MAX_VALUE;
minZ = Double.MAX_VALUE;
maxX = -Double.MAX_VALUE;
maxY = -Double.MAX_VALUE;
maxZ = -Double.MAX_VALUE;
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ void combine(BoundingBox other)
*
* @return The x-coordinate of the center
*/
float getCenterX()
double getCenterX()
{
return getMinX() + getSizeX() * 0.5f;
}
Expand All @@ -124,7 +124,7 @@ float getCenterX()
*
* @return The y-coordinate of the center
*/
float getCenterY()
double getCenterY()
{
return getMinY() + getSizeY() * 0.5f;
}
Expand All @@ -134,7 +134,7 @@ float getCenterY()
*
* @return The z-coordinate of the center
*/
float getCenterZ()
double getCenterZ()
{
return getMinZ() + getSizeZ() * 0.5f;
}
Expand All @@ -144,7 +144,7 @@ float getCenterZ()
*
* @return The size in x-direction
*/
float getSizeX()
double getSizeX()
{
return getMaxX() - getMinX();
}
Expand All @@ -154,7 +154,7 @@ float getSizeX()
*
* @return The size in y-direction
*/
float getSizeY()
double getSizeY()
{
return getMaxY() - getMinY();
}
Expand All @@ -164,7 +164,7 @@ float getSizeY()
*
* @return The size in z-direction
*/
float getSizeZ()
double getSizeZ()
{
return getMaxZ() - getMinZ();
}
Expand All @@ -174,7 +174,7 @@ float getSizeZ()
*
* @return The minimum x coordinate
*/
float getMinX()
double getMinX()
{
return minX;
}
Expand All @@ -184,7 +184,7 @@ float getMinX()
*
* @return The minimum y coordinate
*/
float getMinY()
double getMinY()
{
return minY;
}
Expand All @@ -194,7 +194,7 @@ float getMinY()
*
* @return The minimum z coordinate
*/
float getMinZ()
double getMinZ()
{
return minZ;
}
Expand All @@ -204,7 +204,7 @@ float getMinZ()
*
* @return The maximum x coordinate
*/
float getMaxX()
double getMaxX()
{
return maxX;
}
Expand All @@ -214,7 +214,7 @@ float getMaxX()
*
* @return The maximum y coordinate
*/
float getMaxY()
double getMaxY()
{
return maxY;
}
Expand All @@ -224,7 +224,7 @@ float getMaxY()
*
* @return The maximum z coordinate
*/
float getMaxZ()
double getMaxZ()
{
return maxZ;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ BoundingBox compute()
List<SceneModel> sceneModels = gltfModel.getSceneModels();
for (SceneModel sceneModel : sceneModels)
{
float rootTransform[] = MathUtils.createIdentity4x4();
double rootTransform[] = MathUtils.createIdentity4x4();
computeSceneBoundingBox(sceneModel, rootTransform, boundingBox);
}
return boundingBox;
Expand All @@ -86,7 +86,7 @@ BoundingBox compute()
* @return The result
*/
private BoundingBox computeSceneBoundingBox(
SceneModel sceneModel, float transform[], BoundingBox boundingBox)
SceneModel sceneModel, double transform[], BoundingBox boundingBox)
{
BoundingBox localResult = boundingBox;
if (localResult == null)
Expand Down Expand Up @@ -115,16 +115,16 @@ private BoundingBox computeSceneBoundingBox(
* @return The result
*/
private BoundingBox computeNodeBoundingBox(
NodeModel nodeModel, float parentTransform[], BoundingBox boundingBox)
NodeModel nodeModel, double parentTransform[], BoundingBox boundingBox)
{
BoundingBox result = boundingBox;
if (result == null)
{
result = new BoundingBox();
}

float[] localTransform = nodeModel.computeLocalTransform(null);
float[] transform = new float[16];
double[] localTransform = nodeModel.computeLocalTransform(null);
double[] transform = new double[16];
MathUtils.mul4x4(parentTransform, localTransform, transform);

List<MeshModel> meshModels = nodeModel.getMeshModels();
Expand Down Expand Up @@ -157,7 +157,7 @@ private BoundingBox computeNodeBoundingBox(
* @return The result
*/
private BoundingBox computeMeshBoundingBox(
MeshModel meshModel, float transform[], BoundingBox boundingBox)
MeshModel meshModel, double transform[], BoundingBox boundingBox)
{
BoundingBox result = boundingBox;
if (result == null)
Expand Down Expand Up @@ -194,7 +194,7 @@ private BoundingBox computeMeshBoundingBox(
* returned.
*/
private BoundingBox computeBoundingBox(
MeshPrimitiveModel meshPrimitiveModel, float transform[])
MeshPrimitiveModel meshPrimitiveModel, double transform[])
{
Map<String, AccessorModel> attributes =
meshPrimitiveModel.getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public class BoundingBoxes
* @param gltfModel The {@link GltfModel}
* @return The bounding box
*/
public static float[] computeBoundingBoxMinMax(GltfModel gltfModel)
public static double[] computeBoundingBoxMinMax(GltfModel gltfModel)
{
Objects.requireNonNull(gltfModel, "The gltfModel may not be null");

BoundingBoxComputer boundingBoxComputer =
new BoundingBoxComputer(gltfModel);
BoundingBox boundingBox = boundingBoxComputer.compute();
float result[] = {

double result[] = {
boundingBox.getMinX(),
boundingBox.getMinY(),
boundingBox.getMinZ(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface CameraModel extends NamedModelElement
* camera will be used.
* @return The result array
*/
float[] computeProjectionMatrix(float result[], Float aspectRatio);
double[] computeProjectionMatrix(double result[], Float aspectRatio);

/**
* Create the supplier of the projection matrix for this camera model.<br>
Expand All @@ -84,7 +84,7 @@ public interface CameraModel extends NamedModelElement
* aspect ratio of the camera will be used.
* @return The supplier
*/
Supplier<float[]> createProjectionMatrixSupplier(
Supplier<double[]> createProjectionMatrixSupplier(
DoubleSupplier aspectRatioSupplier);

}
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,22 @@ private static AnimationListener createTranslationAnimationListener(
{
return (animation, timeS, values) ->
{
float translation[] = nodeModel.getTranslation();
double translation[] = nodeModel.getTranslation();
if (translation == null)
{
translation = values.clone();
translation = new double[values.length];
for (int i = 0; i < values.length; i++)
{
translation[i] = values[i];
}
nodeModel.setTranslation(translation);
}
else
{
System.arraycopy(values, 0, translation, 0, values.length);
for (int i = 0; i < values.length; i++)
{
translation[i] = values[i];
}
}
};
}
Expand All @@ -334,15 +341,22 @@ private static AnimationListener createRotationAnimationListener(
{
return (animation, timeS, values) ->
{
float rotation[] = nodeModel.getRotation();
double rotation[] = nodeModel.getRotation();
if (rotation == null)
{
rotation = values.clone();
rotation = new double[values.length];
for (int i = 0; i < values.length; i++)
{
rotation[i] = values[i];
}
nodeModel.setRotation(rotation);
}
else
{
System.arraycopy(values, 0, rotation, 0, values.length);
for (int i = 0; i < values.length; i++)
{
rotation[i] = values[i];
}
}
};
}
Expand All @@ -360,15 +374,22 @@ private static AnimationListener createScaleAnimationListener(
{
return (animation, timeS, values) ->
{
float scale[] = nodeModel.getScale();
double scale[] = nodeModel.getScale();
if (scale == null)
{
scale = values.clone();
scale = new double[values.length];
for (int i = 0; i < values.length; i++)
{
scale[i] = values[i];
}
nodeModel.setScale(scale);
}
else
{
System.arraycopy(values, 0, scale, 0, values.length);
for (int i = 0; i < values.length; i++)
{
scale[i] = values[i];
}
}
};
}
Expand Down
Loading