use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestOgreComplexAnim method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10f);
cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
control = model.getControl(AnimControl.class);
AnimChannel feet = control.createChannel();
AnimChannel leftHand = control.createChannel();
AnimChannel rightHand = control.createChannel();
// feet will dodge
feet.addFromRootBone("hip.right");
feet.addFromRootBone("hip.left");
feet.setAnim("Dodge");
feet.setSpeed(2);
feet.setLoopMode(LoopMode.Cycle);
// will blend over 15 seconds to stand
feet.setAnim("Walk", 15);
feet.setSpeed(0.25f);
feet.setLoopMode(LoopMode.Cycle);
// left hand will pull
leftHand.addFromRootBone("uparm.right");
leftHand.setAnim("pull");
leftHand.setSpeed(.5f);
// will blend over 15 seconds to stand
leftHand.setAnim("stand", 15);
// right hand will push
rightHand.addBone("spinehigh");
rightHand.addFromRootBone("uparm.left");
rightHand.setAnim("push");
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Green);
mat.getAdditionalRenderState().setDepthTest(false);
skeletonDebug.setMaterial(mat);
model.attachChild(skeletonDebug);
rootNode.attachChild(model);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestBillboard method simpleInitApp.
public void simpleInitApp() {
flyCam.setMoveSpeed(10);
Quad q = new Quad(2, 2);
Geometry g = new Geometry("Quad", q);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
g.setMaterial(mat);
Quad q2 = new Quad(1, 1);
Geometry g3 = new Geometry("Quad2", q2);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.Yellow);
g3.setMaterial(mat2);
g3.setLocalTranslation(.5f, .5f, .01f);
Box b = new Box(.25f, .5f, .25f);
Geometry g2 = new Geometry("Box", b);
g2.setLocalTranslation(0, 0, 3);
g2.setMaterial(mat);
Node bb = new Node("billboard");
BillboardControl control = new BillboardControl();
bb.addControl(control);
bb.attachChild(g);
bb.attachChild(g3);
n = new Node("parent");
n.attachChild(g2);
n.attachChild(bb);
rootNode.attachChild(n);
n2 = new Node("parentParent");
n2.setLocalTranslation(Vector3f.UNIT_X.mult(5));
n2.attachChild(n);
rootNode.attachChild(n2);
// rootNode.attachChild(bb);
// rootNode.attachChild(g2);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestCustomAnim method simpleInitApp.
@Override
public void simpleInitApp() {
AmbientLight al = new AmbientLight();
rootNode.addLight(al);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(Vector3f.UNIT_XYZ.negate());
rootNode.addLight(dl);
Box box = new Box(1, 1, 1);
VertexBuffer weightsHW = new VertexBuffer(Type.HWBoneWeight);
VertexBuffer indicesHW = new VertexBuffer(Type.HWBoneIndex);
indicesHW.setUsage(Usage.CpuOnly);
weightsHW.setUsage(Usage.CpuOnly);
box.setBuffer(weightsHW);
box.setBuffer(indicesHW);
// Setup bone weight buffer
FloatBuffer weights = FloatBuffer.allocate(box.getVertexCount() * 4);
VertexBuffer weightsBuf = new VertexBuffer(Type.BoneWeight);
weightsBuf.setupData(Usage.CpuOnly, 4, Format.Float, weights);
box.setBuffer(weightsBuf);
// Setup bone index buffer
ByteBuffer indices = ByteBuffer.allocate(box.getVertexCount() * 4);
VertexBuffer indicesBuf = new VertexBuffer(Type.BoneIndex);
indicesBuf.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indices);
box.setBuffer(indicesBuf);
// Create bind pose buffers
box.generateBindPose(true);
// Create skeleton
bone = new Bone("root");
bone.setBindTransforms(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ);
bone.setUserControl(true);
skeleton = new Skeleton(new Bone[] { bone });
// Assign all verticies to bone 0 with weight 1
for (int i = 0; i < box.getVertexCount() * 4; i += 4) {
// assign vertex to bone index 0
indices.array()[i + 0] = 0;
indices.array()[i + 1] = 0;
indices.array()[i + 2] = 0;
indices.array()[i + 3] = 0;
// set weight to 1 only for first entry
weights.array()[i + 0] = 1;
weights.array()[i + 1] = 0;
weights.array()[i + 2] = 0;
weights.array()[i + 3] = 0;
}
// Maximum number of weights per bone is 1
box.setMaxNumWeights(1);
// Create model
Geometry geom = new Geometry("box", box);
geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
Node model = new Node("model");
model.attachChild(geom);
// Create skeleton control
SkeletonControl skeletonControl = new SkeletonControl(skeleton);
model.addControl(skeletonControl);
rootNode.attachChild(model);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestHoverTank method simpleInitApp.
@Override
public void simpleInitApp() {
Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
flyCam.setEnabled(false);
ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
chaseCam.setSmoothMotion(true);
chaseCam.setMaxDistance(100000);
chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
Geometry tankGeom = (Geometry) tank.getChild(0);
LodControl control = new LodControl();
tankGeom.addControl(control);
rootNode.attachChild(tank);
Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
DirectionalLight dl = new DirectionalLight();
dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
dl.setDirection(lightDir);
Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
DirectionalLight dl2 = new DirectionalLight();
dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
dl2.setDirection(lightDir2);
rootNode.addLight(dl);
rootNode.addLight(dl2);
rootNode.attachChild(tank);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
bf.setBloomIntensity(2.0f);
bf.setExposurePower(1.3f);
fpp.addFilter(bf);
BloomUI bui = new BloomUI(inputManager, bf);
viewPort.addProcessor(fpp);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class Curve method createBezierMesh.
/**
* This method creates the Bezier path for this curve.
*
* @param nbSubSegments amount of subsegments between position control
* points
*/
private void createBezierMesh(int nbSubSegments) {
if (nbSubSegments == 0) {
nbSubSegments = 1;
}
int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3;
//calculating vertices
float[] array = new float[((centerPointsAmount - 1) * nbSubSegments + 1) * 3];
int currentControlPoint = 0;
List<Vector3f> controlPoints = spline.getControlPoints();
int lineIndex = 0;
for (int i = 0; i < centerPointsAmount - 1; ++i) {
Vector3f vector3f = controlPoints.get(currentControlPoint);
array[lineIndex++] = vector3f.x;
array[lineIndex++] = vector3f.y;
array[lineIndex++] = vector3f.z;
for (int j = 1; j < nbSubSegments; ++j) {
spline.interpolate((float) j / nbSubSegments, currentControlPoint, temp);
array[lineIndex++] = temp.getX();
array[lineIndex++] = temp.getY();
array[lineIndex++] = temp.getZ();
}
currentControlPoint += 3;
}
Vector3f vector3f = controlPoints.get(currentControlPoint);
array[lineIndex++] = vector3f.x;
array[lineIndex++] = vector3f.y;
array[lineIndex++] = vector3f.z;
//calculating indexes
int i = 0, k;
short[] indices = new short[(centerPointsAmount - 1) * nbSubSegments << 1];
for (int j = 0; j < (centerPointsAmount - 1) * nbSubSegments; ++j) {
k = j;
indices[i++] = (short) k;
++k;
indices[i++] = (short) k;
}
this.setMode(Mesh.Mode.Lines);
this.setBuffer(VertexBuffer.Type.Position, 3, array);
this.setBuffer(VertexBuffer.Type.Index, 2, indices);
this.updateBound();
this.updateCounts();
}
Aggregations