Java Code Examples for com.jme3.export.InputCapsule#readSavableArray()

The following examples show how to use com.jme3.export.InputCapsule#readSavableArray() . 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: DacConfiguration.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * De-serialize this control, for example when loading from a J3O file.
 *
 * @param im importer (not null)
 * @throws IOException from importer
 */
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);

    damping = ic.readFloat("damping", 0.6f);
    eventDispatchImpulseThreshold
            = ic.readFloat("eventDispatchImpulseThreshold", 0f);

    jointMap.clear();
    blConfigMap.clear();
    String[] linkedBoneNames = ic.readStringArray("linkedBoneNames", null);
    Savable[] linkedBoneJoints
            = ic.readSavableArray("linkedBoneJoints", null);
    float[] blConfigs = ic.readFloatArray("blConfigs", null);
    for (int i = 0; i < linkedBoneNames.length; ++i) {
        String boneName = linkedBoneNames[i];
        RangeOfMotion rom = (RangeOfMotion) linkedBoneJoints[i];
        jointMap.put(boneName, rom);
        blConfigMap.put(boneName, blConfigs[i]);
    }

    torsoMass = ic.readFloat("torsoMass", 1f);
    gravityVector = (Vector3f) ic.readSavable("gravity", null);
}
 
Example 2
Source File: RagUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Read an array of transforms from an input capsule.
 *
 * @param capsule the input capsule (not null)
 * @param fieldName the name of the field to read (not null)
 * @return a new array or null
 * @throws IOException from capsule
 */
static Transform[] readTransformArray(InputCapsule capsule,
        String fieldName) throws IOException {
    Savable[] tmp = capsule.readSavableArray(fieldName, null);
    Transform[] result;
    if (tmp == null) {
        result = null;
    } else {
        result = new Transform[tmp.length];
        for (int i = 0; i < tmp.length; ++i) {
            result[i] = (Transform) tmp[i];
        }
    }

    return result;
}
 
Example 3
Source File: BoneLink.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * De-serialize this link, for example when loading from a J3O file.
 *
 * @param im importer (not null)
 * @throws IOException from importer
 */
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);

    Savable[] tmp = ic.readSavableArray("managedBones", null);
    if (tmp == null) {
        managedBones = null;
    } else {
        managedBones = new Joint[tmp.length];
        for (int i = 0; i < tmp.length; ++i) {
            managedBones[i] = (Joint) tmp[i];
        }
    }

    submode = ic.readEnum("submode", KinematicSubmode.class,
            KinematicSubmode.Animated);
    prevBoneTransforms = RagUtils.readTransformArray(ic,
            "prevBoneTransforms");
    startBoneTransforms = RagUtils.readTransformArray(ic,
            "startBoneTransforms");
}
 
Example 4
Source File: TorsoLink.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * De-serialize this link, for example when loading from a J3O file.
 *
 * @param im importer (not null)
 * @throws IOException from importer
 */
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);

    Savable[] tmp = ic.readSavableArray("managedBones", null);
    if (tmp == null) {
        managedBones = null;
    } else {
        managedBones = new Joint[tmp.length];
        for (int i = 0; i < tmp.length; ++i) {
            managedBones[i] = (Joint) tmp[i];
        }
    }

    submode = ic.readEnum("submode", KinematicSubmode.class,
            KinematicSubmode.Animated);
    endModelTransform = (Transform) ic.readSavable("endModelTransform",
            new Transform());
    meshToModel
            = (Transform) ic.readSavable("meshToModel", new Transform());
    startModelTransform = (Transform) ic.readSavable("startModelTransform",
            new Transform());
    prevBoneTransforms = RagUtils.readTransformArray(ic,
            "prevBoneTransforms");
    startBoneTransforms = RagUtils.readTransformArray(ic,
            "startBoneTransforms");
}
 
Example 5
Source File: InstancedGeometry.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter importer) throws IOException {
    super.read(importer);
    InputCapsule capsule = importer.getCapsule(this);
    //currentNumInstances = capsule.readInt("cur_num_instances", 1);

    Savable[] geometrySavables = capsule.readSavableArray("geometries", null);
    geometries = new Geometry[geometrySavables.length];
    for (int i = 0; i < geometrySavables.length; i++) {
        geometries[i] = (Geometry) geometrySavables[i];
    }
}
 
Example 6
Source File: BitmapFont.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    charSet = (BitmapCharacterSet) ic.readSavable("charSet", null);
    Savable[] pagesSavable = ic.readSavableArray("pages", null);
    pages = new Material[pagesSavable.length];
    System.arraycopy(pagesSavable, 0, pages, 0, pages.length);
}
 
Example 7
Source File: BitmapCharacterSet.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private IntMap<BitmapCharacter> readCharset(InputCapsule ic, int style) throws IOException {
    IntMap<BitmapCharacter> charset = new IntMap<BitmapCharacter>();
    short[] indexes = ic.readShortArray("indexes"+style, null);
    Savable[] chars = ic.readSavableArray("chars"+style, null);

    for (int i = 0; i < indexes.length; i++){
        int index = indexes[i] & 0xFFFF;
        BitmapCharacter chr = (BitmapCharacter) chars[i];
        charset.put(index, chr);
    }
    return charset;
}
 
Example 8
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);
    }