com.jme3.animation.Skeleton Java Examples

The following examples show how to use com.jme3.animation.Skeleton. 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: ArmatureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method retuns the bone tracks for animation for blender version 2.49
 * (and probably several lower versions too).
 * 
 * @param actionStructure
 *            the structure containing the tracks
 * @param blenderContext
 *            the blender context
 * @return a list of tracks for the specified animation
 * @throws BlenderFileException
 *             an exception is thrown when there are problems with the blend
 *             file
 */
private BoneTrack[] getTracks249(Structure actionStructure, Skeleton skeleton, BlenderContext blenderContext) throws BlenderFileException {
    LOGGER.log(Level.FINE, "Getting tracks!");
    IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
    int fps = blenderContext.getBlenderKey().getFps();
    Structure chanbase = (Structure) actionStructure.getFieldValue("chanbase");
    List<Structure> actionChannels = chanbase.evaluateListBase(blenderContext);// bActionChannel
    List<BoneTrack> tracks = new ArrayList<BoneTrack>();
    for (Structure bActionChannel : actionChannels) {
        String name = bActionChannel.getFieldValue("name").toString();
        int boneIndex = this.getBoneIndex(skeleton, name);
        if (boneIndex >= 0) {
            Pointer p = (Pointer) bActionChannel.getFieldValue("ipo");
            if (!p.isNull()) {
                Structure ipoStructure = p.fetchData(blenderContext.getInputStream()).get(0);

                Bone bone = skeleton.getBone(boneIndex);
                Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext);
                if (ipo != null) {
                    tracks.add((BoneTrack) ipo.calculateTrack(boneIndex, bone.getLocalRotation(), 0, ipo.getLastFrame(), fps, false));
                }
            }
        }
    }
    return tracks.toArray(new BoneTrack[tracks.size()]);
}
 
Example #2
Source File: ArmatureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method returns a map where the key is the object's group index that
 * is used by a bone and the key is the bone index in the armature.
 * 
 * @param defBaseStructure
 *            a bPose structure of the object
 * @return bone group-to-index map
 * @throws BlenderFileException
 *             this exception is thrown when the blender file is somehow
 *             corrupted
 */
public Map<Integer, Integer> getGroupToBoneIndexMap(Structure defBaseStructure, Skeleton skeleton, BlenderContext blenderContext) throws BlenderFileException {
    Map<Integer, Integer> result = null;
    if (skeleton.getBoneCount() != 0) {
        result = new HashMap<Integer, Integer>();
        List<Structure> deformGroups = defBaseStructure.evaluateListBase(blenderContext);// bDeformGroup
        int groupIndex = 0;
        for (Structure deformGroup : deformGroups) {
            String deformGroupName = deformGroup.getFieldValue("name").toString();
            int boneIndex = this.getBoneIndex(skeleton, deformGroupName);
            if (boneIndex >= 0) {
                result.put(groupIndex, boneIndex);
            }
            ++groupIndex;
        }
    }
    return result;
}
 
Example #3
Source File: SkeletonPoints.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a points with bone lengths data. If the data is supplied then the points will show both head and tail of each bone.
 * @param skeleton
 *            the skeleton that will be shown
 * @param boneLengths
 *            a map between the bone's index and the bone's length
 */
public SkeletonPoints(Skeleton skeleton, Map<Integer, Float> boneLengths) {
    this.skeleton = skeleton;
    this.setMode(Mode.Points);
    int pointsCount = skeleton.getBoneCount();

    if (boneLengths != null) {
        this.boneLengths = boneLengths;
        pointsCount *= 2;
    }

    VertexBuffer pb = new VertexBuffer(Type.Position);
    FloatBuffer fpb = BufferUtils.createFloatBuffer(pointsCount * 3);
    pb.setupData(Usage.Stream, 3, Format.Float, fpb);
    this.setBuffer(pb);

    this.updateCounts();

}
 
Example #4
Source File: PMDNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
    public void write(JmeExporter e) throws IOException {
        super.write(e);
        OutputCapsule c = e.getCapsule(this);
        c.write(1, "version", 1);
        SavableUtil.write(c, pmdModel, "pmdModel");
        c.write(skeleton, "skeleton", new Skeleton());
        c.writeStringSavableMap(skinMap, "skinMap", new HashMap<String, Skin>());
//        c.write(skinBoneWeightArray, "skinBoneWeightArray", null);
//        c.write(skinBoneArray, "skinBoneArray", null);
        c.write(edgeSize, "edgeSize", 1.0f);
        c.write(pmdGeometryArray.length, "pmdGeometryArrayLength",0);
        c.write(skinTargets.length, "skinTargetsLength",0);
        if (skinTargets != null && skinTargets.length > 0) {
            PMDSkinMesh mesh = skinTargets[0];
            c.write(mesh.getSkinvb2(),"skinvb",null);
//            c.write(mesh.getSkinnb2(),"skinnb",null);
            c.write(mesh.getBuffer(Type.TexCoord),"skintb",null);
        }
        c.write(skinArray, "skinArray", null);
//        SavableUtil.write(c, skinPosArrayOrig,"skinPosArray");
//        SavableUtil.write(c, skinNormalArrayOrig, "skinNormalArray");
//        c.write(skinBoneArray, "skinBoneArray", null);
//        c.write(skinBoneWeightArray, "skinBoneWeightArray", null);
        
    }
 
Example #5
Source File: SkeletonDebugger.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a debugger with bone lengths data. If the data is supplied then the wires will show each full bone (from head to tail),
 * the points will display both heads and tails of the bones and dotted lines between bones will be seen.
 * @param name
 *            the name of the debugger's node
 * @param skeleton
 *            the skeleton that will be shown
 * @param boneLengths
 *            a map between the bone's index and the bone's length
 */
public SkeletonDebugger(String name, Skeleton skeleton, Map<Integer, Float> boneLengths) {
    super(name);

    wires = new SkeletonWire(skeleton, boneLengths);
    points = new SkeletonPoints(skeleton, boneLengths);

    this.attachChild(new Geometry(name + "_wires", wires));
    this.attachChild(new Geometry(name + "_points", points));
    if (boneLengths != null) {
        interBoneWires = new SkeletonInterBoneWire(skeleton, boneLengths);
        this.attachChild(new Geometry(name + "_interwires", interBoneWires));
    }

    this.setQueueBucket(Bucket.Transparent);
}
 
Example #6
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates buffers for points. Each line has POINT_AMOUNT of points.
 * @param skeleton
 *            the skeleton that will be showed
 * @param boneLengths
 *            the lengths of the bones
 */
public SkeletonInterBoneWire(Skeleton skeleton, Map<Integer, Float> boneLengths) {
    this.skeleton = skeleton;

    for (Bone bone : skeleton.getRoots()) {
        this.countConnections(bone);
    }

    this.setMode(Mode.Points);
    this.boneLengths = boneLengths;

    VertexBuffer pb = new VertexBuffer(Type.Position);
    FloatBuffer fpb = BufferUtils.createFloatBuffer(POINT_AMOUNT * connectionsAmount * 3);
    pb.setupData(Usage.Stream, 3, Format.Float, fpb);
    this.setBuffer(pb);

    this.updateCounts();
}
 
Example #7
Source File: SkeletonDebugger.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SkeletonDebugger(String name, Skeleton skeleton){
    super(name);

    this.skeleton = skeleton;
    wires = new SkeletonWire(skeleton);
    points = new SkeletonPoints(skeleton);

    attachChild(new Geometry(name+"_wires", wires));
    attachChild(new Geometry(name+"_points", points));

    setQueueBucket(Bucket.Transparent);
}
 
Example #8
Source File: AnimationBoneTrackTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected String computeName() {
    final BoneTrack boneTrack = getElement();
    final AnimControl control = notNull(getControl());
    final Skeleton skeleton = control.getSkeleton();
    final Bone bone = skeleton.getBone(boneTrack.getTargetBoneIndex());
    return "Bone track : " + bone.getName();
}
 
Example #9
Source File: SkeletonPoints.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SkeletonPoints(Skeleton skeleton){
    this.skeleton = skeleton;

    setMode(Mode.Points);

    VertexBuffer pb = new VertexBuffer(Type.Position);
    FloatBuffer fpb = BufferUtils.createFloatBuffer(skeleton.getBoneCount() * 3);
    pb.setupData(Usage.Stream, 3, Format.Float, fpb);
    setBuffer(pb);

    setPointSize(7);

    updateCounts();
}
 
Example #10
Source File: ArmatureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method returns the index of the bone in the given skeleton.
 * 
 * @param skeleton
 *            the skeleton
 * @param boneName
 *            the name of the bone
 * @return the index of the bone
 */
private int getBoneIndex(Skeleton skeleton, String boneName) {
    int result = -1;
    for (int i = 0; i < skeleton.getBoneCount() && result == -1; ++i) {
        if (boneName.equals(skeleton.getBone(i).getName())) {
            result = i;
        }
    }
    return result;
}
 
Example #11
Source File: ArmatureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method retuns the bone tracks for animation for blender version 2.50
 * and higher.
 * 
 * @param actionStructure
 *            the structure containing the tracks
 * @param blenderContext
 *            the blender context
 * @return a list of tracks for the specified animation
 * @throws BlenderFileException
 *             an exception is thrown when there are problems with the blend
 *             file
 */
private BoneTrack[] getTracks250(Structure actionStructure, Skeleton skeleton, BlenderContext blenderContext) throws BlenderFileException {
    LOGGER.log(Level.FINE, "Getting tracks!");
    IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
    int fps = blenderContext.getBlenderKey().getFps();
    Structure groups = (Structure) actionStructure.getFieldValue("groups");
    List<Structure> actionGroups = groups.evaluateListBase(blenderContext);// bActionGroup
    List<BoneTrack> tracks = new ArrayList<BoneTrack>();
    for (Structure actionGroup : actionGroups) {
        String name = actionGroup.getFieldValue("name").toString();
        int boneIndex = this.getBoneIndex(skeleton, name);
        if (boneIndex >= 0) {
            List<Structure> channels = ((Structure) actionGroup.getFieldValue("channels")).evaluateListBase(blenderContext);
            BezierCurve[] bezierCurves = new BezierCurve[channels.size()];
            int channelCounter = 0;
            for (Structure c : channels) {
                int type = ipoHelper.getCurveType(c, blenderContext);
                Pointer pBezTriple = (Pointer) c.getFieldValue("bezt");
                List<Structure> bezTriples = pBezTriple.fetchData(blenderContext.getInputStream());
                bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
            }

            Bone bone = skeleton.getBone(boneIndex);
            Ipo ipo = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
            tracks.add((BoneTrack) ipo.calculateTrack(boneIndex, bone.getLocalRotation(), 0, ipo.getLastFrame(), fps, false));
        }
    }
    return tracks.toArray(new BoneTrack[tracks.size()]);
}
 
Example #12
Source File: PMDPhysicsWorld.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addPMDNode(PMDNode pmdNode) {
        Skeleton skeleton = pmdNode.getSkeleton();
        skeleton.updateWorldVectors();
        PMDModel pmdModel = pmdNode.getPmdModel();
        PMDRigidBody[] rigidBodyArray = new PMDRigidBody[pmdModel.getRigidBodyList().getRigidBodyArray().length];
        rigidBodyMap.put(pmdNode, rigidBodyArray);
        for (int i = 0; i < pmdModel.getRigidBodyList().getRigidBodyArray().length; i++) {
            projectkyoto.mmd.file.PMDRigidBody fileRigidBody =
                    pmdModel.getRigidBodyList().getRigidBodyArray()[i];
            Bone bone = null;
            if (fileRigidBody.getRelBoneIndex() != 0xffff) {
                bone = skeleton.getBone(fileRigidBody.getRelBoneIndex());
            }
            PMDRigidBody rb = createRigidBody(pmdNode, fileRigidBody, bone);
            rigidBodyArray[i] = rb;

//            btWorld.addRigidBody(rb, (short) (1 << fileRigidBody.getRigidBodyGroupIndex()),
//                    (short) fileRigidBody.getRigidBodyGroupTarget());
            rb.setCollisionGroup(1 << (fileRigidBody.getRigidBodyGroupIndex()));
//            if (fileRigidBody.getRigidBodyName().contains("スカート")) {
//                rb.setCollideWithGroups(1 << 7);
//            } else {
                rb.setCollideWithGroups(fileRigidBody.getRigidBodyGroupTarget());
//            }
//                  rb.setCollideWithGroups(0 );
            physicsSpace.addCollisionObject(rb);
        }
        SixDofJoint constArray[] = new SixDofJoint[pmdModel.getJointList().getJointCount()];
        constraintMap.put(pmdNode, constArray);
        for (int i = 0; i < constArray.length; i++) {
            SixDofJoint constraint = createConstraint(pmdNode,
                    rigidBodyArray, pmdModel.getJointList().getJointArray()[i]);
            constArray[i] = constraint;
            physicsSpace.add(constraint);
        }
        nodeRigidBodyArray = rigidBodyMap.values().toArray(new PMDRigidBody[rigidBodyMap.size()][]);
//        physicsSpace.update(1 / 60f, 1);
    }
 
Example #13
Source File: PhysicsControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void initRigidBodyArray() {
    Skeleton skeleton = pmdNode.getSkeleton();
    PMDModel pmdModel = pmdNode.getPmdModel();
    rigidBodyArray = new PMDRigidBody[pmdModel.getRigidBodyList().getRigidBodyArray().length];
    for (int i = 0; i < pmdModel.getRigidBodyList().getRigidBodyArray().length; i++) {
        projectkyoto.mmd.file.PMDRigidBody fileRigidBody =
                pmdModel.getRigidBodyList().getRigidBodyArray()[i];
        Bone bone = skeleton.getBone(fileRigidBody.getRelBoneIndex());
        PMDRigidBody rb = createRigidBody(fileRigidBody, bone);
        rigidBodyArray[i] = rb;
    }
}
 
Example #14
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<Integer> getBoneIndices(Bone bone, Skeleton skeleton, Set<String> boneList) {
    List<Integer> list = new LinkedList<Integer>();
    if (boneList.isEmpty()) {
        list.add(skeleton.getBoneIndex(bone));
    } else {
        list.add(skeleton.getBoneIndex(bone));
        for (Bone chilBone : bone.getChildren()) {
            if (!boneList.contains(chilBone.getName())) {
                list.addAll(getBoneIndices(chilBone, skeleton, boneList));
            }
        }
    }
    return list;
}
 
Example #15
Source File: FbxLimbNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Skeleton createSkeleton(FbxNode skeletonHolderNode) {
    if (skeletonHolderNode instanceof FbxLimbNode) {
        throw new UnsupportedOperationException("Limb nodes cannot be skeleton holders");
    }
    
    List<Bone> bones = new ArrayList<Bone>();
    
    for (FbxNode child : skeletonHolderNode.getChildren()) {
        if (child instanceof FbxLimbNode) {
            createBones(skeletonHolderNode, (FbxLimbNode) child, bones);
        }
    }
    
    return new Skeleton(bones.toArray(new Bone[0]));
}
 
Example #16
Source File: RagdollUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enumerate the bone indices of the specified bone and all its descendents.
 *
 * @param bone the input bone (not null)
 * @param skeleton the skeleton containing the bone (not null)
 * @param boneList a set of bone names (not null, unaffected)
 *
 * @return a new list (not null)
 */
public static List<Integer> getBoneIndices(Bone bone, Skeleton skeleton, Set<String> boneList) {
    List<Integer> list = new LinkedList<Integer>();
    if (boneList.isEmpty()) {
        list.add(skeleton.getBoneIndex(bone));
    } else {
        list.add(skeleton.getBoneIndex(bone));
        for (Bone chilBone : bone.getChildren()) {
            if (!boneList.contains(chilBone.getName())) {
                list.addAll(getBoneIndices(chilBone, skeleton, boneList));
            }
        }
    }
    return list;
}
 
Example #17
Source File: FbxMesh.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void applyCluster(FbxCluster cluster) {
    if (boneIndices == null) {
        boneIndices = new ArrayList[positions.length];
        boneWeights = new ArrayList[positions.length];
    }
    
    FbxLimbNode limb = cluster.getLimb();
    Bone bone = limb.getJmeBone();
    Skeleton skeleton = limb.getSkeletonHolder().getJmeSkeleton();
    int boneIndex = skeleton.getBoneIndex(bone);
    
    int[] positionIndices = cluster.getVertexIndices();
    double[] weights = cluster.getWeights();
    
    for (int i = 0; i < positionIndices.length; i++) {
        int positionIndex = positionIndices[i];
        float boneWeight = (float)weights[i];
        
        ArrayList<Integer> boneIndicesForVertex = boneIndices[positionIndex];
        ArrayList<Float>  boneWeightsForVertex = boneWeights[positionIndex];
        
        if (boneIndicesForVertex == null) {
            boneIndicesForVertex = new ArrayList<Integer>();
            boneWeightsForVertex = new ArrayList<Float>();
            boneIndices[positionIndex] = boneIndicesForVertex;
            boneWeights[positionIndex] = boneWeightsForVertex;
        }
        
        boneIndicesForVertex.add(boneIndex);
        boneWeightsForVertex.add(boneWeight);
    }
}
 
Example #18
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<Integer> getBoneIndices(Bone bone, Skeleton skeleton, Set<String> boneList) {
    List<Integer> list = new LinkedList<Integer>();
    if (boneList.isEmpty()) {
        list.add(skeleton.getBoneIndex(bone));
    } else {
        list.add(skeleton.getBoneIndex(bone));
        for (Bone chilBone : bone.getChildren()) {
            if (!boneList.contains(chilBone.getName())) {
                list.addAll(getBoneIndices(chilBone, skeleton, boneList));
            }
        }
    }
    return list;
}
 
Example #19
Source File: ModelPerformer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void updateBoneCoords(ModelActor actor) {
	AnimControl ctrl = actor.getViewElements().spatial.getControl(AnimControl.class);
	if(ctrl == null) {
		return;
	}
	Skeleton sk = ctrl.getSkeleton();
	for (int i = 0; i < sk.getBoneCount(); i++) {
		Bone b = sk.getBone(i);
		actor.setBone(b.getName(), getBoneWorldPos(actor, i));
	}
}
 
Example #20
Source File: PMDNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Skeleton getSkeleton() {
    return skeleton;
}
 
Example #21
Source File: FbxNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setSkeleton(Skeleton skeleton) {
	if(bone != null)
		boneIndex = skeleton.getBoneIndex(bone);
}
 
Example #22
Source File: AnimData.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public AnimData(Skeleton skeleton, ArrayList<Animation> anims) {
    this.skeleton = skeleton;
    this.anims = anims;
}
 
Example #23
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);
}
 
Example #24
Source File: FbxNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Skeleton getJmeSkeleton() {
    return skeleton;
}
 
Example #25
Source File: PMDNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void read(JmeImporter e) throws IOException {
        super.read(e);
        InputCapsule c = e.getCapsule(this);
        pmdModel = (PMDModel)SavableUtil.read(c, "pmdModel", null);
        skeleton = (Skeleton)c.readSavable("skeleton", null);
        skinMap = (Map<String, Skin>)c.readStringSavableMap("skinMap", new HashMap<String, Savable>());
//        skinBoneWeightArray = c.readFloatArray("skinBoneWeightArray", new float[0]);
//        skinBoneArray = c.readIntArray("skinBoneArray", new int[0]);
        edgeSize = c.readFloat("edgeSize", 1.0f);
        int pmdGeometryArrayLength = c.readInt("pmdGeometryArrayLength", 0);
        pmdGeometryArray = new PMDGeometry[pmdGeometryArrayLength];
        targets = new PMDMesh[pmdGeometryArrayLength];
        int skinTargetsLength = c.readInt("skinTargetsLength", 0);
        skinTargets = new PMDSkinMesh[skinTargetsLength];
        VertexBuffer skinvb = (VertexBuffer)c.readSavable("skinvb", null);
        VertexBuffer skinnb = (VertexBuffer)c.readSavable("skinnb", null);
        VertexBuffer skintb = (VertexBuffer)c.readSavable("skintb", null);
        VertexBuffer skinvb2 = skinvb.clone();
        VertexBuffer skinnb2 = skinnb.clone();
        int meshCount = 0;
        int skinMeshCount = 0;
            for(Spatial sp : getChildren()) {
                Spatial newSp = sp;//.clone();
//                newPMDNode.attachChild(newSp);
                if (sp instanceof PMDGeometry) {
                    Mesh mesh = ((Geometry)newSp).getMesh();
                    if (mesh instanceof PMDMesh) {
                        PMDMesh pmdMesh = (PMDMesh)mesh;
                        pmdMesh.setVbBackup(pmdMesh.getBuffer(Type.Position));
                        pmdMesh.setNbBackup(pmdMesh.getBuffer(Type.Normal));
                        pmdGeometryArray[meshCount] = (PMDGeometry)sp;
                        targets[meshCount++] = (PMDMesh)mesh;
                    } else if (mesh instanceof PMDSkinMesh) {
//                        mesh.setMode(Mesh.Mode.Triangles);
                        PMDSkinMesh skinMesh = (PMDSkinMesh)mesh;
                        if (skinMeshCount != 0) {
                            skinMesh.setBuffer(skinvb);
                            skinMesh.setSkinvb2(skinvb2);
                            skinMesh.setBuffer(skinnb);
//                            skinMesh.setSkinnb2(skinnb2);
                            skinMesh.setBuffer(skintb);
                        } else {
                            skinMesh.setBuffer(skinvb);
                            skinMesh.setSkinvb2(skinvb2);
                            skinMesh.setBuffer(skinnb);
//                            skinMesh.setSkinnb2(skinnb2);
                            skinMesh.setBuffer(skintb);
                        }
                        skinTargets[skinMeshCount++] = (PMDSkinMesh)mesh;
                    }
                }
            }
            calcOffsetMatrices();
            Savable[] sa = c.readSavableArray("skinArray", new Skin[0]);
            skinArray = new Skin[sa.length];
            for(int i=0;i<sa.length;i++) {
                Skin skin = (Skin)sa[i];
                skinArray[i] = skin;
                skin.pmdNode = this;
                l2:
                for(int i2=0;i2<pmdModel.getSkinCount();i2++){
                    if (pmdModel.getSkinData()[i2].getSkinName().equals(skin.getSkinName())) {
//                        skin.skinData = pmdModel.getSkinData()[i2];
                        break l2;
                    }
                }
                skin.setWeight(0f);
                skin.setUpdateNeeded(true);
                skinMap.put(skin.skinName, skin);
            }
//            skinPosArray = (javax.vecmath.Vector3f[])SavableUtil.read(c, "skinPosArray", null);
//            skinPosArrayOrig = new javax.vecmath.Vector3f[skinPosArray.length];
//            for(int i=0;i<skinPosArray.length;i++) {
//                skinPosArrayOrig[i] = new javax.vecmath.Vector3f(skinPosArray[i]);
//            }
//            skinNormalArray = (javax.vecmath.Vector3f[])SavableUtil.read(c, "skinNormalArray", null);
//            skinNormalArrayOrig = new javax.vecmath.Vector3f[skinNormalArray.length];
//            for(int i=0;i<skinNormalArray.length;i++) {
//                skinNormalArrayOrig[i] = new javax.vecmath.Vector3f(skinNormalArray[i]);
//            }
//            skinBoneArray = c.readIntArray("skinBoneArray", skinBoneArray);
//            skinBoneWeightArray = c.readFloatArray("skinBoneWeightArray", skinBoneWeightArray);
    }
 
Example #26
Source File: BoneContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @return the skeleton the bone of this context belongs to
 */
public Skeleton getSkeleton() {
    return blenderContext.getSkeleton(armatureObjectOMA);
}
 
Example #27
Source File: AnimationData.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public AnimationData(Skeleton skeleton, List<Animation> anims) {
    this.skeleton = skeleton;
    this.anims = anims;
}
 
Example #28
Source File: PMDNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setSkeleton(Skeleton skeleton) {
    this.skeleton = skeleton;
}
 
Example #29
Source File: ArmatureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * This method retuns the bone tracks for animation.
 * 
 * @param actionStructure
 *            the structure containing the tracks
 * @param blenderContext
 *            the blender context
 * @return a list of tracks for the specified animation
 * @throws BlenderFileException
 *             an exception is thrown when there are problems with the blend
 *             file
 */
public BoneTrack[] getTracks(Structure actionStructure, Skeleton skeleton, BlenderContext blenderContext) throws BlenderFileException {
    if (blenderVersion < 250) {
        return this.getTracks249(actionStructure, skeleton, blenderContext);
    } else {
        return this.getTracks250(actionStructure, skeleton, blenderContext);
    }
}
 
Example #30
Source File: ArmatureModifier.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * This method reads mesh indexes
 * 
 * @param objectStructure
 *            structure of the object that has the armature modifier applied
 * @param meshStructure
 *            the structure of the object's mesh
 * @param blenderContext
 *            the blender context
 * @throws BlenderFileException
 *             this exception is thrown when the blend file structure is
 *             somehow invalid or corrupted
 */
private VertexBuffer[] readVerticesWeightsData(Structure objectStructure, Structure meshStructure, Skeleton skeleton, int materialIndex, int[] bonesGroups, BlenderContext blenderContext) throws BlenderFileException {
    ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class);
    Structure defBase = (Structure) objectStructure.getFieldValue("defbase");
    Map<Integer, Integer> groupToBoneIndexMap = armatureHelper.getGroupToBoneIndexMap(defBase, skeleton, blenderContext);

    MeshContext meshContext = blenderContext.getMeshContext(meshStructure.getOldMemoryAddress());

    return this.getBoneWeightAndIndexBuffer(meshStructure, meshContext.getVertexCount(materialIndex), bonesGroups, meshContext.getVertexReferenceMap(materialIndex), groupToBoneIndexMap, blenderContext);
}