tried fixing outline problem
This commit is contained in:
@@ -9,6 +9,12 @@ implementation project(":jme-common")
|
||||
implementation project(":mdga:model")
|
||||
|
||||
implementation libs.jme3.desktop
|
||||
implementation libs.jme3.core
|
||||
implementation libs.jme3.lwjgl3
|
||||
implementation libs.jme3.lwjgl
|
||||
implementation libs.jme3.desktop
|
||||
implementation libs.jme3.effects
|
||||
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.input.KeyInput;
|
||||
import com.jme3.input.MouseInput;
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.input.controls.MouseButtonTrigger;
|
||||
import com.jme3.renderer.lwjgl.LwjglRender;
|
||||
import com.jme3.system.NanoTimer;
|
||||
import pp.mdga.client.acoustic.AcousticHandler;
|
||||
import pp.mdga.client.acoustic.MdgaSound;
|
||||
@@ -15,6 +21,7 @@
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class MdgaApp extends SimpleApplication {
|
||||
private AnimationHandler animationHandler;
|
||||
private AcousticHandler acousticHandler;
|
||||
@@ -31,7 +38,7 @@ public static void main(String[] args) {
|
||||
settings.setWidth(1280);
|
||||
settings.setHeight(720);
|
||||
settings.setVSync(false);
|
||||
|
||||
settings.setRenderer(AppSettings.LWJGL_OPENGL45);
|
||||
MdgaApp app = new MdgaApp();
|
||||
app.setSettings(settings);
|
||||
app.setShowSettings(false);
|
||||
@@ -49,8 +56,10 @@ public void simpleInitApp() {
|
||||
//dialogView.mainMenu();
|
||||
//acousticHandler.playState(MdgaState.GAME);
|
||||
|
||||
acousticHandler.playSound(MdgaSound.LOST);
|
||||
acousticHandler.playSound(MdgaSound.VICTORY);
|
||||
// acousticHandler.playSound(MdgaSound.LOST);
|
||||
// acousticHandler.playSound(MdgaSound.VICTORY);
|
||||
|
||||
|
||||
|
||||
UUID test0 = UUID.randomUUID();
|
||||
UUID test1 = UUID.randomUUID();
|
||||
@@ -60,34 +69,35 @@ public void simpleInitApp() {
|
||||
testList.add(test1);
|
||||
testList.add(test0);
|
||||
|
||||
UUID test0_1 = UUID.randomUUID();
|
||||
UUID test1_1 = UUID.randomUUID();
|
||||
List<UUID> testList_1 = new ArrayList<>();
|
||||
testList_1.add(UUID.randomUUID());
|
||||
testList_1.add(UUID.randomUUID());
|
||||
testList_1.add(test1_1);
|
||||
testList_1.add(test0_1);
|
||||
// UUID test0_1 = UUID.randomUUID();
|
||||
// UUID test1_1 = UUID.randomUUID();
|
||||
// List<UUID> testList_1 = new ArrayList<>();
|
||||
// testList_1.add(UUID.randomUUID());
|
||||
// testList_1.add(UUID.randomUUID());
|
||||
// testList_1.add(test1_1);
|
||||
// testList_1.add(test0_1);
|
||||
|
||||
boardView.init();
|
||||
|
||||
inputManager.addMapping("h", new KeyTrigger(KeyInput.KEY_H));
|
||||
inputManager.addMapping("j", new KeyTrigger(KeyInput.KEY_J));
|
||||
inputManager.addListener(new ActionListener() {
|
||||
@Override
|
||||
public void onAction(String name, boolean isPressed, float tpf) {
|
||||
if (name.equals("h") && isPressed) {
|
||||
boardView.highlight(test0);
|
||||
}
|
||||
if(name.equals("j") && isPressed){
|
||||
boardView.unHighlight(test0);
|
||||
|
||||
}
|
||||
}
|
||||
}, "h", "j");
|
||||
|
||||
|
||||
boardView.addPlayer(Color.AIRFORCE, testList);
|
||||
// boardView.movePieceStart(test0, 0);
|
||||
// boardView.movePiece(test0, 0, 1);
|
||||
// boardView.movePiece(test0, 1, 6);
|
||||
// boardView.throwPiece(test0);
|
||||
// boardView.shieldPiece(test0);
|
||||
|
||||
// boardView.addPlayer(Color.CYBER, testList_1);
|
||||
// boardView.movePieceStart(test0_1, 10);
|
||||
// boardView.movePiece(test0_1, 10,14);
|
||||
// boardView.movePiece(test0_1, 14,15);
|
||||
|
||||
boardView.highlight(test0);
|
||||
|
||||
|
||||
|
||||
// boardView.moveHomePiece(test0, 0);
|
||||
// boardView.moveHomePiece(test0, Color.AIRFORCE,0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,10 +46,10 @@ public BoardHandler(MdgaApp app) {
|
||||
this.waitingNodesMap = new HashMap<>();
|
||||
this.waitingPiecesMap = new HashMap<>();
|
||||
this.pieceColor = new HashMap<>();
|
||||
this.node = new Node();
|
||||
this.node = new Node("Asset Node");
|
||||
this.outlineHandler = new OutlineHandler(app, app.getRootNode());
|
||||
|
||||
// app.getRootNode().attachChild(node);
|
||||
app.getRootNode().attachChild(node);
|
||||
}
|
||||
|
||||
private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
|
||||
@@ -103,8 +103,8 @@ private Spatial createModel(BoardAsset asset, Vector3f pos, float rot) {
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
||||
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName));
|
||||
model.setMaterial(mat);
|
||||
// node.attachChild(model);
|
||||
app.getRootNode().attachChild(model);
|
||||
node.attachChild(model);
|
||||
// app.getRootNode().attachChild(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public void addPlayer(Color color, List<UUID> uuid) {
|
||||
|
||||
for (int i = 0; i < playerAssets.size(); i++){
|
||||
AssetOnMap assetOnMap = playerAssets.get(i);
|
||||
PieceControl pieceControl = displayAndControl(assetOnMap, new PieceControl(assetOnMap.rot(), app.getAssetManager(), app.getRootNode()));
|
||||
PieceControl pieceControl = displayAndControl(assetOnMap, new PieceControl(assetOnMap.rot(), app.getAssetManager(), app));
|
||||
movePieceToNode(pieceControl, waitNodes.get(i));
|
||||
|
||||
pieces.put(uuid.get(i), pieceControl);
|
||||
@@ -289,10 +289,10 @@ public void shutdown(){
|
||||
//List<Pieces>
|
||||
//List<NodesIndexe>
|
||||
public void highlight(UUID uuid){
|
||||
outlineHandler.outlineOwn(pieces.get(uuid).getSpatial());
|
||||
pieces.get(uuid).outline();
|
||||
}
|
||||
|
||||
public void unHighlight(UUID uuid){
|
||||
outlineHandler.deOutline(pieces.get(uuid).getSpatial());
|
||||
pieces.get(uuid).deOutline();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ public class OutlineHandler {
|
||||
private static final ColorRGBA OUTLINE_ENEMY_COLOR = ColorRGBA.Red;
|
||||
private static final int OUTLINE_THICKNESS = 4;
|
||||
|
||||
private Node outlineNode;
|
||||
|
||||
public OutlineHandler(MdgaApp app, Node rootNode){
|
||||
FilterPostProcessor fpp = new FilterPostProcessor(app.getAssetManager());
|
||||
app.getViewPort().addProcessor(fpp);
|
||||
|
||||
@@ -17,31 +17,37 @@
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public class PieceControl extends AbstractControl {
|
||||
private float rotation;
|
||||
private final float initRotation;
|
||||
private AssetManager assetManager;
|
||||
private final AssetManager assetManager;
|
||||
private Spatial shieldRing;
|
||||
private Node rootNode;
|
||||
private Material shield_mat;
|
||||
private MdgaApp app;
|
||||
private final Material shieldMat;
|
||||
|
||||
private static final float SHIELD_SPEED = 1f;
|
||||
private static final float SHIELD_TRANSPARENCY = 0.6f;
|
||||
private static final ColorRGBA SHIELD_COLOR = new ColorRGBA(0, 0.9f, 1, SHIELD_TRANSPARENCY);
|
||||
private static final ColorRGBA SHIELD_SUPPRESSED_COLOR = new ColorRGBA(1f, 0.5f, 0, SHIELD_TRANSPARENCY);
|
||||
private static final float SHIELD_Z = 0f;
|
||||
private static final ColorRGBA OUTLINE_COLOR = ColorRGBA.White;
|
||||
private static final int OUTLINE_THICKNESS = 4;
|
||||
|
||||
public PieceControl(float initRotation, AssetManager assetManager, Node rootNode){
|
||||
SelectObjectOutliner outlineOwn;
|
||||
|
||||
private static final ColorRGBA OUTLINE_OWN_COLOR = ColorRGBA.White;
|
||||
private static final int OUTLINE_THICKNESS = 4;
|
||||
private final Node parentNode;
|
||||
|
||||
public PieceControl(float initRotation, AssetManager assetManager, MdgaApp app){
|
||||
super();
|
||||
this.parentNode = new Node();
|
||||
this.initRotation = initRotation;
|
||||
this.assetManager = assetManager;
|
||||
this.shieldRing = null;
|
||||
this.rootNode = rootNode;
|
||||
this.shieldMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
this.shieldMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
|
||||
|
||||
FilterPostProcessor fpp = new FilterPostProcessor(app.getAssetManager());
|
||||
app.getViewPort().addProcessor(fpp);
|
||||
outlineOwn = new SelectObjectOutliner();
|
||||
outlineOwn.initOutliner(SelectObjectOutliner.OUTLINER_TYPE_FILTER, OUTLINE_THICKNESS, OUTLINE_OWN_COLOR, parentNode, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
|
||||
|
||||
this.shield_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
this.shield_mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
@@ -76,10 +82,23 @@ public void setLocation(Vector3f loc){
|
||||
|
||||
@Override
|
||||
public void setSpatial(Spatial spatial){
|
||||
super.setSpatial(spatial);
|
||||
if(spatial != null){
|
||||
setRotation(this.initRotation);
|
||||
if(this.getSpatial() == null && spatial != null){
|
||||
super.setSpatial(spatial);
|
||||
initSpatial();
|
||||
}
|
||||
else{
|
||||
super.setSpatial(spatial);
|
||||
}
|
||||
}
|
||||
|
||||
public void initSpatial(){
|
||||
setRotation(this.initRotation);
|
||||
|
||||
Node oldParent = this.spatial.getParent();
|
||||
this.parentNode.setName(this.spatial.getName() + " Parent");
|
||||
oldParent.detachChild(this.getSpatial());
|
||||
this.parentNode.attachChild(this.getSpatial());
|
||||
oldParent.attachChild(this.parentNode);
|
||||
}
|
||||
|
||||
public void rotateInit() {
|
||||
@@ -94,20 +113,20 @@ public void activateShield(){
|
||||
|
||||
|
||||
shieldRing.setQueueBucket(RenderQueue.Bucket.Transparent); // Render in the transparent bucket
|
||||
shield_mat.setColor("Color", SHIELD_COLOR);
|
||||
shieldRing.setMaterial(shield_mat);
|
||||
shieldMat.setColor("Color", SHIELD_COLOR);
|
||||
shieldRing.setMaterial(shieldMat);
|
||||
|
||||
rootNode.attachChild(shieldRing);
|
||||
parentNode.attachChild(shieldRing);
|
||||
}
|
||||
|
||||
public void deactivateShield(){
|
||||
rootNode.detachChild(shieldRing);
|
||||
parentNode.detachChild(shieldRing);
|
||||
shieldRing = null;
|
||||
}
|
||||
|
||||
public void suppressShield(){
|
||||
assert(shieldRing != null) : "PieceControl: shieldRing is not set";
|
||||
shield_mat.setColor("Color", SHIELD_SUPPRESSED_COLOR);
|
||||
shieldMat.setColor("Color", SHIELD_SUPPRESSED_COLOR);
|
||||
}
|
||||
|
||||
public void setMaterial(Material mat){
|
||||
@@ -117,4 +136,12 @@ public void setMaterial(Material mat){
|
||||
public Material getMaterial(){
|
||||
return ((Geometry) this.spatial).getMaterial();
|
||||
}
|
||||
|
||||
public void outline() {
|
||||
outlineOwn.select(this.getSpatial());
|
||||
}
|
||||
|
||||
public void deOutline() {
|
||||
outlineOwn.deselect(this.getSpatial());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xxx
|
||||
*/
|
||||
public class SelectObjectOutliner {
|
||||
|
||||
|
||||
private FilterPostProcessor fpp;
|
||||
private RenderManager renderManager;
|
||||
private AssetManager assetManager;
|
||||
@@ -50,15 +50,15 @@ public class SelectObjectOutliner {
|
||||
*/
|
||||
public SelectObjectOutliner()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type of filter: OUTLINER_TYPE_FILTER or OUTLINER_TYPE_MATERIAL
|
||||
* @param width of the selection border
|
||||
* @param color of the selection border
|
||||
* @param modelNode direct node containing the spacial. Wil be used to add geometry in OUTLINER_TYPE_MATERIAL node.
|
||||
* @param modelNode direct node containing the spacial. Wil be used to add geometry in OUTLINER_TYPE_MATERIAL node.
|
||||
* @param fpp - FilterPostProcessor to handle filtering
|
||||
* @param renderManager
|
||||
* @param assetManager
|
||||
@@ -76,17 +76,17 @@ public void initOutliner(int type, int width, ColorRGBA color, Node modelNode,
|
||||
this.color=color;
|
||||
if(outlinerType==OUTLINER_TYPE_MATERIAL)
|
||||
{
|
||||
wireMaterial= new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
wireMaterial= new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
wireMaterial.setColor("Color", color);//color
|
||||
wireMaterial.getAdditionalRenderState().setWireframe(true); //we want wireframe
|
||||
wireMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);//that's just because we add an alpha pulse to the selection later, this is not mandatory
|
||||
wireMaterial.getAdditionalRenderState().setLineWidth(width); //you can play with this param to increase the line thickness
|
||||
wireMaterial.getAdditionalRenderState().setPolyOffset(-3f,-3f); //this is trick one, offsetting the polygons
|
||||
wireMaterial.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front); // trick 2 we hide the front faces to not see the wireframe on top of the geom
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param model to be delected
|
||||
@@ -96,45 +96,45 @@ public void deselect(Spatial model)
|
||||
if(outlinerType==OUTLINER_TYPE_FILTER)
|
||||
hideOutlineFilterEffect(model);
|
||||
else
|
||||
hideOutlineMaterialEffect(model);
|
||||
|
||||
hideOutlineMaterialEffect(model);
|
||||
|
||||
model.setUserData("OutlineSelected", false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param model to delected
|
||||
*/
|
||||
public void select(Spatial model)
|
||||
public void select(Spatial model)
|
||||
{
|
||||
if(outlinerType==OUTLINER_TYPE_FILTER)
|
||||
showOutlineFilterEffect( model, width, color);
|
||||
else
|
||||
showOutlineMaterialEffect( model, width, color);
|
||||
|
||||
showOutlineMaterialEffect( model, width, color);
|
||||
|
||||
model.setUserData("OutlineSelected", true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
public boolean isSelected(Spatial model)
|
||||
public boolean isSelected(Spatial model)
|
||||
{
|
||||
if(model.getUserData("OutlineSelected")!=null && ((Boolean)model.getUserData("OutlineSelected"))==true)
|
||||
if(model.getUserData("OutlineSelected")!=null && ((Boolean)model.getUserData("OutlineSelected"))==true)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
private void hideOutlineMaterialEffect(Spatial model) {
|
||||
|
||||
Spatial geo= (Spatial)model.getUserData("OutlineGeo");
|
||||
|
||||
Spatial geo= (Spatial)model.getUserData("OutlineGeo");
|
||||
if (geo != null)
|
||||
modelNode.detachChild(geo);
|
||||
}
|
||||
private void showOutlineMaterialEffect(Spatial model, int width, ColorRGBA color) {
|
||||
|
||||
|
||||
Spatial geo=model.clone(false);
|
||||
geo.setMaterial(wireMaterial);
|
||||
model.setUserData("OutlineGeo", geo);
|
||||
@@ -144,7 +144,9 @@ private void hideOutlineFilterEffect(Spatial model) {
|
||||
OutlineFilter outlineFilter = model.getUserData("OutlineFilter");
|
||||
if (outlineFilter != null) {
|
||||
outlineFilter.setEnabled(false);
|
||||
outlineFilter.getOutlinePreFilter().setEnabled(false);
|
||||
outlineFilter.getOutlinePreFilter().setEnabled(false);
|
||||
fpp.removeFilter(outlineFilter);
|
||||
model.setUserData("OutlineFilter", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,21 +161,21 @@ private void showOutlineFilterEffect(Spatial model, int width, ColorRGBA color)
|
||||
outlineViewport.attachScene(model);
|
||||
outlineViewport.addProcessor(outlinefpp);
|
||||
//
|
||||
outlineFilter = new OutlineFilter(outlinePreFilter);
|
||||
((OutlineFilter)outlineFilter).setOutlineColor(color);
|
||||
((OutlineFilter)outlineFilter).setOutlineWidth(width);
|
||||
model.setUserData("OutlineFilter", outlineFilter);
|
||||
|
||||
outlineFilter = new OutlineFilter(outlinePreFilter);
|
||||
((OutlineFilter)outlineFilter).setOutlineColor(color);
|
||||
((OutlineFilter)outlineFilter).setOutlineWidth(width);
|
||||
model.setUserData("OutlineFilter", outlineFilter);
|
||||
|
||||
fpp.addFilter(outlineFilter);
|
||||
} else {
|
||||
outlineFilter.setEnabled(true);
|
||||
//
|
||||
((OutlineFilter)outlineFilter).getOutlinePreFilter().setEnabled(true);
|
||||
|
||||
((OutlineFilter)outlineFilter).getOutlinePreFilter().setEnabled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ MaterialDef Cartoon Edge {
|
||||
}
|
||||
|
||||
Technique {
|
||||
VertexShader GLSL100: MatDefs/SelectObjectOutliner/Post15.vert
|
||||
FragmentShader GLSL100: MatDefs/SelectObjectOutliner/Outline.frag
|
||||
VertexShader GLSL150: MatDefs/SelectObjectOutliner/Post15.vert
|
||||
FragmentShader GLSL150: MatDefs/SelectObjectOutliner/Outline.frag
|
||||
|
||||
WorldParameters {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,4 @@ MaterialDef Cartoon Edge {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Technique {
|
||||
VertexShader GLSL100: Common/MatDefs/Post/Post.vert
|
||||
FragmentShader GLSL100: Shaders/outline/OutlinePre.frag
|
||||
|
||||
WorldParameters {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user