|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 jMonkeyEngine |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are |
| 7 | + * met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | +package jme3test.animation; |
| 33 | + |
| 34 | +import com.jme3.anim.SkinningControl; |
| 35 | +import com.jme3.anim.util.AnimMigrationUtils; |
| 36 | +import com.jme3.animation.SkeletonControl; |
| 37 | +import com.jme3.app.SimpleApplication; |
| 38 | +import com.jme3.light.AmbientLight; |
| 39 | +import com.jme3.math.ColorRGBA; |
| 40 | +import com.jme3.scene.Geometry; |
| 41 | +import com.jme3.scene.Mesh; |
| 42 | +import com.jme3.scene.Node; |
| 43 | +import com.jme3.scene.VertexBuffer; |
| 44 | + |
| 45 | +/** |
| 46 | + * Test for JMonkeyEngine issue #2076: software skinning requires vertex |
| 47 | + * normals. |
| 48 | + * |
| 49 | + * <p>If the issue is resolved, 2 copies of the Jaime model will be rendered. |
| 50 | + * |
| 51 | + * <p>If the issue is present, then the application will immediately crash, |
| 52 | + * typically with a {@code NullPointerException}. |
| 53 | + * |
| 54 | + * @author Stephen Gold |
| 55 | + */ |
| 56 | +public class TestIssue2076 extends SimpleApplication { |
| 57 | + /** |
| 58 | + * Main entry point for the TestIssue2076 application. |
| 59 | + * |
| 60 | + * @param args array of command-line arguments (not null) |
| 61 | + */ |
| 62 | + public static void main(String... argv) { |
| 63 | + TestIssue2076 app = new TestIssue2076(); |
| 64 | + app.start(); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Initialize this application. |
| 69 | + */ |
| 70 | + @Override |
| 71 | + public void simpleInitApp() { |
| 72 | + AmbientLight ambientLight = new AmbientLight(); |
| 73 | + ambientLight.setColor(new ColorRGBA(1f, 1f, 1f, 1f)); |
| 74 | + rootNode.addLight(ambientLight); |
| 75 | + /* |
| 76 | + * The original Jaime model was chosen for testing because it includes |
| 77 | + * tangent buffers (needed to trigger issue #2076) and uses the old |
| 78 | + * animation system (so it can be easily used to test both systems). |
| 79 | + */ |
| 80 | + String assetPath = "Models/Jaime/Jaime.j3o"; |
| 81 | + |
| 82 | + testOldAnimationSystem(assetPath); |
| 83 | + testNewAnimationSystem(assetPath); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Attach the specified model (which uses the old animation system) to the |
| 88 | + * scene graph, enable software skinning, and remove its vertex normals. |
| 89 | + * |
| 90 | + * @param assetPath the asset path of the test model (not null) |
| 91 | + */ |
| 92 | + private void testOldAnimationSystem(String assetPath) { |
| 93 | + Node oldJaime = (Node) assetManager.loadModel(assetPath); |
| 94 | + rootNode.attachChild(oldJaime); |
| 95 | + oldJaime.setLocalTranslation(-1f, 0f, 0f); |
| 96 | + |
| 97 | + // enable software skinning: |
| 98 | + SkeletonControl skeletonControl |
| 99 | + = oldJaime.getControl(SkeletonControl.class); |
| 100 | + skeletonControl.setHardwareSkinningPreferred(false); |
| 101 | + |
| 102 | + // remove its vertex normals: |
| 103 | + Geometry oldGeometry = (Geometry) oldJaime.getChild(0); |
| 104 | + Mesh oldMesh = oldGeometry.getMesh(); |
| 105 | + oldMesh.clearBuffer(VertexBuffer.Type.Normal); |
| 106 | + oldMesh.clearBuffer(VertexBuffer.Type.BindPoseNormal); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Attach the specified model, converted to the new animation system, to the |
| 111 | + * scene graph, enable software skinning, and remove its vertex normals. |
| 112 | + * |
| 113 | + * @param assetPath the asset path of the test model (not null) |
| 114 | + */ |
| 115 | + private void testNewAnimationSystem(String assetPath) { |
| 116 | + Node newJaime = (Node) assetManager.loadModel(assetPath); |
| 117 | + AnimMigrationUtils.migrate(newJaime); |
| 118 | + rootNode.attachChild(newJaime); |
| 119 | + newJaime.setLocalTranslation(1f, 0f, 0f); |
| 120 | + |
| 121 | + // enable software skinning: |
| 122 | + SkinningControl skinningControl |
| 123 | + = newJaime.getControl(SkinningControl.class); |
| 124 | + skinningControl.setHardwareSkinningPreferred(false); |
| 125 | + |
| 126 | + // remove its vertex normals: |
| 127 | + Geometry newGeometry = (Geometry) newJaime.getChild(0); |
| 128 | + Mesh newMesh = newGeometry.getMesh(); |
| 129 | + newMesh.clearBuffer(VertexBuffer.Type.Normal); |
| 130 | + newMesh.clearBuffer(VertexBuffer.Type.BindPoseNormal); |
| 131 | + } |
| 132 | +} |
0 commit comments