Java Code Examples for com.jme3.scene.shape.Box#getVertexCount()

The following examples show how to use com.jme3.scene.shape.Box#getVertexCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCustomAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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();

	// Create skeleton
	bone = new Joint("root");
	bone.setLocalTransform(new Transform(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ));
	armature = new Armature(new Joint[] { 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
	SkinningControl skinningControl = new SkinningControl(armature);
	model.addControl(skinningControl);

	rootNode.attachChild(model);
}
 
Example 2
Source File: TestCustomAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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);

    // 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);
}