1+ /*
2+ * Copyright (c) 2009-2025 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+ */
132package com .jme3 .scene .mesh ;
233
3- import com .jme3 .export .*;
34+ import com .jme3 .export .InputCapsule ;
35+ import com .jme3 .export .JmeExporter ;
36+ import com .jme3 .export .JmeImporter ;
37+ import com .jme3 .export .OutputCapsule ;
38+ import com .jme3 .export .Savable ;
439import com .jme3 .scene .VertexBuffer ;
540
641import java .io .IOException ;
7- import java .nio .Buffer ;
842import java .nio .FloatBuffer ;
943import java .util .EnumMap ;
1044import java .util .Map ;
1145
46+ /**
47+ * `MorphTarget` represents a single morph target within a `Mesh`.
48+ * A morph target contains a set of `FloatBuffer` instances, each corresponding
49+ * to a `VertexBuffer.Type` (e.g., `POSITION`, `NORMAL`, `TANGENT`).
50+ * These buffers store the delta (difference) values that, when added to the
51+ * base mesh's corresponding vertex buffers, create a deformed version of the mesh.
52+ * <p>
53+ * Morph targets are primarily used for skeletal animation blending, facial animation,
54+ * or other mesh deformation effects. Each `MorphTarget` can optionally have a name
55+ * for identification and control.
56+ */
1257public class MorphTarget implements Savable {
58+
59+ /**
60+ * Stores the `FloatBuffer` instances for each `VertexBuffer.Type` that
61+ * this morph target affects.
62+ */
1363 private final EnumMap <VertexBuffer .Type , FloatBuffer > buffers = new EnumMap <>(VertexBuffer .Type .class );
14- private String name = null ;
15-
64+ /**
65+ * An optional name for this morph target, useful for identification
66+ * and targeting in animations.
67+ */
68+ private String name ;
69+
70+ /**
71+ * Required for jME deserialization.
72+ */
1673 public MorphTarget () {
17-
1874 }
19-
75+
76+ /**
77+ * Creates a new `MorphTarget` with the specified name.
78+ *
79+ * @param name The name of this morph target (can be null).
80+ */
2081 public MorphTarget (String name ) {
2182 this .name = name ;
2283 }
23-
84+
85+ /**
86+ * Sets the name of this morph target.
87+ *
88+ * @param name The new name for this morph target (can be null).
89+ */
2490 public void setName (String name ) {
2591 this .name = name ;
2692 }
27-
93+
94+ /**
95+ * Returns the name of this morph target.
96+ *
97+ * @return The name of this morph target, or null if not set.
98+ */
2899 public String getName () {
29100 return name ;
30101 }
31102
103+ /**
104+ * Associates a `FloatBuffer` with a specific `VertexBuffer.Type` for this morph target.
105+ * This buffer typically contains the delta values for the specified vertex attribute.
106+ *
107+ * @param type The type of vertex buffer (e.g., `POSITION`, `NORMAL`).
108+ * @param buffer The `FloatBuffer` containing the delta data for the given type.
109+ */
32110 public void setBuffer (VertexBuffer .Type type , FloatBuffer buffer ) {
33111 buffers .put (type , buffer );
34112 }
35113
114+ /**
115+ * Retrieves the `FloatBuffer` associated with a specific `VertexBuffer.Type` for this morph target.
116+ *
117+ * @param type The type of vertex buffer.
118+ * @return The `FloatBuffer` for the given type, or null if not set.
119+ */
36120 public FloatBuffer getBuffer (VertexBuffer .Type type ) {
37121 return buffers .get (type );
38122 }
39123
124+ /**
125+ * Returns the `EnumMap` containing all the `FloatBuffer` instances
126+ * associated with their `VertexBuffer.Type` for this morph target.
127+ *
128+ * @return An `EnumMap` of vertex buffer types to their corresponding `FloatBuffer`s.
129+ */
40130 public EnumMap <VertexBuffer .Type , FloatBuffer > getBuffers () {
41131 return buffers ;
42132 }
43133
134+ /**
135+ * Returns the number of `FloatBuffer`s (i.e., vertex attribute types)
136+ * contained within this morph target.
137+ *
138+ * @return The count of buffers in this morph target.
139+ */
44140 public int getNumBuffers () {
45141 return buffers .size ();
46142 }
@@ -49,8 +145,9 @@ public int getNumBuffers() {
49145 public void write (JmeExporter ex ) throws IOException {
50146 OutputCapsule oc = ex .getCapsule (this );
51147 for (Map .Entry <VertexBuffer .Type , FloatBuffer > entry : buffers .entrySet ()) {
52- Buffer roData = entry .getValue ().asReadOnlyBuffer ();
53- oc .write ((FloatBuffer ) roData , entry .getKey ().name (),null );
148+ VertexBuffer .Type type = entry .getKey ();
149+ FloatBuffer roData = entry .getValue ().asReadOnlyBuffer ();
150+ oc .write (roData , type .name (), null );
54151 }
55152 oc .write (name , "morphName" , null );
56153 }
@@ -59,9 +156,9 @@ public void write(JmeExporter ex) throws IOException {
59156 public void read (JmeImporter im ) throws IOException {
60157 InputCapsule ic = im .getCapsule (this );
61158 for (VertexBuffer .Type type : VertexBuffer .Type .values ()) {
62- FloatBuffer b = ic .readFloatBuffer (type .name (), null );
63- if ( b != null ){
64- setBuffer (type , b );
159+ FloatBuffer fb = ic .readFloatBuffer (type .name (), null );
160+ if ( fb != null ) {
161+ setBuffer (type , fb );
65162 }
66163 }
67164 name = ic .readString ("morphName" , null );
0 commit comments