use of com.jme3.scene.control.AbstractControl in project jmonkeyengine by jMonkeyEngine.
the class TestDepthStencil method simpleInitApp.
@Override
public void simpleInitApp() {
int w = settings.getWidth();
int h = settings.getHeight();
//setup framebuffer
fb = new FrameBuffer(w, h, 1);
Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
fb.setDepthBuffer(Format.Depth24Stencil8);
fb.setColorTexture(fbTex);
// setup framebuffer's scene
Sphere sphMesh = new Sphere(20, 20, 1);
Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
final Geometry sphere = new Geometry("sphere", sphMesh);
sphere.setMaterial(solidColor);
fbNode.attachChild(sphere);
sphere.addControl(new AbstractControl() {
@Override
protected void controlUpdate(float tpf) {
Material mat = sphere.getMaterial();
mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}
});
//setup main scene
Picture p = new Picture("Picture");
p.setPosition(0, 0);
p.setWidth(w);
p.setHeight(h);
p.setTexture(assetManager, fbTex, false);
rootNode.attachChild(p);
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
ActionListener acl = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("toggle") && keyPressed) {
if (enableStencil) {
enableStencil = false;
System.out.println("Stencil Enabled (model should be hidden)");
} else {
enableStencil = true;
System.out.println("Stencil Disabled (model should be visible)");
}
}
}
};
inputManager.addListener(acl, "toggle");
System.out.println("Press space to toggle stencil");
}
use of com.jme3.scene.control.AbstractControl in project TeachingInSimulation by ScOrPiOzzy.
the class MHZ2_20DControlEx method controlUpdate.
@Override
protected void controlUpdate(float tpf) {
Vector3f origin = start.getWorldTranslation();
Vector3f goal = end.getWorldTranslation();
Ray ray = new Ray(origin, goal.add(origin.negate()));
CollisionResults results = new CollisionResults();
rootNode.collideWith(ray, results);
for (CollisionResult result : results) {
Geometry geometry = result.getGeometry();
if ("workpiece".equals(geometry.getUserData("type"))) {
// 获得工件模型
Spatial workpiece = geometry.getParent().getParent();
if ("0".equals(geometry.getParent().getUserData("combined"))) {
Spatial combined = workpiece.getParent();
if (combined.getNumControls() != 0) {
combined.setLocalTranslation(Vector3f.ZERO);
ItemControl control = (ItemControl) combined.getControl(0);
control.setEnabled(false);
pieceLoc.attachChild(combined);
}
}
break;
} else if ("material".equals(geometry.getUserData("type"))) {
// 获得工件模型
Spatial material = geometry.getParent().getParent();
if ("1".equals(geometry.getParent().getUserData("combined"))) {
Spatial combined = material.getParent();
if (combined.getNumControls() != 0) {
combined.setLocalTranslation(Vector3f.ZERO);
ItemControl control = (ItemControl) combined.getControl(0);
control.setEnabled(false);
pieceLoc.attachChild(combined);
}
}
break;
}
}
if (!clamp) {
return;
}
float per = tpf * speed;
if (b) {
left.move(per, 0, 0);
right.move(-per, 0, 0);
total += per;
if (total >= length) {
left.move(length - total, 0, 0);
right.move(total - length, 0, 0);
total = length;
clamp = false;
magnet.setLocalTranslation(0, -0.015f, 0);
}
} else {
left.move(-per, 0, 0);
right.move(per, 0, 0);
total -= per;
if (total <= 0) {
left.move(-total, 0, 0);
right.move(total, 0, 0);
total = 0;
magnet.setLocalTranslation(0, 0.015f, 0);
clamp = false;
if (pieceLoc.getChildren().size() == 0) {
return;
}
final Spatial combined = pieceLoc.getChild(0);
if (combined != null && combined.getNumControls() != 0) {
combined.setLocalTranslation(combined.getWorldTranslation());
Dispatcher.getIns().getMainApp().enqueue(new Runnable() {
@Override
public void run() {
try {
rootNode.attachChild(combined);
AbstractControl control = (AbstractControl) combined.getControl(0);
control.setEnabled(true);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
});
}
}
}
}
use of com.jme3.scene.control.AbstractControl in project TeachingInSimulation by ScOrPiOzzy.
the class LinkTargetHandler method select.
public void select() {
MultimeterState_MF47 multimeterState = stateManager.getState(MultimeterState_MF47.class);
if (multimeterState.isEnabled() && target instanceof Terminal) {
multimeterState.putPenToTerminal((Terminal) target, target.getModel());
return;
}
if (!handler.checkConnect(target)) {
return;
}
LinkerMsg reqMsg = handler.offlineConnect(target);
// 如果当前为多人联机模式则向服务器发送连线请求
if (!handler.isAlone()) {
reqMsg.setType(LinkerMsg.ADD_LINKER);
ClientMgr.send(reqMsg);
}
if (!(target instanceof Terminal)) {
return;
}
// 螺丝拧上拧下
Node parent = (Node) target.getModel();
// findCylinder(parent);
final Spatial luosi = parent.getChild("screw");
if (luosi == null) {
throw new RuntimeException("螺丝的模型结构有问题, 没有指出螺杆节点");
}
if (luosi.getNumControls() > 0) {
AbstractControl control = (AbstractControl) luosi.getControl(0);
control.setEnabled(true);
}
}
use of com.jme3.scene.control.AbstractControl in project TeachingInSimulation by ScOrPiOzzy.
the class SensorLogic method cloneForSpatial.
/**
* Default implementation of cloneForSpatial() that simply clones the control and sets the spatial.
*
* <pre>
* AbstractControl c = clone();
* c.spatial = null;
* c.setSpatial(spatial);
* </pre>
*
* Controls that wish to be persisted must be Cloneable.
*/
@Override
public Control cloneForSpatial(Spatial spatial) {
try {
AbstractControl c = (AbstractControl) clone();
// c.spatial = null; // to keep setSpatial() from throwing an exception
c.setSpatial(spatial);
return c;
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Can't clone control for spatial", e);
}
}
Aggregations