Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* Copyright (c) 2009-2025 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -57,7 +57,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
/**
* Type of buffer. Specifies the actual attribute it defines.
*/
public static enum Type {
public enum Type {
/**
* Position of the vertex (3 floats)
*/
Expand Down Expand Up @@ -233,7 +233,7 @@ public static enum Type {
* is used. This can determine if a vertex buffer is placed in VRAM
* or held in video memory, but no guarantees are made- it's only a hint.
*/
public static enum Usage {
public enum Usage {
/**
* Mesh data is sent once and very rarely updated.
*/
Expand Down Expand Up @@ -261,7 +261,7 @@ public static enum Usage {
* For the {@link Format#Half} type, {@link ByteBuffer}s should
* be used.
*/
public static enum Format {
public enum Format {
/**
* Half precision floating point. 2 bytes, signed.
*/
Expand Down Expand Up @@ -1130,6 +1130,7 @@ public void write(JmeExporter ex) throws IOException {
oc.write(offset, "offset", 0);
oc.write(stride, "stride", 0);
oc.write(instanceSpan, "instanceSpan", 0);
oc.write(name, "name", null);

String dataName = "data" + format.name();
Buffer roData = getDataReadOnly();
Expand Down Expand Up @@ -1166,6 +1167,8 @@ public void read(JmeImporter im) throws IOException {
offset = ic.readInt("offset", 0);
stride = ic.readInt("stride", 0);
instanceSpan = ic.readInt("instanceSpan", 0);
name = ic.readString("name", null);

componentsLength = components * format.getComponentSize();

String dataName = "data" + format.name();
Expand All @@ -1191,14 +1194,28 @@ public void read(JmeImporter im) throws IOException {
}
}

/**
* Returns the name of this `VertexBuffer`. If no name has been explicitly
* set, a default name is generated based on its class name and buffer type
* (e.g., "VertexBuffer(Position)").
*
* @return The name of the `VertexBuffer`.
*/
public String getName() {
if (name == null) {
name = getClass().getSimpleName() + "(" + getBufferType().name() + ")";
return String.format("%s(%s)", getClass().getSimpleName(), getBufferType().name());
}
return name;
}

/**
* Sets a custom name for this `VertexBuffer`.
*
* @param name The new name for the `VertexBuffer`. Can be null to revert
* to the default generated name.
*/
public void setName(String name) {
this.name = name;
}

}