From 630412d0c181f2e00783091152368cd17d5e2564 Mon Sep 17 00:00:00 2001 From: m4ndeokyi Date: Fri, 17 Jan 2025 11:50:50 +0300 Subject: [PATCH 1/3] Change TRS matrix floating-point precision to double --- .../java/de/javagl/jgltf/impl/v1/Node.java | 1274 ++++++++--------- .../java/de/javagl/jgltf/impl/v1/Skin.java | 398 ++--- .../java/de/javagl/jgltf/impl/v2/Node.java | 1162 +++++++-------- .../model/creation/DuplicateMeshesTest.java | 4 +- .../jgltf/model/BoundingBoxComputer.java | 14 +- .../de/javagl/jgltf/model/CameraModel.java | 4 +- .../de/javagl/jgltf/model/GltfAnimations.java | 39 +- .../java/de/javagl/jgltf/model/MathUtils.java | 276 ++-- .../java/de/javagl/jgltf/model/MeshModel.java | 6 +- .../java/de/javagl/jgltf/model/NodeModel.java | 24 +- .../java/de/javagl/jgltf/model/Optionals.java | 16 + .../java/de/javagl/jgltf/model/SkinModel.java | 14 +- .../java/de/javagl/jgltf/model/Suppliers.java | 10 +- .../java/de/javagl/jgltf/model/Utils.java | 18 + .../de/javagl/jgltf/model/impl/Cameras.java | 6 +- .../jgltf/model/impl/DefaultCameraModel.java | 6 +- .../jgltf/model/impl/DefaultNodeModel.java | 72 +- .../jgltf/model/impl/DefaultSkinModel.java | 12 +- .../model/structure/GltfModelStructures.java | 8 +- .../jgltf/model/v1/GltfModelCreatorV1.java | 12 +- .../javagl/jgltf/model/v2/GltfCreatorV2.java | 28 +- .../jgltf/model/v2/GltfModelCreatorV2.java | 39 +- .../jgltf/viewer/AbstractGltfViewer.java | 6 +- .../javagl/jgltf/viewer/CesiumRtcUtils.java | 16 +- .../jgltf/viewer/DefaultRenderedCamera.java | 12 +- .../viewer/DefaultRenderedGltfModel.java | 2 +- .../de/javagl/jgltf/viewer/MatrixOps.java | 36 +- .../javagl/jgltf/viewer/RenderedCamera.java | 10 +- .../jgltf/viewer/UniformGetterFactory.java | 64 +- .../jgltf/viewer/ViewConfiguration.java | 22 +- 30 files changed, 1854 insertions(+), 1756 deletions(-) diff --git a/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Node.java b/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Node.java index 04c395b1..401ea7ef 100644 --- a/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Node.java +++ b/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Node.java @@ -5,640 +5,640 @@ * with JsonModelGen (https://github.com/javagl/JsonModelGen) * Copyright (c) 2016 Marco Hutter - http://www.javagl.de */ - -package de.javagl.jgltf.impl.v1; - -import java.util.ArrayList; -import java.util.List; - - -/** - * A node in the node hierarchy. A node can have either the `camera`, - * `meshes`, or `skeletons`/`skin`/`meshes` properties defined. In the - * later case, all `primitives` in the referenced `meshes` contain - * `JOINT` and `WEIGHT` attributes and the referenced - * `material`/`technique` from each `primitive` has parameters with - * `JOINT` and `WEIGHT` semantics. A node can have either a `matrix` or - * any combination of `translation`/`rotation`/`scale` (TRS) properties. - * TRS properties are converted to matrices and postmultiplied in the `T - * * R * S` order to compose the transformation matrix; first the scale - * is applied to the vertices, then the rotation, and then the - * translation. If none are provided, the transform is the identity. When - * a node is targeted for animation (referenced by an - * animation.channel.target), only TRS properties may be present; - * `matrix` will not be present. - * - * Auto-generated for node.schema.json - * - */ -public class Node - extends GlTFChildOfRootProperty -{ - - /** - * The ID of the camera referenced by this node. (optional) - * - */ - private String camera; - /** - * The IDs of this node's children. (optional)
- * Default: []
- * Array elements:
- *   The elements of this array (optional) - * - */ - private List children; - /** - * The ID of skeleton nodes. (optional)
- * Array elements:
- *   The elements of this array (optional) - * - */ - private List skeletons; - /** - * The ID of the skin referenced by this node. (optional) - * - */ - private String skin; - /** - * Name used when this node is a joint in a skin. (optional) - * - */ - private String jointName; - /** - * A floating-point 4x4 transformation matrix stored in column-major - * order. (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] matrix; - /** - * The IDs of the meshes in this node. (optional)
- * Array elements:
- *   The elements of this array (optional) - * - */ - private List meshes; - /** - * The node's unit quaternion rotation in the order (x, y, z, w), where w - * is the scalar. (optional)
- * Default: [0.0,0.0,0.0,1.0]
- * Number of items: 4
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] rotation; - /** - * The node's non-uniform scale. (optional)
- * Default: [1.0,1.0,1.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] scale; - /** - * The node's translation. (optional)
- * Default: [0.0,0.0,0.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] translation; - - /** - * The ID of the camera referenced by this node. (optional) - * - * @param camera The camera to set - * - */ - public void setCamera(String camera) { - if (camera == null) { - this.camera = camera; - return ; - } - this.camera = camera; - } - - /** - * The ID of the camera referenced by this node. (optional) - * - * @return The camera - * - */ - public String getCamera() { - return this.camera; - } - - /** - * The IDs of this node's children. (optional)
- * Default: []
- * Array elements:
- *   The elements of this array (optional) - * - * @param children The children to set - * - */ - public void setChildren(List children) { - if (children == null) { - this.children = children; - return ; - } - this.children = children; - } - - /** - * The IDs of this node's children. (optional)
- * Default: []
- * Array elements:
- *   The elements of this array (optional) - * - * @return The children - * - */ - public List getChildren() { - return this.children; - } - - /** - * Add the given children. The children of this instance will be replaced - * with a list that contains all previous elements, and additionally the - * new element. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void addChildren(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.children; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.add(element); - this.children = newList; - } - - /** - * Remove the given children. The children of this instance will be - * replaced with a list that contains all previous elements, except for - * the removed one.
- * If this new list would be empty, then it will be set to - * null. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void removeChildren(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.children; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.remove(element); - if (newList.isEmpty()) { - this.children = null; - } else { - this.children = newList; - } - } - - /** - * Returns the default value of the children
- * @see #getChildren - * - * @return The default children - * - */ - public List defaultChildren() { - return new ArrayList(); - } - - /** - * The ID of skeleton nodes. (optional)
- * Array elements:
- *   The elements of this array (optional) - * - * @param skeletons The skeletons to set - * - */ - public void setSkeletons(List skeletons) { - if (skeletons == null) { - this.skeletons = skeletons; - return ; - } - this.skeletons = skeletons; - } - - /** - * The ID of skeleton nodes. (optional)
- * Array elements:
- *   The elements of this array (optional) - * - * @return The skeletons - * - */ - public List getSkeletons() { - return this.skeletons; - } - - /** - * Add the given skeletons. The skeletons of this instance will be - * replaced with a list that contains all previous elements, and - * additionally the new element. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void addSkeletons(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.skeletons; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.add(element); - this.skeletons = newList; - } - - /** - * Remove the given skeletons. The skeletons of this instance will be - * replaced with a list that contains all previous elements, except for - * the removed one.
- * If this new list would be empty, then it will be set to - * null. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void removeSkeletons(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.skeletons; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.remove(element); - if (newList.isEmpty()) { - this.skeletons = null; - } else { - this.skeletons = newList; - } - } - - /** - * The ID of the skin referenced by this node. (optional) - * - * @param skin The skin to set - * - */ - public void setSkin(String skin) { - if (skin == null) { - this.skin = skin; - return ; - } - this.skin = skin; - } - - /** - * The ID of the skin referenced by this node. (optional) - * - * @return The skin - * - */ - public String getSkin() { - return this.skin; - } - - /** - * Name used when this node is a joint in a skin. (optional) - * - * @param jointName The jointName to set - * - */ - public void setJointName(String jointName) { - if (jointName == null) { - this.jointName = jointName; - return ; - } - this.jointName = jointName; - } - - /** - * Name used when this node is a joint in a skin. (optional) - * - * @return The jointName - * - */ - public String getJointName() { - return this.jointName; - } - - /** - * A floating-point 4x4 transformation matrix stored in column-major - * order. (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - * @param matrix The matrix to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setMatrix(float[] matrix) { - if (matrix == null) { - this.matrix = matrix; - return ; - } - if (matrix.length< 16) { - throw new IllegalArgumentException("Number of matrix elements is < 16"); - } - if (matrix.length > 16) { - throw new IllegalArgumentException("Number of matrix elements is > 16"); - } - this.matrix = matrix; - } - - /** - * A floating-point 4x4 transformation matrix stored in column-major - * order. (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - * @return The matrix - * - */ - public float[] getMatrix() { - return this.matrix; - } - - /** - * Returns the default value of the matrix
- * @see #getMatrix - * - * @return The default matrix - * - */ - public float[] defaultMatrix() { - return new float[] { 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F }; - } - - /** - * The IDs of the meshes in this node. (optional)
- * Array elements:
- *   The elements of this array (optional) - * - * @param meshes The meshes to set - * - */ - public void setMeshes(List meshes) { - if (meshes == null) { - this.meshes = meshes; - return ; - } - this.meshes = meshes; - } - - /** - * The IDs of the meshes in this node. (optional)
- * Array elements:
- *   The elements of this array (optional) - * - * @return The meshes - * - */ - public List getMeshes() { - return this.meshes; - } - - /** - * Add the given meshes. The meshes of this instance will be replaced - * with a list that contains all previous elements, and additionally the - * new element. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void addMeshes(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.meshes; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.add(element); - this.meshes = newList; - } - - /** - * Remove the given meshes. The meshes of this instance will be replaced - * with a list that contains all previous elements, except for the - * removed one.
- * If this new list would be empty, then it will be set to - * null. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void removeMeshes(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.meshes; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.remove(element); - if (newList.isEmpty()) { - this.meshes = null; - } else { - this.meshes = newList; - } - } - - /** - * The node's unit quaternion rotation in the order (x, y, z, w), where w - * is the scalar. (optional)
- * Default: [0.0,0.0,0.0,1.0]
- * Number of items: 4
- * Array elements:
- *   The elements of this array (optional) - * - * @param rotation The rotation to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setRotation(float[] rotation) { - if (rotation == null) { - this.rotation = rotation; - return ; - } - if (rotation.length< 4) { - throw new IllegalArgumentException("Number of rotation elements is < 4"); - } - if (rotation.length > 4) { - throw new IllegalArgumentException("Number of rotation elements is > 4"); - } - this.rotation = rotation; - } - - /** - * The node's unit quaternion rotation in the order (x, y, z, w), where w - * is the scalar. (optional)
- * Default: [0.0,0.0,0.0,1.0]
- * Number of items: 4
- * Array elements:
- *   The elements of this array (optional) - * - * @return The rotation - * - */ - public float[] getRotation() { - return this.rotation; - } - - /** - * Returns the default value of the rotation
- * @see #getRotation - * - * @return The default rotation - * - */ - public float[] defaultRotation() { - return new float[] { 0.0F, 0.0F, 0.0F, 1.0F }; - } - - /** - * The node's non-uniform scale. (optional)
- * Default: [1.0,1.0,1.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @param scale The scale to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setScale(float[] scale) { - if (scale == null) { - this.scale = scale; - return ; - } - if (scale.length< 3) { - throw new IllegalArgumentException("Number of scale elements is < 3"); - } - if (scale.length > 3) { - throw new IllegalArgumentException("Number of scale elements is > 3"); - } - this.scale = scale; - } - - /** - * The node's non-uniform scale. (optional)
- * Default: [1.0,1.0,1.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @return The scale - * - */ - public float[] getScale() { - return this.scale; - } - - /** - * Returns the default value of the scale
- * @see #getScale - * - * @return The default scale - * - */ - public float[] defaultScale() { - return new float[] { 1.0F, 1.0F, 1.0F }; - } - - /** - * The node's translation. (optional)
- * Default: [0.0,0.0,0.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @param translation The translation to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setTranslation(float[] translation) { - if (translation == null) { - this.translation = translation; - return ; - } - if (translation.length< 3) { - throw new IllegalArgumentException("Number of translation elements is < 3"); - } - if (translation.length > 3) { - throw new IllegalArgumentException("Number of translation elements is > 3"); - } - this.translation = translation; - } - - /** - * The node's translation. (optional)
- * Default: [0.0,0.0,0.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @return The translation - * - */ - public float[] getTranslation() { - return this.translation; - } - - /** - * Returns the default value of the translation
- * @see #getTranslation - * - * @return The default translation - * - */ - public float[] defaultTranslation() { - return new float[] { 0.0F, 0.0F, 0.0F }; - } - -} + +package de.javagl.jgltf.impl.v1; + +import java.util.ArrayList; +import java.util.List; + + +/** + * A node in the node hierarchy. A node can have either the `camera`, + * `meshes`, or `skeletons`/`skin`/`meshes` properties defined. In the + * later case, all `primitives` in the referenced `meshes` contain + * `JOINT` and `WEIGHT` attributes and the referenced + * `material`/`technique` from each `primitive` has parameters with + * `JOINT` and `WEIGHT` semantics. A node can have either a `matrix` or + * any combination of `translation`/`rotation`/`scale` (TRS) properties. + * TRS properties are converted to matrices and postmultiplied in the `T + * * R * S` order to compose the transformation matrix; first the scale + * is applied to the vertices, then the rotation, and then the + * translation. If none are provided, the transform is the identity. When + * a node is targeted for animation (referenced by an + * animation.channel.target), only TRS properties may be present; + * `matrix` will not be present. + * + * Auto-generated for node.schema.json + * + */ +public class Node + extends GlTFChildOfRootProperty +{ + + /** + * The ID of the camera referenced by this node. (optional) + * + */ + private String camera; + /** + * The IDs of this node's children. (optional)
+ * Default: []
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private List children; + /** + * The ID of skeleton nodes. (optional)
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private List skeletons; + /** + * The ID of the skin referenced by this node. (optional) + * + */ + private String skin; + /** + * Name used when this node is a joint in a skin. (optional) + * + */ + private String jointName; + /** + * A floating-point 4x4 transformation matrix stored in column-major + * order. (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] matrix; + /** + * The IDs of the meshes in this node. (optional)
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private List meshes; + /** + * The node's unit quaternion rotation in the order (x, y, z, w), where w + * is the scalar. (optional)
+ * Default: [0.0,0.0,0.0,1.0]
+ * Number of items: 4
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] rotation; + /** + * The node's non-uniform scale. (optional)
+ * Default: [1.0,1.0,1.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] scale; + /** + * The node's translation. (optional)
+ * Default: [0.0,0.0,0.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] translation; + + /** + * The ID of the camera referenced by this node. (optional) + * + * @param camera The camera to set + * + */ + public void setCamera(String camera) { + if (camera == null) { + this.camera = camera; + return ; + } + this.camera = camera; + } + + /** + * The ID of the camera referenced by this node. (optional) + * + * @return The camera + * + */ + public String getCamera() { + return this.camera; + } + + /** + * The IDs of this node's children. (optional)
+ * Default: []
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param children The children to set + * + */ + public void setChildren(List children) { + if (children == null) { + this.children = children; + return ; + } + this.children = children; + } + + /** + * The IDs of this node's children. (optional)
+ * Default: []
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The children + * + */ + public List getChildren() { + return this.children; + } + + /** + * Add the given children. The children of this instance will be replaced + * with a list that contains all previous elements, and additionally the + * new element. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void addChildren(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.children; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.add(element); + this.children = newList; + } + + /** + * Remove the given children. The children of this instance will be + * replaced with a list that contains all previous elements, except for + * the removed one.
+ * If this new list would be empty, then it will be set to + * null. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void removeChildren(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.children; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.remove(element); + if (newList.isEmpty()) { + this.children = null; + } else { + this.children = newList; + } + } + + /** + * Returns the default value of the children
+ * @see #getChildren + * + * @return The default children + * + */ + public List defaultChildren() { + return new ArrayList(); + } + + /** + * The ID of skeleton nodes. (optional)
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param skeletons The skeletons to set + * + */ + public void setSkeletons(List skeletons) { + if (skeletons == null) { + this.skeletons = skeletons; + return ; + } + this.skeletons = skeletons; + } + + /** + * The ID of skeleton nodes. (optional)
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The skeletons + * + */ + public List getSkeletons() { + return this.skeletons; + } + + /** + * Add the given skeletons. The skeletons of this instance will be + * replaced with a list that contains all previous elements, and + * additionally the new element. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void addSkeletons(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.skeletons; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.add(element); + this.skeletons = newList; + } + + /** + * Remove the given skeletons. The skeletons of this instance will be + * replaced with a list that contains all previous elements, except for + * the removed one.
+ * If this new list would be empty, then it will be set to + * null. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void removeSkeletons(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.skeletons; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.remove(element); + if (newList.isEmpty()) { + this.skeletons = null; + } else { + this.skeletons = newList; + } + } + + /** + * The ID of the skin referenced by this node. (optional) + * + * @param skin The skin to set + * + */ + public void setSkin(String skin) { + if (skin == null) { + this.skin = skin; + return ; + } + this.skin = skin; + } + + /** + * The ID of the skin referenced by this node. (optional) + * + * @return The skin + * + */ + public String getSkin() { + return this.skin; + } + + /** + * Name used when this node is a joint in a skin. (optional) + * + * @param jointName The jointName to set + * + */ + public void setJointName(String jointName) { + if (jointName == null) { + this.jointName = jointName; + return ; + } + this.jointName = jointName; + } + + /** + * Name used when this node is a joint in a skin. (optional) + * + * @return The jointName + * + */ + public String getJointName() { + return this.jointName; + } + + /** + * A floating-point 4x4 transformation matrix stored in column-major + * order. (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param matrix The matrix to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setMatrix(double[] matrix) { + if (matrix == null) { + this.matrix = matrix; + return ; + } + if (matrix.length< 16) { + throw new IllegalArgumentException("Number of matrix elements is < 16"); + } + if (matrix.length > 16) { + throw new IllegalArgumentException("Number of matrix elements is > 16"); + } + this.matrix = matrix; + } + + /** + * A floating-point 4x4 transformation matrix stored in column-major + * order. (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The matrix + * + */ + public double[] getMatrix() { + return this.matrix; + } + + /** + * Returns the default value of the matrix
+ * @see #getMatrix + * + * @return The default matrix + * + */ + public double[] defaultMatrix() { + return new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; + } + + /** + * The IDs of the meshes in this node. (optional)
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param meshes The meshes to set + * + */ + public void setMeshes(List meshes) { + if (meshes == null) { + this.meshes = meshes; + return ; + } + this.meshes = meshes; + } + + /** + * The IDs of the meshes in this node. (optional)
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The meshes + * + */ + public List getMeshes() { + return this.meshes; + } + + /** + * Add the given meshes. The meshes of this instance will be replaced + * with a list that contains all previous elements, and additionally the + * new element. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void addMeshes(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.meshes; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.add(element); + this.meshes = newList; + } + + /** + * Remove the given meshes. The meshes of this instance will be replaced + * with a list that contains all previous elements, except for the + * removed one.
+ * If this new list would be empty, then it will be set to + * null. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void removeMeshes(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.meshes; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.remove(element); + if (newList.isEmpty()) { + this.meshes = null; + } else { + this.meshes = newList; + } + } + + /** + * The node's unit quaternion rotation in the order (x, y, z, w), where w + * is the scalar. (optional)
+ * Default: [0.0,0.0,0.0,1.0]
+ * Number of items: 4
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param rotation The rotation to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setRotation(double[] rotation) { + if (rotation == null) { + this.rotation = rotation; + return ; + } + if (rotation.length< 4) { + throw new IllegalArgumentException("Number of rotation elements is < 4"); + } + if (rotation.length > 4) { + throw new IllegalArgumentException("Number of rotation elements is > 4"); + } + this.rotation = rotation; + } + + /** + * The node's unit quaternion rotation in the order (x, y, z, w), where w + * is the scalar. (optional)
+ * Default: [0.0,0.0,0.0,1.0]
+ * Number of items: 4
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The rotation + * + */ + public double[] getRotation() { + return this.rotation; + } + + /** + * Returns the default value of the rotation
+ * @see #getRotation + * + * @return The default rotation + * + */ + public double[] defaultRotation() { + return new double[] { 0.0, 0.0, 0.0, 1.0 }; + } + + /** + * The node's non-uniform scale. (optional)
+ * Default: [1.0,1.0,1.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param scale The scale to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setScale(double[] scale) { + if (scale == null) { + this.scale = scale; + return ; + } + if (scale.length< 3) { + throw new IllegalArgumentException("Number of scale elements is < 3"); + } + if (scale.length > 3) { + throw new IllegalArgumentException("Number of scale elements is > 3"); + } + this.scale = scale; + } + + /** + * The node's non-uniform scale. (optional)
+ * Default: [1.0,1.0,1.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The scale + * + */ + public double[] getScale() { + return this.scale; + } + + /** + * Returns the default value of the scale
+ * @see #getScale + * + * @return The default scale + * + */ + public double[] defaultScale() { + return new double[] { 1.0, 1.0, 1.0 }; + } + + /** + * The node's translation. (optional)
+ * Default: [0.0,0.0,0.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param translation The translation to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setTranslation(double[] translation) { + if (translation == null) { + this.translation = translation; + return ; + } + if (translation.length< 3) { + throw new IllegalArgumentException("Number of translation elements is < 3"); + } + if (translation.length > 3) { + throw new IllegalArgumentException("Number of translation elements is > 3"); + } + this.translation = translation; + } + + /** + * The node's translation. (optional)
+ * Default: [0.0,0.0,0.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The translation + * + */ + public double[] getTranslation() { + return this.translation; + } + + /** + * Returns the default value of the translation
+ * @see #getTranslation + * + * @return The default translation + * + */ + public double[] defaultTranslation() { + return new double[] { 0.0, 0.0, 0.0 }; + } + +} diff --git a/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Skin.java b/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Skin.java index 9f24fd86..948c3475 100644 --- a/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Skin.java +++ b/jgltf-impl-v1/src/main/java/de/javagl/jgltf/impl/v1/Skin.java @@ -5,202 +5,202 @@ * with JsonModelGen (https://github.com/javagl/JsonModelGen) * Copyright (c) 2016 Marco Hutter - http://www.javagl.de */ - -package de.javagl.jgltf.impl.v1; - -import java.util.ArrayList; -import java.util.List; - - -/** - * Joints and matrices defining a skin. - * - * Auto-generated for skin.schema.json - * - */ -public class Skin - extends GlTFChildOfRootProperty -{ - - /** - * Floating-point 4x4 transformation matrix stored in column-major order. - * (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] bindShapeMatrix; - /** - * The ID of the accessor containing the floating-point 4x4 inverse-bind - * matrices. (required) - * - */ - private String inverseBindMatrices; - /** - * Joint names of the joints (nodes with a `jointName` property) in this - * skin. (required)
- * Array elements:
- *   The elements of this array (optional) - * - */ - private List jointNames; - - /** - * Floating-point 4x4 transformation matrix stored in column-major order. - * (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - * @param bindShapeMatrix The bindShapeMatrix to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setBindShapeMatrix(float[] bindShapeMatrix) { - if (bindShapeMatrix == null) { - this.bindShapeMatrix = bindShapeMatrix; - return ; - } - if (bindShapeMatrix.length< 16) { - throw new IllegalArgumentException("Number of bindShapeMatrix elements is < 16"); - } - if (bindShapeMatrix.length > 16) { - throw new IllegalArgumentException("Number of bindShapeMatrix elements is > 16"); - } - this.bindShapeMatrix = bindShapeMatrix; - } - - /** - * Floating-point 4x4 transformation matrix stored in column-major order. - * (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - * @return The bindShapeMatrix - * - */ - public float[] getBindShapeMatrix() { - return this.bindShapeMatrix; - } - - /** - * Returns the default value of the bindShapeMatrix
- * @see #getBindShapeMatrix - * - * @return The default bindShapeMatrix - * - */ - public float[] defaultBindShapeMatrix() { - return new float[] { 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F }; - } - - /** - * The ID of the accessor containing the floating-point 4x4 inverse-bind - * matrices. (required) - * - * @param inverseBindMatrices The inverseBindMatrices to set - * @throws NullPointerException If the given value is null - * - */ - public void setInverseBindMatrices(String inverseBindMatrices) { - if (inverseBindMatrices == null) { - throw new NullPointerException((("Invalid value for inverseBindMatrices: "+ inverseBindMatrices)+", may not be null")); - } - this.inverseBindMatrices = inverseBindMatrices; - } - - /** - * The ID of the accessor containing the floating-point 4x4 inverse-bind - * matrices. (required) - * - * @return The inverseBindMatrices - * - */ - public String getInverseBindMatrices() { - return this.inverseBindMatrices; - } - - /** - * Joint names of the joints (nodes with a `jointName` property) in this - * skin. (required)
- * Array elements:
- *   The elements of this array (optional) - * - * @param jointNames The jointNames to set - * @throws NullPointerException If the given value is null - * - */ - public void setJointNames(List jointNames) { - if (jointNames == null) { - throw new NullPointerException((("Invalid value for jointNames: "+ jointNames)+", may not be null")); - } - this.jointNames = jointNames; - } - - /** - * Joint names of the joints (nodes with a `jointName` property) in this - * skin. (required)
- * Array elements:
- *   The elements of this array (optional) - * - * @return The jointNames - * - */ - public List getJointNames() { - return this.jointNames; - } - - /** - * Add the given jointNames. The jointNames of this instance will be - * replaced with a list that contains all previous elements, and - * additionally the new element. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void addJointNames(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.jointNames; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.add(element); - this.jointNames = newList; - } - - /** - * Remove the given jointNames. The jointNames of this instance will be - * replaced with a list that contains all previous elements, except for - * the removed one. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void removeJointNames(String element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.jointNames; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.remove(element); - this.jointNames = newList; - } - -} + +package de.javagl.jgltf.impl.v1; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Joints and matrices defining a skin. + * + * Auto-generated for skin.schema.json + * + */ +public class Skin + extends GlTFChildOfRootProperty +{ + + /** + * Floating-point 4x4 transformation matrix stored in column-major order. + * (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] bindShapeMatrix; + /** + * The ID of the accessor containing the floating-point 4x4 inverse-bind + * matrices. (required) + * + */ + private String inverseBindMatrices; + /** + * Joint names of the joints (nodes with a `jointName` property) in this + * skin. (required)
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private List jointNames; + + /** + * Floating-point 4x4 transformation matrix stored in column-major order. + * (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param bindShapeMatrix The bindShapeMatrix to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setBindShapeMatrix(double[] bindShapeMatrix) { + if (bindShapeMatrix == null) { + this.bindShapeMatrix = bindShapeMatrix; + return ; + } + if (bindShapeMatrix.length< 16) { + throw new IllegalArgumentException("Number of bindShapeMatrix elements is < 16"); + } + if (bindShapeMatrix.length > 16) { + throw new IllegalArgumentException("Number of bindShapeMatrix elements is > 16"); + } + this.bindShapeMatrix = bindShapeMatrix; + } + + /** + * Floating-point 4x4 transformation matrix stored in column-major order. + * (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The bindShapeMatrix + * + */ + public double[] getBindShapeMatrix() { + return this.bindShapeMatrix; + } + + /** + * Returns the default value of the bindShapeMatrix
+ * @see #getBindShapeMatrix + * + * @return The default bindShapeMatrix + * + */ + public float[] defaultBindShapeMatrix() { + return new float[] { 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F }; + } + + /** + * The ID of the accessor containing the floating-point 4x4 inverse-bind + * matrices. (required) + * + * @param inverseBindMatrices The inverseBindMatrices to set + * @throws NullPointerException If the given value is null + * + */ + public void setInverseBindMatrices(String inverseBindMatrices) { + if (inverseBindMatrices == null) { + throw new NullPointerException((("Invalid value for inverseBindMatrices: "+ inverseBindMatrices)+", may not be null")); + } + this.inverseBindMatrices = inverseBindMatrices; + } + + /** + * The ID of the accessor containing the floating-point 4x4 inverse-bind + * matrices. (required) + * + * @return The inverseBindMatrices + * + */ + public String getInverseBindMatrices() { + return this.inverseBindMatrices; + } + + /** + * Joint names of the joints (nodes with a `jointName` property) in this + * skin. (required)
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param jointNames The jointNames to set + * @throws NullPointerException If the given value is null + * + */ + public void setJointNames(List jointNames) { + if (jointNames == null) { + throw new NullPointerException((("Invalid value for jointNames: "+ jointNames)+", may not be null")); + } + this.jointNames = jointNames; + } + + /** + * Joint names of the joints (nodes with a `jointName` property) in this + * skin. (required)
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The jointNames + * + */ + public List getJointNames() { + return this.jointNames; + } + + /** + * Add the given jointNames. The jointNames of this instance will be + * replaced with a list that contains all previous elements, and + * additionally the new element. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void addJointNames(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.jointNames; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.add(element); + this.jointNames = newList; + } + + /** + * Remove the given jointNames. The jointNames of this instance will be + * replaced with a list that contains all previous elements, except for + * the removed one. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void removeJointNames(String element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.jointNames; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.remove(element); + this.jointNames = newList; + } + +} diff --git a/jgltf-impl-v2/src/main/java/de/javagl/jgltf/impl/v2/Node.java b/jgltf-impl-v2/src/main/java/de/javagl/jgltf/impl/v2/Node.java index bffdb7f7..8110fb48 100644 --- a/jgltf-impl-v2/src/main/java/de/javagl/jgltf/impl/v2/Node.java +++ b/jgltf-impl-v2/src/main/java/de/javagl/jgltf/impl/v2/Node.java @@ -5,584 +5,584 @@ * with JsonModelGen (https://github.com/javagl/JsonModelGen) * Copyright (c) 2016-2021 Marco Hutter - http://www.javagl.de */ - -package de.javagl.jgltf.impl.v2; - -import java.util.ArrayList; -import java.util.List; - - -/** - * A node in the node hierarchy. When the node contains `skin`, all - * `mesh.primitives` **MUST** contain `JOINTS_0` and `WEIGHTS_0` - * attributes. A node **MAY** have either a `matrix` or any combination - * of `translation`/`rotation`/`scale` (TRS) properties. TRS properties - * are converted to matrices and postmultiplied in the `T * R * S` order - * to compose the transformation matrix; first the scale is applied to - * the vertices, then the rotation, and then the translation. If none are - * provided, the transform is the identity. When a node is targeted for - * animation (referenced by an animation.channel.target), `matrix` **MUST - * NOT** be present. - * - * Auto-generated for node.schema.json - * - */ -public class Node - extends GlTFChildOfRootProperty -{ - - /** - * The index of the camera referenced by this node. (optional) - * - */ - private Integer camera; - /** - * The indices of this node's children. (optional)
- * Minimum number of items: 1
- * Array elements:
- *   The elements of this array (optional)
- *   Minimum: 0 (inclusive) - * - */ - private List children; - /** - * The index of the skin referenced by this node. (optional) - * - */ - private Integer skin; - /** - * A floating-point 4x4 transformation matrix stored in column-major - * order. (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] matrix; - /** - * The index of the mesh in this node. (optional) - * - */ - private Integer mesh; - /** - * The node's unit quaternion rotation in the order (x, y, z, w), where w - * is the scalar. (optional)
- * Default: [0.0,0.0,0.0,1.0]
- * Number of items: 4
- * Array elements:
- *   The elements of this array (optional)
- *   Minimum: -1.0 (inclusive)
- *   Maximum: 1.0 (inclusive) - * - */ - private float[] rotation; - /** - * The node's non-uniform scale, given as the scaling factors along the - * x, y, and z axes. (optional)
- * Default: [1.0,1.0,1.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] scale; - /** - * The node's translation along the x, y, and z axes. (optional)
- * Default: [0.0,0.0,0.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - */ - private float[] translation; - /** - * The weights of the instantiated morph target. The number of array - * elements **MUST** match the number of morph targets of the referenced - * mesh. When defined, `mesh` **MUST** also be defined. (optional)
- * Minimum number of items: 1
- * Array elements:
- *   The elements of this array (optional) - * - */ - private List weights; - - /** - * The index of the camera referenced by this node. (optional) - * - * @param camera The camera to set - * - */ - public void setCamera(Integer camera) { - if (camera == null) { - this.camera = camera; - return ; - } - this.camera = camera; - } - - /** - * The index of the camera referenced by this node. (optional) - * - * @return The camera - * - */ - public Integer getCamera() { - return this.camera; - } - - /** - * The indices of this node's children. (optional)
- * Minimum number of items: 1
- * Array elements:
- *   The elements of this array (optional)
- *   Minimum: 0 (inclusive) - * - * @param children The children to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setChildren(List children) { - if (children == null) { - this.children = children; - return ; - } - if (children.size()< 1) { - throw new IllegalArgumentException("Number of children elements is < 1"); - } - for (Integer childrenElement: children) { - if (childrenElement< 0) { - throw new IllegalArgumentException("childrenElement < 0"); - } - } - this.children = children; - } - - /** - * The indices of this node's children. (optional)
- * Minimum number of items: 1
- * Array elements:
- *   The elements of this array (optional)
- *   Minimum: 0 (inclusive) - * - * @return The children - * - */ - public List getChildren() { - return this.children; - } - - /** - * Add the given children. The children of this instance will be replaced - * with a list that contains all previous elements, and additionally the - * new element. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void addChildren(Integer element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.children; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.add(element); - this.children = newList; - } - - /** - * Remove the given children. The children of this instance will be - * replaced with a list that contains all previous elements, except for - * the removed one.
- * If this new list would be empty, then it will be set to - * null. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void removeChildren(Integer element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.children; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.remove(element); - if (newList.isEmpty()) { - this.children = null; - } else { - this.children = newList; - } - } - - /** - * The index of the skin referenced by this node. (optional) - * - * @param skin The skin to set - * - */ - public void setSkin(Integer skin) { - if (skin == null) { - this.skin = skin; - return ; - } - this.skin = skin; - } - - /** - * The index of the skin referenced by this node. (optional) - * - * @return The skin - * - */ - public Integer getSkin() { - return this.skin; - } - - /** - * A floating-point 4x4 transformation matrix stored in column-major - * order. (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - * @param matrix The matrix to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setMatrix(float[] matrix) { - if (matrix == null) { - this.matrix = matrix; - return ; - } - if (matrix.length< 16) { - throw new IllegalArgumentException("Number of matrix elements is < 16"); - } - if (matrix.length > 16) { - throw new IllegalArgumentException("Number of matrix elements is > 16"); - } - this.matrix = matrix; - } - - /** - * A floating-point 4x4 transformation matrix stored in column-major - * order. (optional)
- * Default: - * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
- * Number of items: 16
- * Array elements:
- *   The elements of this array (optional) - * - * @return The matrix - * - */ - public float[] getMatrix() { - return this.matrix; - } - - /** - * Returns the default value of the matrix
- * @see #getMatrix - * - * @return The default matrix - * - */ - public float[] defaultMatrix() { - return new float[] { 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F }; - } - - /** - * The index of the mesh in this node. (optional) - * - * @param mesh The mesh to set - * - */ - public void setMesh(Integer mesh) { - if (mesh == null) { - this.mesh = mesh; - return ; - } - this.mesh = mesh; - } - - /** - * The index of the mesh in this node. (optional) - * - * @return The mesh - * - */ - public Integer getMesh() { - return this.mesh; - } - - /** - * The node's unit quaternion rotation in the order (x, y, z, w), where w - * is the scalar. (optional)
- * Default: [0.0,0.0,0.0,1.0]
- * Number of items: 4
- * Array elements:
- *   The elements of this array (optional)
- *   Minimum: -1.0 (inclusive)
- *   Maximum: 1.0 (inclusive) - * - * @param rotation The rotation to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setRotation(float[] rotation) { - if (rotation == null) { - this.rotation = rotation; - return ; - } - if (rotation.length< 4) { - throw new IllegalArgumentException("Number of rotation elements is < 4"); - } - if (rotation.length > 4) { - throw new IllegalArgumentException("Number of rotation elements is > 4"); - } - for (float rotationElement: rotation) { - if (rotationElement > 1.0D) { - throw new IllegalArgumentException("rotationElement > 1.0"); - } - if (rotationElement<-1.0D) { - throw new IllegalArgumentException("rotationElement < -1.0"); - } - } - this.rotation = rotation; - } - - /** - * The node's unit quaternion rotation in the order (x, y, z, w), where w - * is the scalar. (optional)
- * Default: [0.0,0.0,0.0,1.0]
- * Number of items: 4
- * Array elements:
- *   The elements of this array (optional)
- *   Minimum: -1.0 (inclusive)
- *   Maximum: 1.0 (inclusive) - * - * @return The rotation - * - */ - public float[] getRotation() { - return this.rotation; - } - - /** - * Returns the default value of the rotation
- * @see #getRotation - * - * @return The default rotation - * - */ - public float[] defaultRotation() { - return new float[] { 0.0F, 0.0F, 0.0F, 1.0F }; - } - - /** - * The node's non-uniform scale, given as the scaling factors along the - * x, y, and z axes. (optional)
- * Default: [1.0,1.0,1.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @param scale The scale to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setScale(float[] scale) { - if (scale == null) { - this.scale = scale; - return ; - } - if (scale.length< 3) { - throw new IllegalArgumentException("Number of scale elements is < 3"); - } - if (scale.length > 3) { - throw new IllegalArgumentException("Number of scale elements is > 3"); - } - this.scale = scale; - } - - /** - * The node's non-uniform scale, given as the scaling factors along the - * x, y, and z axes. (optional)
- * Default: [1.0,1.0,1.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @return The scale - * - */ - public float[] getScale() { - return this.scale; - } - - /** - * Returns the default value of the scale
- * @see #getScale - * - * @return The default scale - * - */ - public float[] defaultScale() { - return new float[] { 1.0F, 1.0F, 1.0F }; - } - - /** - * The node's translation along the x, y, and z axes. (optional)
- * Default: [0.0,0.0,0.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @param translation The translation to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setTranslation(float[] translation) { - if (translation == null) { - this.translation = translation; - return ; - } - if (translation.length< 3) { - throw new IllegalArgumentException("Number of translation elements is < 3"); - } - if (translation.length > 3) { - throw new IllegalArgumentException("Number of translation elements is > 3"); - } - this.translation = translation; - } - - /** - * The node's translation along the x, y, and z axes. (optional)
- * Default: [0.0,0.0,0.0]
- * Number of items: 3
- * Array elements:
- *   The elements of this array (optional) - * - * @return The translation - * - */ - public float[] getTranslation() { - return this.translation; - } - - /** - * Returns the default value of the translation
- * @see #getTranslation - * - * @return The default translation - * - */ - public float[] defaultTranslation() { - return new float[] { 0.0F, 0.0F, 0.0F }; - } - - /** - * The weights of the instantiated morph target. The number of array - * elements **MUST** match the number of morph targets of the referenced - * mesh. When defined, `mesh` **MUST** also be defined. (optional)
- * Minimum number of items: 1
- * Array elements:
- *   The elements of this array (optional) - * - * @param weights The weights to set - * @throws IllegalArgumentException If the given value does not meet - * the given constraints - * - */ - public void setWeights(List weights) { - if (weights == null) { - this.weights = weights; - return ; - } - if (weights.size()< 1) { - throw new IllegalArgumentException("Number of weights elements is < 1"); - } - this.weights = weights; - } - - /** - * The weights of the instantiated morph target. The number of array - * elements **MUST** match the number of morph targets of the referenced - * mesh. When defined, `mesh` **MUST** also be defined. (optional)
- * Minimum number of items: 1
- * Array elements:
- *   The elements of this array (optional) - * - * @return The weights - * - */ - public List getWeights() { - return this.weights; - } - - /** - * Add the given weights. The weights of this instance will be replaced - * with a list that contains all previous elements, and additionally the - * new element. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void addWeights(Float element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.weights; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.add(element); - this.weights = newList; - } - - /** - * Remove the given weights. The weights of this instance will be - * replaced with a list that contains all previous elements, except for - * the removed one.
- * If this new list would be empty, then it will be set to - * null. - * - * @param element The element - * @throws NullPointerException If the given element is null - * - */ - public void removeWeights(Float element) { - if (element == null) { - throw new NullPointerException("The element may not be null"); - } - List oldList = this.weights; - List newList = new ArrayList(); - if (oldList!= null) { - newList.addAll(oldList); - } - newList.remove(element); - if (newList.isEmpty()) { - this.weights = null; - } else { - this.weights = newList; - } - } - -} + +package de.javagl.jgltf.impl.v2; + +import java.util.ArrayList; +import java.util.List; + + +/** + * A node in the node hierarchy. When the node contains `skin`, all + * `mesh.primitives` **MUST** contain `JOINTS_0` and `WEIGHTS_0` + * attributes. A node **MAY** have either a `matrix` or any combination + * of `translation`/`rotation`/`scale` (TRS) properties. TRS properties + * are converted to matrices and postmultiplied in the `T * R * S` order + * to compose the transformation matrix; first the scale is applied to + * the vertices, then the rotation, and then the translation. If none are + * provided, the transform is the identity. When a node is targeted for + * animation (referenced by an animation.channel.target), `matrix` **MUST + * NOT** be present. + * + * Auto-generated for node.schema.json + * + */ +public class Node + extends GlTFChildOfRootProperty +{ + + /** + * The index of the camera referenced by this node. (optional) + * + */ + private Integer camera; + /** + * The indices of this node's children. (optional)
+ * Minimum number of items: 1
+ * Array elements:
+ *   The elements of this array (optional)
+ *   Minimum: 0 (inclusive) + * + */ + private List children; + /** + * The index of the skin referenced by this node. (optional) + * + */ + private Integer skin; + /** + * A floating-point 4x4 transformation matrix stored in column-major + * order. (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] matrix; + /** + * The index of the mesh in this node. (optional) + * + */ + private Integer mesh; + /** + * The node's unit quaternion rotation in the order (x, y, z, w), where w + * is the scalar. (optional)
+ * Default: [0.0,0.0,0.0,1.0]
+ * Number of items: 4
+ * Array elements:
+ *   The elements of this array (optional)
+ *   Minimum: -1.0 (inclusive)
+ *   Maximum: 1.0 (inclusive) + * + */ + private double[] rotation; + /** + * The node's non-uniform scale, given as the scaling factors along the + * x, y, and z axes. (optional)
+ * Default: [1.0,1.0,1.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] scale; + /** + * The node's translation along the x, y, and z axes. (optional)
+ * Default: [0.0,0.0,0.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private double[] translation; + /** + * The weights of the instantiated morph target. The number of array + * elements **MUST** match the number of morph targets of the referenced + * mesh. When defined, `mesh` **MUST** also be defined. (optional)
+ * Minimum number of items: 1
+ * Array elements:
+ *   The elements of this array (optional) + * + */ + private List weights; + + /** + * The index of the camera referenced by this node. (optional) + * + * @param camera The camera to set + * + */ + public void setCamera(Integer camera) { + if (camera == null) { + this.camera = camera; + return ; + } + this.camera = camera; + } + + /** + * The index of the camera referenced by this node. (optional) + * + * @return The camera + * + */ + public Integer getCamera() { + return this.camera; + } + + /** + * The indices of this node's children. (optional)
+ * Minimum number of items: 1
+ * Array elements:
+ *   The elements of this array (optional)
+ *   Minimum: 0 (inclusive) + * + * @param children The children to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setChildren(List children) { + if (children == null) { + this.children = children; + return ; + } + if (children.size()< 1) { + throw new IllegalArgumentException("Number of children elements is < 1"); + } + for (Integer childrenElement: children) { + if (childrenElement< 0) { + throw new IllegalArgumentException("childrenElement < 0"); + } + } + this.children = children; + } + + /** + * The indices of this node's children. (optional)
+ * Minimum number of items: 1
+ * Array elements:
+ *   The elements of this array (optional)
+ *   Minimum: 0 (inclusive) + * + * @return The children + * + */ + public List getChildren() { + return this.children; + } + + /** + * Add the given children. The children of this instance will be replaced + * with a list that contains all previous elements, and additionally the + * new element. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void addChildren(Integer element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.children; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.add(element); + this.children = newList; + } + + /** + * Remove the given children. The children of this instance will be + * replaced with a list that contains all previous elements, except for + * the removed one.
+ * If this new list would be empty, then it will be set to + * null. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void removeChildren(Integer element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.children; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.remove(element); + if (newList.isEmpty()) { + this.children = null; + } else { + this.children = newList; + } + } + + /** + * The index of the skin referenced by this node. (optional) + * + * @param skin The skin to set + * + */ + public void setSkin(Integer skin) { + if (skin == null) { + this.skin = skin; + return ; + } + this.skin = skin; + } + + /** + * The index of the skin referenced by this node. (optional) + * + * @return The skin + * + */ + public Integer getSkin() { + return this.skin; + } + + /** + * A floating-point 4x4 transformation matrix stored in column-major + * order. (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param matrix The matrix to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setMatrix(double[] matrix) { + if (matrix == null) { + this.matrix = matrix; + return ; + } + if (matrix.length< 16) { + throw new IllegalArgumentException("Number of matrix elements is < 16"); + } + if (matrix.length > 16) { + throw new IllegalArgumentException("Number of matrix elements is > 16"); + } + this.matrix = matrix; + } + + /** + * A floating-point 4x4 transformation matrix stored in column-major + * order. (optional)
+ * Default: + * [1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]
+ * Number of items: 16
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The matrix + * + */ + public double[] getMatrix() { + return this.matrix; + } + + /** + * Returns the default value of the matrix
+ * @see #getMatrix + * + * @return The default matrix + * + */ + public double[] defaultMatrix() { + return new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; + } + + /** + * The index of the mesh in this node. (optional) + * + * @param mesh The mesh to set + * + */ + public void setMesh(Integer mesh) { + if (mesh == null) { + this.mesh = mesh; + return ; + } + this.mesh = mesh; + } + + /** + * The index of the mesh in this node. (optional) + * + * @return The mesh + * + */ + public Integer getMesh() { + return this.mesh; + } + + /** + * The node's unit quaternion rotation in the order (x, y, z, w), where w + * is the scalar. (optional)
+ * Default: [0.0,0.0,0.0,1.0]
+ * Number of items: 4
+ * Array elements:
+ *   The elements of this array (optional)
+ *   Minimum: -1.0 (inclusive)
+ *   Maximum: 1.0 (inclusive) + * + * @param rotation The rotation to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setRotation(double[] rotation) { + if (rotation == null) { + this.rotation = rotation; + return ; + } + if (rotation.length< 4) { + throw new IllegalArgumentException("Number of rotation elements is < 4"); + } + if (rotation.length > 4) { + throw new IllegalArgumentException("Number of rotation elements is > 4"); + } + for (double rotationElement: rotation) { + if (rotationElement > 1.0D) { + throw new IllegalArgumentException("rotationElement > 1.0"); + } + if (rotationElement<-1.0D) { + throw new IllegalArgumentException("rotationElement < -1.0"); + } + } + this.rotation = rotation; + } + + /** + * The node's unit quaternion rotation in the order (x, y, z, w), where w + * is the scalar. (optional)
+ * Default: [0.0,0.0,0.0,1.0]
+ * Number of items: 4
+ * Array elements:
+ *   The elements of this array (optional)
+ *   Minimum: -1.0 (inclusive)
+ *   Maximum: 1.0 (inclusive) + * + * @return The rotation + * + */ + public double[] getRotation() { + return this.rotation; + } + + /** + * Returns the default value of the rotation
+ * @see #getRotation + * + * @return The default rotation + * + */ + public double[] defaultRotation() { + return new double[] { 0.0, 0.0, 0.0, 1.0 }; + } + + /** + * The node's non-uniform scale, given as the scaling factors along the + * x, y, and z axes. (optional)
+ * Default: [1.0,1.0,1.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param scale The scale to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setScale(double[] scale) { + if (scale == null) { + this.scale = scale; + return ; + } + if (scale.length< 3) { + throw new IllegalArgumentException("Number of scale elements is < 3"); + } + if (scale.length > 3) { + throw new IllegalArgumentException("Number of scale elements is > 3"); + } + this.scale = scale; + } + + /** + * The node's non-uniform scale, given as the scaling factors along the + * x, y, and z axes. (optional)
+ * Default: [1.0,1.0,1.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The scale + * + */ + public double[] getScale() { + return this.scale; + } + + /** + * Returns the default value of the scale
+ * @see #getScale + * + * @return The default scale + * + */ + public double[] defaultScale() { + return new double[] { 1.0, 1.0, 1.0 }; + } + + /** + * The node's translation along the x, y, and z axes. (optional)
+ * Default: [0.0,0.0,0.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param translation The translation to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setTranslation(double[] translation) { + if (translation == null) { + this.translation = translation; + return ; + } + if (translation.length< 3) { + throw new IllegalArgumentException("Number of translation elements is < 3"); + } + if (translation.length > 3) { + throw new IllegalArgumentException("Number of translation elements is > 3"); + } + this.translation = translation; + } + + /** + * The node's translation along the x, y, and z axes. (optional)
+ * Default: [0.0,0.0,0.0]
+ * Number of items: 3
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The translation + * + */ + public double[] getTranslation() { + return this.translation; + } + + /** + * Returns the default value of the translation
+ * @see #getTranslation + * + * @return The default translation + * + */ + public double[] defaultTranslation() { + return new double[] { 0.0, 0.0, 0.0 }; + } + + /** + * The weights of the instantiated morph target. The number of array + * elements **MUST** match the number of morph targets of the referenced + * mesh. When defined, `mesh` **MUST** also be defined. (optional)
+ * Minimum number of items: 1
+ * Array elements:
+ *   The elements of this array (optional) + * + * @param weights The weights to set + * @throws IllegalArgumentException If the given value does not meet + * the given constraints + * + */ + public void setWeights(List weights) { + if (weights == null) { + this.weights = weights; + return ; + } + if (weights.size()< 1) { + throw new IllegalArgumentException("Number of weights elements is < 1"); + } + this.weights = weights; + } + + /** + * The weights of the instantiated morph target. The number of array + * elements **MUST** match the number of morph targets of the referenced + * mesh. When defined, `mesh` **MUST** also be defined. (optional)
+ * Minimum number of items: 1
+ * Array elements:
+ *   The elements of this array (optional) + * + * @return The weights + * + */ + public List getWeights() { + return this.weights; + } + + /** + * Add the given weights. The weights of this instance will be replaced + * with a list that contains all previous elements, and additionally the + * new element. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void addWeights(Float element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.weights; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.add(element); + this.weights = newList; + } + + /** + * Remove the given weights. The weights of this instance will be + * replaced with a list that contains all previous elements, except for + * the removed one.
+ * If this new list would be empty, then it will be set to + * null. + * + * @param element The element + * @throws NullPointerException If the given element is null + * + */ + public void removeWeights(Float element) { + if (element == null) { + throw new NullPointerException("The element may not be null"); + } + List oldList = this.weights; + List newList = new ArrayList(); + if (oldList!= null) { + newList.addAll(oldList); + } + newList.remove(element); + if (newList.isEmpty()) { + this.weights = null; + } else { + this.weights = newList; + } + } + +} diff --git a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/DuplicateMeshesTest.java b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/DuplicateMeshesTest.java index 6fe484a9..5699e223 100644 --- a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/DuplicateMeshesTest.java +++ b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/DuplicateMeshesTest.java @@ -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); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxComputer.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxComputer.java index 320a7068..f080ae20 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxComputer.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxComputer.java @@ -67,7 +67,7 @@ BoundingBox compute() List sceneModels = gltfModel.getSceneModels(); for (SceneModel sceneModel : sceneModels) { - float rootTransform[] = MathUtils.createIdentity4x4(); + double rootTransform[] = MathUtils.createIdentity4x4(); computeSceneBoundingBox(sceneModel, rootTransform, boundingBox); } return boundingBox; @@ -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) @@ -115,7 +115,7 @@ 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) @@ -123,8 +123,8 @@ private BoundingBox computeNodeBoundingBox( 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 meshModels = nodeModel.getMeshModels(); @@ -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) @@ -194,7 +194,7 @@ private BoundingBox computeMeshBoundingBox( * returned. */ private BoundingBox computeBoundingBox( - MeshPrimitiveModel meshPrimitiveModel, float transform[]) + MeshPrimitiveModel meshPrimitiveModel, double transform[]) { Map attributes = meshPrimitiveModel.getAttributes(); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/CameraModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/CameraModel.java index 7e71e92d..cb39d51a 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/CameraModel.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/CameraModel.java @@ -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.
@@ -84,7 +84,7 @@ public interface CameraModel extends NamedModelElement * aspect ratio of the camera will be used. * @return The supplier */ - Supplier createProjectionMatrixSupplier( + Supplier createProjectionMatrixSupplier( DoubleSupplier aspectRatioSupplier); } \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/GltfAnimations.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/GltfAnimations.java index 07337743..b8014900 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/GltfAnimations.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/GltfAnimations.java @@ -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]; + } } }; } @@ -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]; + } } }; } @@ -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]; + } } }; } diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/MathUtils.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/MathUtils.java index 9afc5076..ef4b4f5c 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/MathUtils.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/MathUtils.java @@ -58,16 +58,16 @@ public class MathUtils /** * Epsilon for floating point computations */ - private static final float FLOAT_EPSILON = 1e-8f; + private static final double FLOAT_EPSILON = 1e-8f; /** * Creates a 4x4 identity matrix * * @return The matrix */ - public static float[] createIdentity4x4() + public static double[] createIdentity4x4() { - float m[] = new float[16]; + double m[] = new double[16]; setIdentity4x4(m); return m; } @@ -77,7 +77,7 @@ public static float[] createIdentity4x4() * * @param m The matrix */ - public static void setIdentity4x4(float m[]) + public static void setIdentity4x4(double m[]) { Arrays.fill(m, 0.0f); m[0] = 1.0f; @@ -91,7 +91,7 @@ public static void setIdentity4x4(float m[]) * * @param m The matrix */ - static void setIdentity3x3(float m[]) + static void setIdentity3x3(double m[]) { Arrays.fill(m, 0.0f); m[0] = 1.0f; @@ -107,7 +107,7 @@ static void setIdentity3x3(float m[]) * @param source The source array * @param target The target array */ - static void set(float source[], float target[]) + static void set(double source[], double target[]) { System.arraycopy(source, 0, target, 0, Math.min(source.length, target.length)); @@ -122,7 +122,7 @@ static void set(float source[], float target[]) * @param targetMatrix3x3 The target matrix */ public static void getRotationScale( - float sourceMatrix4x4[], float targetMatrix3x3[]) + double sourceMatrix4x4[], double targetMatrix3x3[]) { targetMatrix3x3[0] = sourceMatrix4x4[ 0]; targetMatrix3x3[1] = sourceMatrix4x4[ 1]; @@ -143,17 +143,17 @@ public static void getRotationScale( * @param m The input matrix * @param t The target matrix */ - static void transpose3x3(float m[], float t[]) + static void transpose3x3(double m[], double t[]) { - float m0 = m[0]; - float m1 = m[1]; - float m2 = m[2]; - float m3 = m[3]; - float m4 = m[4]; - float m5 = m[5]; - float m6 = m[6]; - float m7 = m[7]; - float m8 = m[8]; + double m0 = m[0]; + double m1 = m[1]; + double m2 = m[2]; + double m3 = m[3]; + double m4 = m[4]; + double m5 = m[5]; + double m6 = m[6]; + double m7 = m[7]; + double m8 = m[8]; t[0] = m0; t[1] = m3; t[2] = m6; @@ -172,24 +172,24 @@ static void transpose3x3(float m[], float t[]) * @param m The input matrix * @param t The target matrix */ - public static void transpose4x4(float m[], float t[]) + public static void transpose4x4(double m[], double t[]) { - float m0 = m[ 0]; - float m1 = m[ 1]; - float m2 = m[ 2]; - float m3 = m[ 3]; - float m4 = m[ 4]; - float m5 = m[ 5]; - float m6 = m[ 6]; - float m7 = m[ 7]; - float m8 = m[ 8]; - float m9 = m[ 9]; - float mA = m[10]; - float mB = m[11]; - float mC = m[12]; - float mD = m[13]; - float mE = m[14]; - float mF = m[15]; + double m0 = m[ 0]; + double m1 = m[ 1]; + double m2 = m[ 2]; + double m3 = m[ 3]; + double m4 = m[ 4]; + double m5 = m[ 5]; + double m6 = m[ 6]; + double m7 = m[ 7]; + double m8 = m[ 8]; + double m9 = m[ 9]; + double mA = m[10]; + double mB = m[11]; + double mC = m[12]; + double mD = m[13]; + double mE = m[14]; + double mF = m[15]; t[ 0] = m0; t[ 1] = m4; t[ 2] = m8; @@ -215,61 +215,61 @@ public static void transpose4x4(float m[], float t[]) * @param b The second matrix * @param m The result matrix */ - public static void mul4x4(float a[], float b[], float m[]) + public static void mul4x4(double a[], double b[], double m[]) { - float a00 = a[ 0]; - float a10 = a[ 1]; - float a20 = a[ 2]; - float a30 = a[ 3]; - float a01 = a[ 4]; - float a11 = a[ 5]; - float a21 = a[ 6]; - float a31 = a[ 7]; - float a02 = a[ 8]; - float a12 = a[ 9]; - float a22 = a[10]; - float a32 = a[11]; - float a03 = a[12]; - float a13 = a[13]; - float a23 = a[14]; - float a33 = a[15]; + double a00 = a[ 0]; + double a10 = a[ 1]; + double a20 = a[ 2]; + double a30 = a[ 3]; + double a01 = a[ 4]; + double a11 = a[ 5]; + double a21 = a[ 6]; + double a31 = a[ 7]; + double a02 = a[ 8]; + double a12 = a[ 9]; + double a22 = a[10]; + double a32 = a[11]; + double a03 = a[12]; + double a13 = a[13]; + double a23 = a[14]; + double a33 = a[15]; - float b00 = b[ 0]; - float b10 = b[ 1]; - float b20 = b[ 2]; - float b30 = b[ 3]; - float b01 = b[ 4]; - float b11 = b[ 5]; - float b21 = b[ 6]; - float b31 = b[ 7]; - float b02 = b[ 8]; - float b12 = b[ 9]; - float b22 = b[10]; - float b32 = b[11]; - float b03 = b[12]; - float b13 = b[13]; - float b23 = b[14]; - float b33 = b[15]; + double b00 = b[ 0]; + double b10 = b[ 1]; + double b20 = b[ 2]; + double b30 = b[ 3]; + double b01 = b[ 4]; + double b11 = b[ 5]; + double b21 = b[ 6]; + double b31 = b[ 7]; + double b02 = b[ 8]; + double b12 = b[ 9]; + double b22 = b[10]; + double b32 = b[11]; + double b03 = b[12]; + double b13 = b[13]; + double b23 = b[14]; + double b33 = b[15]; - float m00 = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30; - float m01 = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31; - float m02 = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32; - float m03 = a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33; + double m00 = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30; + double m01 = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31; + double m02 = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32; + double m03 = a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33; - float m10 = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30; - float m11 = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31; - float m12 = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32; - float m13 = a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33; + double m10 = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30; + double m11 = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31; + double m12 = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32; + double m13 = a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33; - float m20 = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30; - float m21 = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31; - float m22 = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32; - float m23 = a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33; + double m20 = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30; + double m21 = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31; + double m22 = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32; + double m23 = a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33; - float m30 = a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30; - float m31 = a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31; - float m32 = a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32; - float m33 = a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33; + double m30 = a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30; + double m31 = a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31; + double m32 = a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32; + double m33 = a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33; m[ 0] = m00; m[ 1] = m10; @@ -298,15 +298,15 @@ public static void mul4x4(float a[], float b[], float m[]) * @param q The quaternion * @param m The matrix */ - public static void quaternionToMatrix4x4(float q[], float m[]) + public static void quaternionToMatrix4x4(double q[], double m[]) { - float invLength = 1.0f / (float)Math.sqrt(dot(q, q)); + double invLength = 1.0f / Math.sqrt(dot(q, q)); // Adapted from javax.vecmath.Matrix4f - float qx = q[0] * invLength; - float qy = q[1] * invLength; - float qz = q[2] * invLength; - float qw = q[3] * invLength; + double qx = q[0] * invLength; + double qy = q[1] * invLength; + double qz = q[2] * invLength; + double qw = q[3] * invLength; m[ 0] = 1.0f - 2.0f * qy * qy - 2.0f * qz * qz; m[ 1] = 2.0f * (qx * qy + qw * qz); m[ 2] = 2.0f * (qx * qz - qw * qy); @@ -333,27 +333,27 @@ public static void quaternionToMatrix4x4(float q[], float m[]) * @param m The input matrix * @param inv The inverse matrix */ - public static void invert4x4(float m[], float inv[]) + public static void invert4x4(double m[], double inv[]) { // Adapted from The Mesa 3-D graphics library. // Copyright (C) 1999-2007 Brian Paul All Rights Reserved. // Published under the MIT license (see the header of this file) - float m0 = m[ 0]; - float m1 = m[ 1]; - float m2 = m[ 2]; - float m3 = m[ 3]; - float m4 = m[ 4]; - float m5 = m[ 5]; - float m6 = m[ 6]; - float m7 = m[ 7]; - float m8 = m[ 8]; - float m9 = m[ 9]; - float mA = m[10]; - float mB = m[11]; - float mC = m[12]; - float mD = m[13]; - float mE = m[14]; - float mF = m[15]; + double m0 = m[ 0]; + double m1 = m[ 1]; + double m2 = m[ 2]; + double m3 = m[ 3]; + double m4 = m[ 4]; + double m5 = m[ 5]; + double m6 = m[ 6]; + double m7 = m[ 7]; + double m8 = m[ 8]; + double m9 = m[ 9]; + double mA = m[10]; + double mB = m[11]; + double mC = m[12]; + double mD = m[13]; + double mE = m[14]; + double mF = m[15]; inv[ 0] = m5 * mA * mF - m5 * mB * mE - m9 * m6 * mF + m9 * m7 * mE + mD * m6 * mB - mD * m7 * mA; @@ -389,7 +389,7 @@ public static void invert4x4(float m[], float inv[]) m4 * m2 * m9 + m8 * m1 * m6 - m8 * m2 * m5; // (Ain't that pretty?) - float det = m0 * inv[0] + m1 * inv[4] + m2 * inv[8] + m3 * inv[12]; + double det = m0 * inv[0] + m1 * inv[4] + m2 * inv[8] + m3 * inv[12]; if (Math.abs(det) <= FLOAT_EPSILON) { if (logger.isLoggable(Level.FINE)) @@ -400,7 +400,7 @@ public static void invert4x4(float m[], float inv[]) setIdentity4x4(inv); return; } - float invDet = 1.0f / det; + double invDet = 1.0f / det; for (int i = 0; i < 16; i++) { inv[i] *= invDet; @@ -415,19 +415,19 @@ public static void invert4x4(float m[], float inv[]) * @param m The input matrix * @param inv The inverse matrix */ - public static void invert3x3(float m[], float inv[]) + public static void invert3x3(double m[], double inv[]) { // Adapted from http://stackoverflow.com/a/18504573 - float m0 = m[0]; - float m1 = m[1]; - float m2 = m[2]; - float m3 = m[3]; - float m4 = m[4]; - float m5 = m[5]; - float m6 = m[6]; - float m7 = m[7]; - float m8 = m[8]; - float det = m0 * (m4 * m8 - m5 * m7) - + double m0 = m[0]; + double m1 = m[1]; + double m2 = m[2]; + double m3 = m[3]; + double m4 = m[4]; + double m5 = m[5]; + double m6 = m[6]; + double m7 = m[7]; + double m8 = m[8]; + double det = m0 * (m4 * m8 - m5 * m7) - m3 * (m1 * m8 - m7 * m2) + m6 * (m1 * m5 - m4 * m2); if (Math.abs(det) <= FLOAT_EPSILON) @@ -440,7 +440,7 @@ public static void invert3x3(float m[], float inv[]) setIdentity3x3(inv); return; } - float invDet = 1.0f / det; + double invDet = 1.0f / det; inv[0] = (m4 * m8 - m5 * m7) * invDet; inv[3] = (m6 * m5 - m3 * m8) * invDet; inv[6] = (m3 * m7 - m6 * m4) * invDet; @@ -463,7 +463,7 @@ public static void invert3x3(float m[], float inv[]) * @param result The result matrix */ public static void translate( - float m[], float x, float y, float z, float result[]) + double m[], double x, double y, double z, double result[]) { set(m, result); result[12] += x; @@ -481,11 +481,11 @@ public static void translate( * @param m The matrix to fill */ public static void infinitePerspective4x4( - float fovyDeg, float aspect, float zNear, float m[]) + double fovyDeg, double aspect, double zNear, double m[]) { setIdentity4x4(m); - float fovyRad = (float)Math.toRadians(fovyDeg); - float t = (float)Math.tan(0.5 * fovyRad); + double fovyRad = Math.toRadians(fovyDeg); + double t = Math.tan(0.5 * fovyRad); m[0] = 1.0f / (aspect * t); m[5] = 1.0f / t; m[10] = -1.0f; @@ -505,11 +505,11 @@ public static void infinitePerspective4x4( * @param m The matrix to fill */ public static void perspective4x4( - float fovyDeg, float aspect, float zNear, float zFar, float m[]) + double fovyDeg, double aspect, double zNear, double zFar, double m[]) { setIdentity4x4(m); - float fovyRad = (float)Math.toRadians(fovyDeg); - float t = (float)Math.tan(0.5 * fovyRad); + double fovyRad = Math.toRadians(fovyDeg); + double t = Math.tan(0.5 * fovyRad); m[0] = 1.0f / (aspect * t); m[5] = 1.0f / t; m[10] = (zFar + zNear) / (zNear - zFar); @@ -527,9 +527,9 @@ public static void perspective4x4( * @param b The second array * @return The dot product */ - private static float dot(float a[], float b[]) + private static double dot(double a[], double b[]) { - float sum = 0; + double sum = 0; for (int i=0; i getMeshPrimitiveModels(); /** - * Returns a reference to the default morph target weights, - * or null if no default morph target weights have + * Returns a reference to the default morph target weights, + * or null if no default morph target weights have * been defined - * + * * @return The morph target weights */ float[] getWeights(); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/NodeModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/NodeModel.java index 79d0d83a..54dc7f95 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/NodeModel.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/NodeModel.java @@ -88,7 +88,7 @@ public interface NodeModel extends NamedModelElement * @throws IllegalArgumentException If the given array does not have * a length of 16 */ - void setMatrix(float matrix[]); + void setMatrix(double matrix[]); /** * Returns a reference to the array storing the matrix of this node. @@ -97,7 +97,7 @@ public interface NodeModel extends NamedModelElement * * @return The matrix */ - float[] getMatrix(); + double[] getMatrix(); /** * Set the translation of this node to be a reference to the given @@ -107,7 +107,7 @@ public interface NodeModel extends NamedModelElement * @throws IllegalArgumentException If the given array does not have * a length of 3 */ - void setTranslation(float translation[]); + void setTranslation(double translation[]); /** * Returns a reference to the array storing the translation of this @@ -115,7 +115,7 @@ public interface NodeModel extends NamedModelElement * * @return The translation */ - float[] getTranslation(); + double[] getTranslation(); /** * Set the rotation of this node to be a reference to the given @@ -126,7 +126,7 @@ public interface NodeModel extends NamedModelElement * @throws IllegalArgumentException If the given array does not have * a length of 4 */ - void setRotation(float rotation[]); + void setRotation(double rotation[]); /** * Returns a reference to the array storing the rotation of this @@ -134,7 +134,7 @@ public interface NodeModel extends NamedModelElement * * @return The rotation */ - float[] getRotation(); + double[] getRotation(); /** * Set the scale of this node to be a reference to the given @@ -144,7 +144,7 @@ public interface NodeModel extends NamedModelElement * @throws IllegalArgumentException If the given array does not have * a length of 3 */ - void setScale(float scale[]); + void setScale(double scale[]); /** * Returns a reference to the array storing the scale of this @@ -152,7 +152,7 @@ public interface NodeModel extends NamedModelElement * * @return The scale */ - float[] getScale(); + double[] getScale(); /** * Set the morph target weights to be a reference to the given @@ -181,7 +181,7 @@ public interface NodeModel extends NamedModelElement * @param result The result array * @return The result array */ - float[] computeLocalTransform(float result[]); + double[] computeLocalTransform(double result[]); /** * Computes the global transform of this node.
@@ -194,7 +194,7 @@ public interface NodeModel extends NamedModelElement * @param result The result array * @return The result array */ - float[] computeGlobalTransform(float result[]); + double[] computeGlobalTransform(double result[]); /** * Creates a supplier for the global transform matrix of this node @@ -208,7 +208,7 @@ public interface NodeModel extends NamedModelElement * * @return The supplier */ - Supplier createGlobalTransformSupplier(); + Supplier createGlobalTransformSupplier(); /** * Creates a supplier for the local transform matrix of this node model.
@@ -221,6 +221,6 @@ public interface NodeModel extends NamedModelElement * * @return The supplier */ - Supplier createLocalTransformSupplier(); + Supplier createLocalTransformSupplier(); } \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/Optionals.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/Optionals.java index c3e2d342..7da99c55 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/Optionals.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/Optionals.java @@ -131,6 +131,22 @@ public static V get(Object key, Map map) } return map.get(key); } + + /** + * Returns a clone of the given array, or null if the + * given array is null + * + * @param array The array + * @return The result + */ + public static double[] clone(double array[]) + { + if (array == null) + { + return null; + } + return array.clone(); + } /** * Returns a clone of the given array, or null if the diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/SkinModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/SkinModel.java index 324a9f90..e247a492 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/SkinModel.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/SkinModel.java @@ -44,7 +44,7 @@ public interface SkinModel extends NamedModelElement * @param result The result array * @return The result array */ - float[] getBindShapeMatrix(float result[]); + double[] getBindShapeMatrix(double result[]); /** * Returns an unmodifiable list containing the joint nodes of the skeleton @@ -73,14 +73,14 @@ public interface SkinModel extends NamedModelElement * Convenience function to obtain the inverse bind matrix for the joint * with the given index.
*
- * The result will be written to the given array, as a 4x4 matrix in + * The result will be written to the given array, as a 4x4 matrix in * column major order. If the given array is null or does - * not have a length of 16, then a new array with length 16 will be - * created and returned. - * - * @param index The index of the joint + * not have a length of 16, then a new array with length 16 will be + * created and returned. + * + * @param index The index of the joint * @param result The result array * @return The result array */ - float[] getInverseBindMatrix(int index, float result[]); + double[] getInverseBindMatrix(int index, double result[]); } diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/Suppliers.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/Suppliers.java index b9d2e594..99d518c6 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/Suppliers.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/Suppliers.java @@ -35,10 +35,10 @@ public class Suppliers { /** - * Create a supplier of a 4x4 matrix that is computed by applying + * Create a supplier of a 4x4 matrix that is computed by applying * the given computer to the given object and a 16-element array.
*
- * If the given object is null, then the identity + * If the given object is null, then the identity * matrix will be supplied.
*
* Note: The supplier MAY always return the same array instance. @@ -50,10 +50,10 @@ public class Suppliers * @param computer The computer function * @return The supplier */ - public static Supplier createTransformSupplier( - T object, BiConsumer computer) + public static Supplier createTransformSupplier( + T object, BiConsumer computer) { - float transform[] = new float[16]; + double transform[] = new double[16]; if (object == null) { return () -> diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/Utils.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/Utils.java index 2c5f9360..4e2ee87c 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/Utils.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/Utils.java @@ -49,6 +49,24 @@ public static float[] validate(float array[], int length) return new float[length]; } + /** + * Validate that the given array is not null and has the + * given length. If this is not the case, return a new array with the + * specified length. + * + * @param array The array + * @param length The length + * @return The array, or a new array with the desired length + */ + public static double[] validate(double array[], int length) + { + if (array != null && array.length == length) + { + return array; + } + return new double[length]; + } + /** * Private constructor to prevent instantiation */ diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/Cameras.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/Cameras.java index 866b4c40..78d838df 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/Cameras.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/Cameras.java @@ -61,10 +61,10 @@ class Cameras * @param result The array storing the result * @return The result array */ - static float[] computeProjectionMatrix( - CameraModel cameraModel, Float aspectRatio, float result[]) + static double[] computeProjectionMatrix( + CameraModel cameraModel, Float aspectRatio, double result[]) { - float localResult[] = Utils.validate(result, 16); + double localResult[] = Utils.validate(result, 16); CameraPerspectiveModel cameraPerspective = cameraModel.getCameraPerspectiveModel(); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultCameraModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultCameraModel.java index 2ebe121d..c30d9260 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultCameraModel.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultCameraModel.java @@ -93,16 +93,16 @@ public CameraPerspectiveModel getCameraPerspectiveModel() } @Override - public float[] computeProjectionMatrix(float result[], Float aspectRatio) + public double[] computeProjectionMatrix(double result[], Float aspectRatio) { return Cameras.computeProjectionMatrix(this, aspectRatio, result); } @Override - public Supplier createProjectionMatrixSupplier( + public Supplier createProjectionMatrixSupplier( DoubleSupplier aspectRatioSupplier) { - return Suppliers.createTransformSupplier(this, (c, t) -> + return Suppliers.createTransformSupplier(this, (c, t) -> { Float aspectRatio = null; if (aspectRatioSupplier != null) diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNodeModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNodeModel.java index afe1b320..a35aa8ee 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNodeModel.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNodeModel.java @@ -49,14 +49,14 @@ public class DefaultNodeModel extends AbstractNamedModelElement /** * A thread-local, temporary 16-element matrix */ - private static final ThreadLocal TEMP_MATRIX_4x4_IN_LOCAL = - ThreadLocal.withInitial(() -> new float[16]); + private static final ThreadLocal TEMP_MATRIX_4x4_IN_LOCAL = + ThreadLocal.withInitial(() -> new double[16]); /** * A thread-local, temporary 16-element matrix */ - private static final ThreadLocal TEMP_MATRIX_4x4_IN_GLOBAL = - ThreadLocal.withInitial(() -> new float[16]); + private static final ThreadLocal TEMP_MATRIX_4x4_IN_GLOBAL = + ThreadLocal.withInitial(() -> new double[16]); /** * The parent of this node. This is null for the root node. @@ -86,22 +86,22 @@ public class DefaultNodeModel extends AbstractNamedModelElement /** * The local transform matrix */ - private float matrix[]; + private double matrix[]; /** * The translation */ - private float translation[]; + private double translation[]; /** * The rotation */ - private float rotation[]; + private double rotation[]; /** * The scale */ - private float scale[]; + private double scale[]; /** * The weights @@ -222,49 +222,49 @@ public CameraModel getCameraModel() } @Override - public void setMatrix(float[] matrix) + public void setMatrix(double[] matrix) { this.matrix = check(matrix, 16); } @Override - public float[] getMatrix() + public double[] getMatrix() { return matrix; } @Override - public void setTranslation(float[] translation) + public void setTranslation(double[] translation) { this.translation = check(translation, 3); } @Override - public float[] getTranslation() + public double[] getTranslation() { return translation; } @Override - public void setRotation(float[] rotation) + public void setRotation(double[] rotation) { this.rotation = check(rotation, 4); } @Override - public float[] getRotation() + public double[] getRotation() { return rotation; } @Override - public void setScale(float[] scale) + public void setScale(double[] scale) { this.scale = check(scale, 3); } @Override - public float[] getScale() + public double[] getScale() { return scale; } @@ -283,28 +283,28 @@ public float[] getWeights() @Override - public float[] computeLocalTransform(float result[]) + public double[] computeLocalTransform(double result[]) { return computeLocalTransform(this, result); } @Override - public float[] computeGlobalTransform(float result[]) + public double[] computeGlobalTransform(double result[]) { return computeGlobalTransform(this, result); } @Override - public Supplier createGlobalTransformSupplier() + public Supplier createGlobalTransformSupplier() { - return Suppliers.createTransformSupplier(this, + return Suppliers.createTransformSupplier(this, NodeModel::computeGlobalTransform); } @Override - public Supplier createLocalTransformSupplier() + public Supplier createLocalTransformSupplier() { - return Suppliers.createTransformSupplier(this, + return Suppliers.createTransformSupplier(this, NodeModel::computeLocalTransform); } @@ -324,13 +324,13 @@ public Supplier createLocalTransformSupplier() * @param result The result array * @return The result array */ - public static float[] computeLocalTransform( - NodeModel nodeModel, float result[]) + public static double[] computeLocalTransform( + NodeModel nodeModel, double result[]) { - float localResult[] = Utils.validate(result, 16); + double localResult[] = Utils.validate(result, 16); if (nodeModel.getMatrix() != null) { - float m[] = nodeModel.getMatrix(); + double m[] = nodeModel.getMatrix(); System.arraycopy(m, 0, localResult, 0, m.length); return localResult; } @@ -338,22 +338,22 @@ public static float[] computeLocalTransform( MathUtils.setIdentity4x4(localResult); if (nodeModel.getTranslation() != null) { - float t[] = nodeModel.getTranslation(); + double t[] = nodeModel.getTranslation(); localResult[12] = t[0]; localResult[13] = t[1]; localResult[14] = t[2]; } if (nodeModel.getRotation() != null) { - float q[] = nodeModel.getRotation(); - float m[] = TEMP_MATRIX_4x4_IN_LOCAL.get(); + double q[] = nodeModel.getRotation(); + double m[] = TEMP_MATRIX_4x4_IN_LOCAL.get(); MathUtils.quaternionToMatrix4x4(q, m); MathUtils.mul4x4(localResult, m, localResult); } if (nodeModel.getScale() != null) { - float s[] = nodeModel.getScale(); - float m[] = TEMP_MATRIX_4x4_IN_LOCAL.get(); + double s[] = nodeModel.getScale(); + double m[] = TEMP_MATRIX_4x4_IN_LOCAL.get(); MathUtils.setIdentity4x4(m); m[ 0] = s[0]; m[ 5] = s[1]; @@ -374,11 +374,11 @@ public static float[] computeLocalTransform( * @param result The result * @return The result */ - private static float[] computeGlobalTransform( - NodeModel nodeModel, float result[]) + private static double[] computeGlobalTransform( + NodeModel nodeModel, double result[]) { - float localResult[] = Utils.validate(result, 16); - float tempLocalTransform[] = TEMP_MATRIX_4x4_IN_GLOBAL.get(); + double localResult[] = Utils.validate(result, 16); + double tempLocalTransform[] = TEMP_MATRIX_4x4_IN_GLOBAL.get(); NodeModel currentNode = nodeModel; MathUtils.setIdentity4x4(localResult); while (currentNode != null) @@ -404,7 +404,7 @@ private static float[] computeGlobalTransform( * @throws IllegalArgumentException If the given array does not have * the expected length */ - private static float[] check(float array[], int expectedLength) + private static double[] check(double array[], int expectedLength) { if (array == null) { diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultSkinModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultSkinModel.java index cd70cda2..90e14144 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultSkinModel.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultSkinModel.java @@ -48,7 +48,7 @@ public final class DefaultSkinModel extends AbstractNamedModelElement /** * The bind shape matrix */ - private float bindShapeMatrix[]; + private double bindShapeMatrix[]; /** * The joint nodes @@ -81,7 +81,7 @@ public DefaultSkinModel() * will be stored. If it is null, a new array will be * created, which represents the identity matrix. */ - public void setBindShapeMatrix(float[] bindShapeMatrix) + public void setBindShapeMatrix(double[] bindShapeMatrix) { if (bindShapeMatrix == null) { @@ -127,9 +127,9 @@ public void setInverseBindMatrices(AccessorModel inverseBindMatrices) @Override - public float[] getBindShapeMatrix(float[] result) + public double[] getBindShapeMatrix(double[] result) { - float localResult[] = Utils.validate(result, 16); + double localResult[] = Utils.validate(result, 16); System.arraycopy(bindShapeMatrix, 0, localResult, 0, 16); return localResult; } @@ -154,9 +154,9 @@ public AccessorModel getInverseBindMatrices() } @Override - public float[] getInverseBindMatrix(int index, float[] result) + public double[] getInverseBindMatrix(int index, double[] result) { - float localResult[] = Utils.validate(result, 16); + double localResult[] = Utils.validate(result, 16); AccessorFloatData inverseBindMatricesData = AccessorDatas.createFloat(inverseBindMatrices); for (int j = 0; j < 16; j++) diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java index e2e58e17..43a7d0cf 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java @@ -706,10 +706,10 @@ private void initNodeModels() DefaultCameraModel targetCamera = cameraModelsMap.get(sourceCamera); targetNodeModel.setCameraModel(targetCamera); - float matrix[] = sourceNodeModel.getMatrix(); - float translation[] = sourceNodeModel.getTranslation(); - float rotation[] = sourceNodeModel.getRotation(); - float scale[] = sourceNodeModel.getScale(); + double matrix[] = sourceNodeModel.getMatrix(); + double translation[] = sourceNodeModel.getTranslation(); + double rotation[] = sourceNodeModel.getRotation(); + double scale[] = sourceNodeModel.getScale(); float weights[] = sourceNodeModel.getWeights(); targetNodeModel.setMatrix(Optionals.clone(matrix)); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java index dc9f2eee..08280381 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java @@ -473,7 +473,7 @@ private void createSkinModels() for (Entry entry : skins.entrySet()) { Skin skin = entry.getValue(); - float[] bindShapeMatrix = skin.getBindShapeMatrix(); + double[] bindShapeMatrix = skin.getBindShapeMatrix(); DefaultSkinModel skinModel = new DefaultSkinModel(); skinModel.setBindShapeMatrix(bindShapeMatrix); gltfModel.addSkinModel(skinModel); @@ -1007,11 +1007,11 @@ private void initNodeModels() get("cameras", cameraId, gltfModel::getCameraModel); nodeModel.setCameraModel(cameraModel); } - - float matrix[] = node.getMatrix(); - float translation[] = node.getTranslation(); - float rotation[] = node.getRotation(); - float scale[] = node.getScale(); + + double matrix[] = node.getMatrix(); + double translation[] = node.getTranslation(); + double rotation[] = node.getRotation(); + double scale[] = node.getScale(); nodeModel.setMatrix(Optionals.clone(matrix)); nodeModel.setTranslation(Optionals.clone(translation)); nodeModel.setRotation(Optionals.clone(rotation)); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java index b3f89564..1f183047 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java @@ -1083,12 +1083,12 @@ private static Map computeIndexMap( } return indices; } - - + + /** * Returns a new list containing the elements of the given array, * or null if the given array is null - * + * * @param array The array * @return The list */ @@ -1105,4 +1105,26 @@ private static List toList(float array[]) } return list; } + + + /** + * Returns a new list containing the elements of the given array, + * or null if the given array is null + * + * @param array The array + * @return The list + */ + private static List toList(double array[]) + { + if (array == null) + { + return null; + } + List list = new ArrayList(); + for (double f : array) + { + list.add(f); + } + return list; + } } \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java index 6854caa6..231b27fa 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java @@ -905,7 +905,7 @@ private void initMeshModels() createMeshPrimitiveModel(meshPrimitive); meshModel.addMeshPrimitiveModel(meshPrimitiveModel); } - meshModel.setWeights(toArray(mesh.getWeights())); + meshModel.setWeights(toFloatArray(mesh.getWeights())); } } @@ -1011,17 +1011,17 @@ private void initNodeModels() CameraModel cameraModel = gltfModel.getCameraModel(cameraIndex); nodeModel.setCameraModel(cameraModel); } - - float matrix[] = node.getMatrix(); - float translation[] = node.getTranslation(); - float rotation[] = node.getRotation(); - float scale[] = node.getScale(); + + double matrix[] = node.getMatrix(); + double translation[] = node.getTranslation(); + double rotation[] = node.getRotation(); + double scale[] = node.getScale(); nodeModel.setMatrix(Optionals.clone(matrix)); nodeModel.setTranslation(Optionals.clone(translation)); nodeModel.setRotation(Optionals.clone(rotation)); nodeModel.setScale(Optionals.clone(scale)); - nodeModel.setWeights(toArray(node.getWeights())); + nodeModel.setWeights(toFloatArray(node.getWeights())); } } @@ -1336,11 +1336,11 @@ private static void transferGltfChildOfRootPropertyElements( /** * Returns an array containing the float representations of the given * numbers, or null if the given list is null. - * + * * @param numbers The numbers * @return The array */ - private static float[] toArray(List numbers) + private static float[] toFloatArray(List numbers) { if (numbers == null) { @@ -1353,4 +1353,25 @@ private static float[] toArray(List numbers) } return array; } + + /** + * Returns an array containing the float representations of the given + * numbers, or null if the given list is null. + * + * @param numbers The numbers + * @return The array + */ + private static double[] toDoubleArray(List numbers) + { + if (numbers == null) + { + return null; + } + double array[] = new double[numbers.size()]; + for (int j = 0; j < numbers.size(); j++) + { + array[j] = numbers.get(j).doubleValue(); + } + return array; + } } diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/AbstractGltfViewer.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/AbstractGltfViewer.java index f5bb52e0..7cacd0b4 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/AbstractGltfViewer.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/AbstractGltfViewer.java @@ -64,12 +64,12 @@ public abstract class AbstractGltfViewer implements GltfViewer * {@link RenderedGltfModel} constructor, and eventually provide the data * for the uniforms that have the VIEWPORT semantic. */ - private final Supplier viewportSupplier = new Supplier() + private final Supplier viewportSupplier = new Supplier() { - private final float viewport[] = new float[4]; + private final double viewport[] = new double[4]; @Override - public float[] get() + public double[] get() { viewport[0] = 0; viewport[1] = 0; diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/CesiumRtcUtils.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/CesiumRtcUtils.java index 8562a2ab..3d55c65e 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/CesiumRtcUtils.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/CesiumRtcUtils.java @@ -77,11 +77,11 @@ static boolean isCesiumRtcModelViewSemantic(String semanticString) * @param rtcCenter The RTC center * @return The supplier */ - static Supplier createCesiumRtcModelViewMatrixSupplier( - NodeModel nodeModel, Supplier viewMatrixSupplier, - float rtcCenter[]) + static Supplier createCesiumRtcModelViewMatrixSupplier( + NodeModel nodeModel, Supplier viewMatrixSupplier, + double rtcCenter[]) { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4() @@ -102,7 +102,7 @@ static Supplier createCesiumRtcModelViewMatrixSupplier( * @param gltfModel The {@link GltfModel} * @return The RTC center */ - static float[] extractRtcCenterFromModel(GltfModel gltfModel) + static double[] extractRtcCenterFromModel(GltfModel gltfModel) { Map extensions = gltfModel.getExtensions(); if (extensions == null) @@ -121,7 +121,7 @@ static float[] extractRtcCenterFromModel(GltfModel gltfModel) * @param extensionObject The extension object * @return The RTC center */ - private static float[] extractRtcCenterFromExtensionObbject( + private static double[] extractRtcCenterFromExtensionObbject( Object extensionObject) { // NOTE: This is very pragmatic and involves some manual fiddling. @@ -156,7 +156,7 @@ private static float[] extractRtcCenterFromExtensionObbject( + "have size 3, but has " + list.size()); return null; } - float result[] = new float[3]; + double result[] = new double[3]; for (int i = 0; i < list.size(); i++) { Object value = list.get(i); @@ -168,7 +168,7 @@ private static float[] extractRtcCenterFromExtensionObbject( return null; } Number number = (Number) value; - result[i] = number.floatValue(); + result[i] = number.doubleValue(); } return result; } diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedCamera.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedCamera.java index 4721333c..7b1a7c7c 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedCamera.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedCamera.java @@ -52,12 +52,12 @@ public class DefaultRenderedCamera implements RenderedCamera /** * The view matrix */ - private final float viewMatrix[]; + private final double viewMatrix[]; /** * The projection matrix */ - private final float projectionMatrix[]; + private final double projectionMatrix[]; /** * An optional supplier for the aspect ratio. If this is null, @@ -89,12 +89,12 @@ public class DefaultRenderedCamera implements RenderedCamera cameraModel, "The cameraModel may not be null"); this.aspectRatioSupplier = aspectRatioSupplier; - this.viewMatrix = new float[16]; - this.projectionMatrix = new float[16]; + this.viewMatrix = new double[16]; + this.projectionMatrix = new double[16]; } @Override - public float[] getViewMatrix() + public double[] getViewMatrix() { nodeModel.computeGlobalTransform(viewMatrix); MathUtils.invert4x4(viewMatrix, viewMatrix); @@ -102,7 +102,7 @@ public float[] getViewMatrix() } @Override - public float[] getProjectionMatrix() + public double[] getProjectionMatrix() { Float aspectRatio = null; if (aspectRatioSupplier != null) diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java index d7bb90ae..e3efe264 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java @@ -147,7 +147,7 @@ public DefaultRenderedGltfModel( Objects.requireNonNull(viewConfiguration, "The viewConfiguration may not be null"); - float rtcCenter[] = CesiumRtcUtils.extractRtcCenterFromModel(gltfModel); + double rtcCenter[] = CesiumRtcUtils.extractRtcCenterFromModel(gltfModel); if (rtcCenter != null) { // NOTE: The RTC center is not really APPLIED here during diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MatrixOps.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MatrixOps.java index d7578ac3..f434af6e 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MatrixOps.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MatrixOps.java @@ -56,7 +56,7 @@ class MatrixOps /** * The supplier that provides the input matrix */ - private final Supplier inputSupplier; + private final Supplier inputSupplier; /** * The chain of functions that will be applied. Starting with the @@ -65,7 +65,7 @@ class MatrixOps * The result of the final function will be returned by the * supplier that is created with {@link #build()}. */ - private final List> functions; + private final List> functions; /** * Create a builder for matrix operations that obtains its initial @@ -74,7 +74,7 @@ class MatrixOps * @param inputSupplier The input matrix supplier * @return The builder */ - static MatrixOps create4x4(Supplier inputSupplier) + static MatrixOps create4x4(Supplier inputSupplier) { return new MatrixOps(inputSupplier); } @@ -95,9 +95,9 @@ static MatrixOps create4x4() * * @return The supplier */ - private static Supplier createIdentitySupplier4x4() + private static Supplier createIdentitySupplier4x4() { - float matrix[] = new float[16]; + double matrix[] = new double[16]; return () -> { MathUtils.setIdentity4x4(matrix); @@ -110,10 +110,10 @@ private static Supplier createIdentitySupplier4x4() * * @param inputSupplier The supplier of the input matrix */ - private MatrixOps(Supplier inputSupplier) + private MatrixOps(Supplier inputSupplier) { this.inputSupplier = inputSupplier; - this.functions = new ArrayList>(); + this.functions = new ArrayList>(); } /** @@ -123,9 +123,9 @@ private MatrixOps(Supplier inputSupplier) * @param operandSupplier The supplier of the operand * @return This builder */ - MatrixOps multiply4x4(Supplier operandSupplier) + MatrixOps multiply4x4(Supplier operandSupplier) { - float result[] = new float[16]; + double result[] = new double[16]; functions.add(named("multiply4x4", input -> { MathUtils.mul4x4(input, operandSupplier.get(), result); @@ -141,7 +141,7 @@ MatrixOps multiply4x4(Supplier operandSupplier) */ MatrixOps invert4x4() { - float result[] = new float[16]; + double result[] = new double[16]; functions.add(named("invert4x4", input -> { MathUtils.invert4x4(input, result); @@ -157,7 +157,7 @@ MatrixOps invert4x4() */ MatrixOps invert3x3() { - float result[] = new float[9]; + double result[] = new double[9]; functions.add(named("invert3x4", input -> { MathUtils.invert3x3(input, result); @@ -173,7 +173,7 @@ MatrixOps invert3x3() */ MatrixOps transpose4x4() { - float result[] = new float[16]; + double result[] = new double[16]; functions.add(named("transpose4x4", input -> { MathUtils.transpose4x4(input, result); @@ -190,7 +190,7 @@ MatrixOps transpose4x4() */ MatrixOps getRotationScale() { - float result[] = new float[9]; + double result[] = new double[9]; functions.add(named("getRotationScale", input -> { MathUtils.getRotationScale(input, result); @@ -207,9 +207,9 @@ MatrixOps getRotationScale() * @param z The z-translation * @return This builder */ - MatrixOps translate(float x, float y, float z) + MatrixOps translate(double x, double y, double z) { - float result[] = new float[16]; + double result[] = new double[16]; functions.add(named("translate", input -> { MathUtils.translate(input, x, y, z, result); @@ -275,12 +275,12 @@ public String toString() * * @return The supplier */ - Supplier build() + Supplier build() { return () -> { - float current[] = inputSupplier.get(); - for (Function function : functions) + double current[] = inputSupplier.get(); + for (Function function : functions) { current = function.apply(current); if (logger.isLoggable(Level.FINEST)) diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedCamera.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedCamera.java index f1d030be..0e4eef39 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedCamera.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedCamera.java @@ -32,15 +32,15 @@ public interface RenderedCamera { /** - * The view matrix of this camera, as a float array with 16 elements, + * The view matrix of this camera, as a float array with 16 elements, * representing the 4x4 matrix in column-major order.
*
* The returned matrix will not be stored or modified. So the supplier * may always return the same matrix instance. - * + * * @return The view matrix */ - float[] getViewMatrix(); + double[] getViewMatrix(); /** * The projection matrix of this camera, as a float array with 16 elements, @@ -48,8 +48,8 @@ public interface RenderedCamera *
* The returned matrix will not be stored or modified. So the supplier * may always return the same matrix instance. - * + * * @return The projection matrix */ - float[] getProjectionMatrix(); + double[] getProjectionMatrix(); } \ No newline at end of file diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/UniformGetterFactory.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/UniformGetterFactory.java index 6fddaef0..5a6cefdf 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/UniformGetterFactory.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/UniformGetterFactory.java @@ -57,18 +57,18 @@ class UniformGetterFactory /** * A supplier for the view matrix. */ - private final Supplier viewMatrixSupplier; + private final Supplier viewMatrixSupplier; /** * A supplier for the projection matrix. */ - private final Supplier projectionMatrixSupplier; + private final Supplier projectionMatrixSupplier; /** * A supplier that supplies the viewport, as 4 float elements, * [x, y, width, height] */ - private final Supplier viewportSupplier; + private final Supplier viewportSupplier; /** * The set of uniform names for which a null value @@ -79,7 +79,7 @@ class UniformGetterFactory /** * The RTC center point for the CESIUM_RTC extension */ - private float rtcCenter[]; + private double rtcCenter[]; /** * Creates a new instance @@ -95,10 +95,10 @@ class UniformGetterFactory * extension */ public UniformGetterFactory( - Supplier viewportSupplier, - Supplier viewMatrixSupplier, - Supplier projectionMatrixSupplier, - float rtcCenter[]) + Supplier viewportSupplier, + Supplier viewMatrixSupplier, + Supplier projectionMatrixSupplier, + double rtcCenter[]) { this.viewportSupplier = Objects.requireNonNull(viewportSupplier, "The viewportSupplier may not be null"); @@ -107,7 +107,7 @@ public UniformGetterFactory( this.projectionMatrixSupplier = Objects.requireNonNull(projectionMatrixSupplier, "The projectionMatrixSupplier may not be null"); - this.rtcCenter = rtcCenter == null ? new float[3] : rtcCenter.clone(); + this.rtcCenter = rtcCenter == null ? new double[3] : rtcCenter.clone(); this.reportedNullUniformNames = new LinkedHashSet(); } @@ -233,7 +233,7 @@ private Supplier createNullLoggingSupplier( * * * The actual contents of these joint matrices is computed from the - * {@link SkinModel#getBindShapeMatrix(float[]) bind shape matrix}, the + * {@link SkinModel#getBindShapeMatrix(double[]) bind shape matrix}, the * {@link SkinModel#getInverseBindMatrices() inverse bind matrices} and * the global transform of the given node and the joint node. See the glTF * specification for details.
@@ -308,7 +308,7 @@ private Supplier createSemanticBasedSupplier( case MODELVIEW: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(viewMatrixSupplier) @@ -319,7 +319,7 @@ private Supplier createSemanticBasedSupplier( case MODELVIEWPROJECTION: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(projectionMatrixSupplier) @@ -331,7 +331,7 @@ private Supplier createSemanticBasedSupplier( case MODELINVERSE: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(modelMatrixSupplier) @@ -351,7 +351,7 @@ private Supplier createSemanticBasedSupplier( case MODELVIEWINVERSE: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(viewMatrixSupplier) @@ -372,7 +372,7 @@ private Supplier createSemanticBasedSupplier( case MODELVIEWPROJECTIONINVERSE: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(projectionMatrixSupplier) @@ -385,7 +385,7 @@ private Supplier createSemanticBasedSupplier( case MODELINVERSETRANSPOSE: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(modelMatrixSupplier) @@ -398,7 +398,7 @@ private Supplier createSemanticBasedSupplier( case MODELVIEWINVERSETRANSPOSE: { - Supplier modelMatrixSupplier = + Supplier modelMatrixSupplier = nodeModel.createGlobalTransformSupplier(); return MatrixOps .create4x4(viewMatrixSupplier) @@ -435,15 +435,15 @@ private Supplier createSemanticBasedSupplier( * @param nodeModel The {@link NodeModel} * @return The supplier */ - private static Supplier createJointMatrixSupplier( + private static Supplier createJointMatrixSupplier( NodeModel nodeModel) { SkinModel skinModel = nodeModel.getSkinModel(); // Create the supplier for the bind shape matrix (or a supplier // of the identity matrix, if the bind shape matrix is null) - float bindShapeMatrix[] = skinModel.getBindShapeMatrix(null); - Supplier bindShapeMatrixSupplier = + double bindShapeMatrix[] = skinModel.getBindShapeMatrix(null); + Supplier bindShapeMatrixSupplier = MatrixOps.create4x4(() -> bindShapeMatrix) .log("bindShapeMatrix", Level.FINE) .build(); @@ -454,18 +454,18 @@ private static Supplier createJointMatrixSupplier( // Create one supplier for each inverse bind matrix. Each of them will // extract one element of the inverse bind matrix accessor data and // provide it as a single float[16] array, representing a 4x4 matrix - List> inverseBindMatrixSuppliers = - new ArrayList>(); + List> inverseBindMatrixSuppliers = + new ArrayList>(); for (int i = 0; i < numJoints; i++) { final int currentJointIndex = i; - float inverseBindMatrix[] = new float[16]; - Supplier inverseBindMatrixSupplier = () -> + double inverseBindMatrix[] = new double[16]; + Supplier inverseBindMatrixSupplier = () -> { return skinModel.getInverseBindMatrix( currentJointIndex, inverseBindMatrix); }; - Supplier loggingInverseBindMatrixSupplier = + Supplier loggingInverseBindMatrixSupplier = MatrixOps.create4x4(inverseBindMatrixSupplier) .log("inverseBindMatrix "+i, Level.FINE) .build(); @@ -479,16 +479,16 @@ private static Supplier createJointMatrixSupplier( // [globalTransformOfJointNode] * // [inverseBindMatrix(j)] * // [bindShapeMatrix] - List> jointMatrixSuppliers = - new ArrayList>(); + List> jointMatrixSuppliers = + new ArrayList>(); for (int j = 0; j < numJoints; j++) { NodeModel jointNodeModel = joints.get(j); - Supplier inverseBindMatrixSupplier = + Supplier inverseBindMatrixSupplier = inverseBindMatrixSuppliers.get(j); - Supplier jointMatrixSupplier = MatrixOps + Supplier jointMatrixSupplier = MatrixOps .create4x4(nodeModel.createGlobalTransformSupplier()) .invert4x4() .multiply4x4(jointNodeModel.createGlobalTransformSupplier()) @@ -502,14 +502,14 @@ private static Supplier createJointMatrixSupplier( // Create a supplier for the joint matrices, which combines the // joint matrices of the individual joint matrix suppliers // into one array - float jointMatrices[] = new float[jointMatrixSuppliers.size() * 16]; + double jointMatrices[] = new double[jointMatrixSuppliers.size() * 16]; return () -> { for (int i=0; i jointMatrixSupplier = + Supplier jointMatrixSupplier = jointMatrixSuppliers.get(i); - float[] jointMatrix = jointMatrixSupplier.get(); + double[] jointMatrix = jointMatrixSupplier.get(); System.arraycopy(jointMatrix, 0, jointMatrices, i * 16, 16); } return jointMatrices; diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/ViewConfiguration.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/ViewConfiguration.java index 1f9656b9..d76e543c 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/ViewConfiguration.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/ViewConfiguration.java @@ -47,17 +47,17 @@ final class ViewConfiguration /** * The supplier for the viewport, as an array [x, y, width, height] */ - private final Supplier viewportSupplier; + private final Supplier viewportSupplier; /** * The supplier for the view matrix */ - private final Supplier viewMatrixSupplier; + private final Supplier viewMatrixSupplier; /** * The supplier for the projection matrix */ - private final Supplier projectionMatrixSupplier; + private final Supplier projectionMatrixSupplier; /** * Creates a new view configuration @@ -66,7 +66,7 @@ final class ViewConfiguration * as 4 float elements, [x, y, width, height] */ ViewConfiguration( - Supplier viewportSupplier) + Supplier viewportSupplier) { this.viewportSupplier = Objects.requireNonNull( viewportSupplier, "The viewportSupplier may not be null"); @@ -116,9 +116,9 @@ public RenderedCamera getRenderedCamera() * * @return The view matrix supplier */ - private Supplier createViewMatrixSupplier() + private Supplier createViewMatrixSupplier() { - float defaultViewMatrix[] = MathUtils.createIdentity4x4(); + double defaultViewMatrix[] = MathUtils.createIdentity4x4(); return () -> { if (renderedCamera == null) @@ -150,9 +150,9 @@ private Supplier createViewMatrixSupplier() * * @return The projection matrix supplier */ - private Supplier createProjectionMatrixSupplier() + private Supplier createProjectionMatrixSupplier() { - float defaultProjectionMatrix[] = MathUtils.createIdentity4x4(); + double defaultProjectionMatrix[] = MathUtils.createIdentity4x4(); return () -> { if (renderedCamera == null) @@ -170,7 +170,7 @@ private Supplier createProjectionMatrixSupplier() * * @return The viewport */ - public float[] getViewport() + public double[] getViewport() { return viewportSupplier.get(); } @@ -184,7 +184,7 @@ public float[] getViewport() * * @return The view matrix */ - public float[] getViewMatrix() + public double[] getViewMatrix() { return viewMatrixSupplier.get(); } @@ -198,7 +198,7 @@ public float[] getViewMatrix() * * @return The view matrix */ - public float[] getProjectionMatrix() + public double[] getProjectionMatrix() { return projectionMatrixSupplier.get(); } From 835dc12ba752d1ddb1cb1ef779bda4035383150e Mon Sep 17 00:00:00 2001 From: m4ndeokyi Date: Fri, 17 Jan 2025 14:19:38 +0300 Subject: [PATCH 2/3] Change bounding box floating-point precision to double --- .../de/javagl/jgltf/model/BoundingBox.java | 48 +++++++++---------- .../de/javagl/jgltf/model/BoundingBoxes.java | 6 +-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBox.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBox.java index 20934157..b231acf7 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBox.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBox.java @@ -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; } /** @@ -114,7 +114,7 @@ void combine(BoundingBox other) * * @return The x-coordinate of the center */ - float getCenterX() + double getCenterX() { return getMinX() + getSizeX() * 0.5f; } @@ -124,7 +124,7 @@ float getCenterX() * * @return The y-coordinate of the center */ - float getCenterY() + double getCenterY() { return getMinY() + getSizeY() * 0.5f; } @@ -134,7 +134,7 @@ float getCenterY() * * @return The z-coordinate of the center */ - float getCenterZ() + double getCenterZ() { return getMinZ() + getSizeZ() * 0.5f; } @@ -144,7 +144,7 @@ float getCenterZ() * * @return The size in x-direction */ - float getSizeX() + double getSizeX() { return getMaxX() - getMinX(); } @@ -154,7 +154,7 @@ float getSizeX() * * @return The size in y-direction */ - float getSizeY() + double getSizeY() { return getMaxY() - getMinY(); } @@ -164,7 +164,7 @@ float getSizeY() * * @return The size in z-direction */ - float getSizeZ() + double getSizeZ() { return getMaxZ() - getMinZ(); } @@ -174,7 +174,7 @@ float getSizeZ() * * @return The minimum x coordinate */ - float getMinX() + double getMinX() { return minX; } @@ -184,7 +184,7 @@ float getMinX() * * @return The minimum y coordinate */ - float getMinY() + double getMinY() { return minY; } @@ -194,7 +194,7 @@ float getMinY() * * @return The minimum z coordinate */ - float getMinZ() + double getMinZ() { return minZ; } @@ -204,7 +204,7 @@ float getMinZ() * * @return The maximum x coordinate */ - float getMaxX() + double getMaxX() { return maxX; } @@ -214,7 +214,7 @@ float getMaxX() * * @return The maximum y coordinate */ - float getMaxY() + double getMaxY() { return maxY; } @@ -224,7 +224,7 @@ float getMaxY() * * @return The maximum z coordinate */ - float getMaxZ() + double getMaxZ() { return maxZ; } diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxes.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxes.java index ac22953d..a06a4ec5 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxes.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/BoundingBoxes.java @@ -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(), From c23747172078929b931c1d31b610ff7a2da1f70a Mon Sep 17 00:00:00 2001 From: m4ndeokyi Date: Fri, 17 Jan 2025 14:31:03 +0300 Subject: [PATCH 3/3] Remove unnecessary double floating-point static methods --- .../javagl/jgltf/model/v2/GltfCreatorV2.java | 22 --------------- .../jgltf/model/v2/GltfModelCreatorV2.java | 27 +++---------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java index 1f183047..cd7dabc7 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java @@ -1105,26 +1105,4 @@ private static List toList(float array[]) } return list; } - - - /** - * Returns a new list containing the elements of the given array, - * or null if the given array is null - * - * @param array The array - * @return The list - */ - private static List toList(double array[]) - { - if (array == null) - { - return null; - } - List list = new ArrayList(); - for (double f : array) - { - list.add(f); - } - return list; - } } \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java index 231b27fa..85f0879d 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java @@ -905,7 +905,7 @@ private void initMeshModels() createMeshPrimitiveModel(meshPrimitive); meshModel.addMeshPrimitiveModel(meshPrimitiveModel); } - meshModel.setWeights(toFloatArray(mesh.getWeights())); + meshModel.setWeights(toArray(mesh.getWeights())); } } @@ -1021,7 +1021,7 @@ private void initNodeModels() nodeModel.setRotation(Optionals.clone(rotation)); nodeModel.setScale(Optionals.clone(scale)); - nodeModel.setWeights(toFloatArray(node.getWeights())); + nodeModel.setWeights(toArray(node.getWeights())); } } @@ -1340,7 +1340,7 @@ private static void transferGltfChildOfRootPropertyElements( * @param numbers The numbers * @return The array */ - private static float[] toFloatArray(List numbers) + private static float[] toArray(List numbers) { if (numbers == null) { @@ -1353,25 +1353,4 @@ private static float[] toFloatArray(List numbers) } return array; } - - /** - * Returns an array containing the float representations of the given - * numbers, or null if the given list is null. - * - * @param numbers The numbers - * @return The array - */ - private static double[] toDoubleArray(List numbers) - { - if (numbers == null) - { - return null; - } - double array[] = new double[numbers.size()]; - for (int j = 0; j < numbers.size(); j++) - { - array[j] = numbers.get(j).doubleValue(); - } - return array; - } }