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 1 commit
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
Next Next commit
Change TRS matrix floating-point precision to double
  • Loading branch information
tf2mandeokyi committed Jan 17, 2025
commit 630412d0c181f2e00783091152368cd17d5e2564
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
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 @@ -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