| package org.eclipse.apogy.addons.sensors.fov.ui.jme3.scene_objects; |
| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard - initial API and implementation |
| * Regent L'Archeveque |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| |
| import java.util.concurrent.Callable; |
| |
| import org.eclipse.apogy.addons.sensors.fov.FieldOfView; |
| import org.eclipse.apogy.addons.sensors.fov.ui.jme3.utils.AbstractFieldOfViewImageProjectorControl; |
| import org.eclipse.apogy.addons.sensors.fov.ui.scene_objects.FieldOfViewSceneObject; |
| import org.eclipse.apogy.common.topology.ui.MeshPresentationMode; |
| import org.eclipse.apogy.common.topology.ui.jme3.JME3RenderEngineDelegate; |
| import org.eclipse.apogy.common.topology.ui.jme3.JME3Utilities; |
| import org.eclipse.apogy.common.topology.ui.jme3.scene_objects.DefaultJME3SceneObject; |
| import org.eclipse.swt.graphics.RGB; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.jme3.math.ColorRGBA; |
| |
| public abstract class AbstractFieldOfViewJME3Object<R extends FieldOfView> extends DefaultJME3SceneObject<R> |
| implements FieldOfViewSceneObject { |
| private static final Logger Logger = LoggerFactory.getLogger(AbstractFieldOfViewJME3Object.class); |
| |
| protected MeshPresentationMode meshPresentationMode = MeshPresentationMode.WIREFRAME; |
| protected float transparency = 0.0f; |
| protected boolean showProjection = false; |
| protected boolean fovVisible = false; |
| protected boolean showOutlineOnly = false; |
| protected ColorRGBA fovColor = new ColorRGBA(0f, 1f, 0.0f, 0.25f); |
| protected RGB rgb = new RGB(1, 1, 1); |
| protected RGB projectionColor = new RGB(1, 1, 1); |
| protected com.jme3.scene.Node fovNode; |
| |
| public AbstractFieldOfViewJME3Object(R topologyNode, JME3RenderEngineDelegate jme3RenderEngineDelegate) { |
| super(topologyNode, jme3RenderEngineDelegate); |
| } |
| |
| @Override |
| public void setColor(RGB rgb) { |
| this.rgb = rgb; |
| this.fovColor = JME3Utilities.convertToColorRGBA(rgb); |
| } |
| |
| @Override |
| public RGB getColor() { |
| return this.rgb; |
| } |
| |
| @Override |
| public MeshPresentationMode getPresentationMode() { |
| return this.meshPresentationMode; |
| } |
| |
| @Override |
| public float getTransparency() { |
| return this.transparency; |
| } |
| |
| @Override |
| public void setFOVVisible(boolean visible) { |
| Logger.info("Set FOV Visible <" + visible + ")"); |
| |
| this.fovVisible = visible; |
| |
| this.jme3Application.enqueue(new Callable<Object>() { |
| @Override |
| public Object call() throws Exception { |
| if (!AbstractFieldOfViewJME3Object.this.fovVisible && getAttachmentNode().hasChild(getFovNode())) { |
| getAttachmentNode().detachChild(getFovNode()); |
| } else if (AbstractFieldOfViewJME3Object.this.fovVisible |
| && !getAttachmentNode().hasChild(getFovNode())) { |
| getAttachmentNode().attachChild(getFovNode()); |
| } |
| return null; |
| } |
| }); |
| } |
| |
| @Override |
| public boolean isFOVVisible() { |
| return this.fovVisible; |
| } |
| |
| @Override |
| public boolean isShowProjection() { |
| return this.showProjection; |
| } |
| |
| @Override |
| public boolean isShowOutlineOnly() { |
| return this.showOutlineOnly; |
| } |
| |
| @Override |
| public void setProjectionColor(RGB color) { |
| this.projectionColor = color; |
| this.jme3Application.enqueue(new Callable<Object>() { |
| @Override |
| public Object call() throws Exception { |
| getAbstractFieldOfViewImageProjectorControl().setProjectionColor(color); |
| return null; |
| } |
| }); |
| } |
| |
| @Override |
| public RGB getProjectionColor() { |
| return this.projectionColor; |
| } |
| |
| public abstract AbstractFieldOfViewImageProjectorControl<R> getAbstractFieldOfViewImageProjectorControl(); |
| |
| /** |
| * Return the n ode to which the FOV representation should be attached. |
| * |
| * @return The node. |
| */ |
| protected com.jme3.scene.Node getFovNode() { |
| if (this.fovNode == null) { |
| String name = null; |
| if (getTopologyNode() != null && getTopologyNode().getNodeId() != null) { |
| name = getTopologyNode().getNodeId(); |
| } else { |
| name = getClass().getSimpleName(); |
| } |
| name += "_fov"; |
| |
| this.fovNode = new com.jme3.scene.Node(name); |
| |
| // Attaches the FOV node to the attachment node. |
| getAttachmentNode().attachChild(this.fovNode); |
| } |
| return this.fovNode; |
| } |
| } |