11/*
2- * Copyright (c) 2009-2023 jMonkeyEngine
2+ * Copyright (c) 2009-2025 jMonkeyEngine
33 * All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
5757 /**
5858 * Type of buffer. Specifies the actual attribute it defines.
5959 */
60- public static enum Type {
60+ public enum Type {
6161 /**
6262 * Position of the vertex (3 floats)
6363 */
@@ -233,7 +233,7 @@ public static enum Type {
233233 * is used. This can determine if a vertex buffer is placed in VRAM
234234 * or held in video memory, but no guarantees are made- it's only a hint.
235235 */
236- public static enum Usage {
236+ public enum Usage {
237237 /**
238238 * Mesh data is sent once and very rarely updated.
239239 */
@@ -261,7 +261,7 @@ public static enum Usage {
261261 * For the {@link Format#Half} type, {@link ByteBuffer}s should
262262 * be used.
263263 */
264- public static enum Format {
264+ public enum Format {
265265 /**
266266 * Half precision floating point. 2 bytes, signed.
267267 */
@@ -1130,6 +1130,7 @@ public void write(JmeExporter ex) throws IOException {
11301130 oc .write (offset , "offset" , 0 );
11311131 oc .write (stride , "stride" , 0 );
11321132 oc .write (instanceSpan , "instanceSpan" , 0 );
1133+ oc .write (name , "name" , null );
11331134
11341135 String dataName = "data" + format .name ();
11351136 Buffer roData = getDataReadOnly ();
@@ -1166,6 +1167,8 @@ public void read(JmeImporter im) throws IOException {
11661167 offset = ic .readInt ("offset" , 0 );
11671168 stride = ic .readInt ("stride" , 0 );
11681169 instanceSpan = ic .readInt ("instanceSpan" , 0 );
1170+ name = ic .readString ("name" , null );
1171+
11691172 componentsLength = components * format .getComponentSize ();
11701173
11711174 String dataName = "data" + format .name ();
@@ -1191,14 +1194,28 @@ public void read(JmeImporter im) throws IOException {
11911194 }
11921195 }
11931196
1197+ /**
1198+ * Returns the name of this `VertexBuffer`. If no name has been explicitly
1199+ * set, a default name is generated based on its class name and buffer type
1200+ * (e.g., "VertexBuffer(Position)").
1201+ *
1202+ * @return The name of the `VertexBuffer`.
1203+ */
11941204 public String getName () {
11951205 if (name == null ) {
1196- name = getClass ().getSimpleName () + "(" + getBufferType ().name () + ")" ;
1206+ return String . format ( "%s(%s)" , getClass ().getSimpleName (), getBufferType ().name ()) ;
11971207 }
11981208 return name ;
11991209 }
12001210
1211+ /**
1212+ * Sets a custom name for this `VertexBuffer`.
1213+ *
1214+ * @param name The new name for the `VertexBuffer`. Can be null to revert
1215+ * to the default generated name.
1216+ */
12011217 public void setName (String name ) {
12021218 this .name = name ;
12031219 }
1220+
12041221}
0 commit comments