Skip to content

Commit f67a843

Browse files
authored
solve issue 1640 (CartoonEdgeFilter failing to override read() and write()) (#1647)
* solve issue 1640 (CartoonEdgeFilter failing to override read() and write()) - remove unused import and extra empty lines from CartoonEdgeFilter - add test case for CartoonEdgeFilter save and load * fix for Desktop Asset Manager creation while run test case for CartoonEdgeFilter * add javadoc
1 parent 8acc565 commit f67a843

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

jme3-effects/src/main/java/com/jme3/post/filters/CartoonEdgeFilter.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@
3131
*/
3232
package com.jme3.post.filters;
3333

34+
import java.io.IOException;
35+
3436
import com.jme3.asset.AssetManager;
37+
import com.jme3.export.InputCapsule;
38+
import com.jme3.export.JmeExporter;
39+
import com.jme3.export.JmeImporter;
40+
import com.jme3.export.OutputCapsule;
3541
import com.jme3.material.Material;
3642
import com.jme3.math.ColorRGBA;
3743
import com.jme3.post.Filter;
38-
import com.jme3.post.Filter.Pass;
3944
import com.jme3.renderer.RenderManager;
4045
import com.jme3.renderer.Renderer;
4146
import com.jme3.renderer.ViewPort;
@@ -109,8 +114,6 @@ protected void initFilter(AssetManager manager, RenderManager renderManager, Vie
109114
protected void cleanUpFilter(Renderer r) {
110115
normalPass.cleanup(r);
111116
}
112-
113-
114117

115118
/**
116119
* Return the depth sensitivity<br>
@@ -196,7 +199,6 @@ public void setEdgeWidth(float edgeWidth) {
196199
if (material != null) {
197200
material.setFloat("EdgeWidth", edgeWidth);
198201
}
199-
200202
}
201203

202204
/**
@@ -261,4 +263,30 @@ public void setEdgeColor(ColorRGBA edgeColor) {
261263
material.setColor("EdgeColor", edgeColor);
262264
}
263265
}
266+
267+
@Override
268+
public void write(JmeExporter ex) throws IOException {
269+
super.write(ex);
270+
OutputCapsule oc = ex.getCapsule(this);
271+
oc.write(edgeWidth, "edgeWidth", 1.0f);
272+
oc.write(edgeIntensity, "edgeIntensity", 1.0f);
273+
oc.write(normalThreshold, "normalThreshold", 0.5f);
274+
oc.write(depthThreshold, "depthThreshold", 0.1f);
275+
oc.write(normalSensitivity, "normalSensitivity", 1.0f);
276+
oc.write(depthSensitivity, "depthSensitivity", 10.0f);
277+
oc.write(edgeColor, "edgeColor", ColorRGBA.Black);
278+
}
279+
280+
@Override
281+
public void read(JmeImporter im) throws IOException {
282+
super.read(im);
283+
InputCapsule ic = im.getCapsule(this);
284+
edgeWidth = ic.readFloat("edgeWidth", 1.0f);
285+
edgeIntensity = ic.readFloat("edgeIntensity", 1.0f);
286+
normalThreshold = ic.readFloat("normalThreshold", 0.5f);
287+
depthThreshold = ic.readFloat("depthThreshold", 0.1f);
288+
normalSensitivity = ic.readFloat("normalSensitivity", 1.0f);
289+
depthSensitivity = ic.readFloat("depthSensitivity", 10.0f);
290+
edgeColor = (ColorRGBA) ic.readSavable("edgeColor", ColorRGBA.Black.clone());
291+
}
264292
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.jme3.post.filters;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import com.jme3.asset.AssetManager;
7+
import com.jme3.asset.DesktopAssetManager;
8+
import com.jme3.export.binary.BinaryExporter;
9+
import com.jme3.math.ColorRGBA;
10+
11+
/**
12+
*
13+
* @author capdevon
14+
*/
15+
public class CartoonEdgeFilterTest {
16+
17+
/**
18+
* Test saving/loading a CartoonEdgeFilter
19+
*/
20+
@Test
21+
public void testSaveAndLoad() {
22+
AssetManager assetManager = new DesktopAssetManager();
23+
24+
CartoonEdgeFilter cartoon = new CartoonEdgeFilter();
25+
cartoon.setEdgeColor(ColorRGBA.Red);
26+
cartoon.setEdgeIntensity(.5f);
27+
cartoon.setEdgeWidth(1);
28+
cartoon.setNormalSensitivity(2);
29+
cartoon.setNormalThreshold(1);
30+
cartoon.setDepthSensitivity(20);
31+
cartoon.setDepthThreshold(2);
32+
33+
CartoonEdgeFilter filter = BinaryExporter.saveAndLoad(assetManager, cartoon);
34+
35+
Assert.assertEquals(ColorRGBA.Red, filter.getEdgeColor());
36+
Assert.assertEquals(.5f, filter.getEdgeIntensity(), 0.0001);
37+
Assert.assertEquals(1, filter.getEdgeWidth(), 0.0001);
38+
Assert.assertEquals(2, filter.getNormalSensitivity(), 0.0001);
39+
Assert.assertEquals(1, filter.getNormalThreshold(), 0.0001);
40+
Assert.assertEquals(20, filter.getDepthSensitivity(), 0.0001);
41+
Assert.assertEquals(2, filter.getDepthThreshold(), 0.0001);
42+
}
43+
44+
}

0 commit comments

Comments
 (0)