Skip to content

Commit 0d62284

Browse files
authored
Merge pull request #2395 from jcfandino/texture-array-wrap
Fix TextureArray not exporting WrapMode
2 parents 4f055d1 + 576b238 commit 0d62284

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

jme3-core/src/main/java/com/jme3/texture/TextureArray.java

+46-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@
3131
*/
3232
package com.jme3.texture;
3333

34+
import com.jme3.export.InputCapsule;
35+
import com.jme3.export.JmeExporter;
36+
import com.jme3.export.JmeImporter;
37+
import com.jme3.export.OutputCapsule;
3438
import com.jme3.texture.Image.Format;
3539
import com.jme3.texture.image.ColorSpace;
40+
import java.io.IOException;
3641
import java.util.Arrays;
3742
import java.util.List;
3843

@@ -151,4 +156,44 @@ public void setWrap(WrapMode mode) {
151156
this.wrapS = mode;
152157
this.wrapT = mode;
153158
}
154-
}
159+
160+
@Override
161+
public void write(JmeExporter e) throws IOException {
162+
super.write(e);
163+
OutputCapsule capsule = e.getCapsule(this);
164+
capsule.write(wrapS, "wrapS", WrapMode.EdgeClamp);
165+
capsule.write(wrapT, "wrapT", WrapMode.EdgeClamp);
166+
}
167+
168+
@Override
169+
public void read(JmeImporter importer) throws IOException {
170+
super.read(importer);
171+
InputCapsule capsule = importer.getCapsule(this);
172+
wrapS = capsule.readEnum("wrapS", WrapMode.class, WrapMode.EdgeClamp);
173+
wrapT = capsule.readEnum("wrapT", WrapMode.class, WrapMode.EdgeClamp);
174+
}
175+
176+
@Override
177+
public boolean equals(Object other) {
178+
if (this == other) {
179+
return true;
180+
}
181+
if (!(other instanceof TextureArray)) {
182+
return false;
183+
}
184+
TextureArray that = (TextureArray) other;
185+
if (this.getWrap(WrapAxis.S) != that.getWrap(WrapAxis.S))
186+
return false;
187+
if (this.getWrap(WrapAxis.T) != that.getWrap(WrapAxis.T))
188+
return false;
189+
return super.equals(other);
190+
}
191+
192+
@Override
193+
public int hashCode() {
194+
int hash = super.hashCode();
195+
hash = 79 * hash + (this.wrapS != null ? this.wrapS.hashCode() : 0);
196+
hash = 79 * hash + (this.wrapT != null ? this.wrapT.hashCode() : 0);
197+
return hash;
198+
}
199+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
*/
32+
package com.jme3.texture;
33+
34+
import static org.junit.Assert.*;
35+
36+
import com.jme3.asset.AssetManager;
37+
import com.jme3.asset.DesktopAssetManager;
38+
import com.jme3.export.binary.BinaryExporter;
39+
import com.jme3.texture.Texture.WrapAxis;
40+
import com.jme3.texture.Texture.WrapMode;
41+
import com.jme3.texture.image.ColorSpace;
42+
import com.jme3.util.BufferUtils;
43+
import java.nio.ByteBuffer;
44+
import java.util.ArrayList;
45+
import java.util.List;
46+
import org.junit.Test;
47+
48+
public class TextureArrayTest {
49+
50+
private static final AssetManager assetManager = new DesktopAssetManager();
51+
52+
@Test
53+
public void testExportWrapMode() {
54+
List<Image> images = new ArrayList<>();
55+
images.add(createImage());
56+
images.add(createImage());
57+
TextureArray tex3 = new TextureArray(images);
58+
tex3.setWrap(WrapMode.Repeat);
59+
TextureArray tex4 = BinaryExporter.saveAndLoad(assetManager, tex3);
60+
61+
assertEquals(tex3.getWrap(WrapAxis.S), tex4.getWrap(WrapAxis.S));
62+
assertEquals(tex3.getWrap(WrapAxis.T), tex4.getWrap(WrapAxis.T));
63+
}
64+
65+
private Image createImage() {
66+
int width = 8;
67+
int height = 8;
68+
int numBytes = 4 * width * height;
69+
ByteBuffer data = BufferUtils.createByteBuffer(numBytes);
70+
return new Image(Image.Format.RGBA8, width, height, data, ColorSpace.Linear);
71+
}
72+
73+
}

0 commit comments

Comments
 (0)