Search in sources :

Example 11 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project Terasology by MovingBlocks.

the class GLTFAnimationFormat method load.

@Override
public MeshAnimationBundleData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (Reader in = new InputStreamReader(inputs.get(0).openStream())) {
        GLTF gltf = gson.fromJson(in, GLTF.class);
        checkVersionSupported(urn, gltf);
        List<byte[]> loadedBuffers = loadBinaryBuffers(urn, gltf);
        if (gltf.getSkins().isEmpty()) {
            throw new IOException("Skeletal mesh '" + urn + "' missing skin");
        }
        GLTFSkin skin = gltf.getSkins().get(0);
        List<String> boneNames = Lists.newArrayList();
        TIntList boneParents = new TIntArrayList();
        TIntIntMap nodeToJoint = new TIntIntHashMap();
        for (int i = 0; i < skin.getJoints().size(); i++) {
            nodeToJoint.put(skin.getJoints().get(i), i);
        }
        List<Bone> bones = loadBones(gltf, skin, loadedBuffers);
        bones.forEach(x -> boneNames.add(x.getName()));
        bones.forEach(x -> {
            if (x.getParentIndex() != -1) {
                boneParents.add(x.getParentIndex());
            } else {
                boneParents.add(MeshAnimationData.NO_PARENT);
            }
        });
        Map<ResourceUrn, MeshAnimationData> animations = new HashMap<>();
        for (int index = 0; index < gltf.getAnimations().size(); ++index) {
            GLTFAnimation gltfAnimation = gltf.getAnimations().get(index);
            String name = gltfAnimation.getName();
            if (Strings.isNullOrEmpty(name)) {
                name = "anim_" + index;
            }
            animations.put(new ResourceUrn(urn, name), loadAnimation(gltf, gltfAnimation, loadedBuffers, nodeToJoint, boneNames, boneParents, bones));
        }
        return new MeshAnimationBundleData(animations);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) MeshAnimationBundleData(org.terasology.engine.rendering.assets.animation.MeshAnimationBundleData) IOException(java.io.IOException) TIntArrayList(gnu.trove.list.array.TIntArrayList) TIntIntMap(gnu.trove.map.TIntIntMap) GLTFSkin(org.terasology.engine.rendering.gltf.model.GLTFSkin) GLTF(org.terasology.engine.rendering.gltf.model.GLTF) MeshAnimationData(org.terasology.engine.rendering.assets.animation.MeshAnimationData) Bone(org.terasology.engine.rendering.assets.skeletalmesh.Bone) TIntList(gnu.trove.list.TIntList) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) GLTFAnimation(org.terasology.engine.rendering.gltf.model.GLTFAnimation)

Example 12 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project Terasology by MovingBlocks.

the class GLTFCommonFormat method loadBones.

protected List<Bone> loadBones(GLTF gltf, GLTFSkin skin, List<byte[]> loadedBuffers) {
    List<Bone> bones = new ArrayList<>();
    TIntIntMap boneToJoint = new TIntIntHashMap();
    List<Matrix4f> inverseMats = loadInverseMats(skin.getInverseBindMatrices(), skin.getJoints().size(), gltf, loadedBuffers);
    for (int i = 0; i < skin.getJoints().size(); i++) {
        int nodeIndex = skin.getJoints().get(i);
        GLTFNode node = gltf.getNodes().get(nodeIndex);
        Vector3f position = new Vector3f();
        Quaternionf rotation = new Quaternionf();
        Vector3f scale = new Vector3f(1, 1, 1);
        if (node.getTranslation() != null) {
            position.set(node.getTranslation());
        }
        if (node.getRotation() != null) {
            rotation.set(node.getRotation());
        }
        if (node.getScale() != null) {
            scale.set(node.getScale());
        }
        String boneName = node.getName();
        if (Strings.isNullOrEmpty(boneName)) {
            boneName = "bone_" + i;
        }
        Bone bone = new Bone(i, boneName, new Matrix4f().translationRotateScale(position, rotation, scale));
        bone.setInverseBindMatrix(inverseMats.get(i));
        bones.add(bone);
        boneToJoint.put(nodeIndex, i);
    }
    for (int i = 0; i < skin.getJoints().size(); i++) {
        int nodeIndex = skin.getJoints().get(i);
        GLTFNode node = gltf.getNodes().get(nodeIndex);
        Bone bone = bones.get(i);
        TIntIterator iterator = node.getChildren().iterator();
        while (iterator.hasNext()) {
            bone.addChild(bones.get(boneToJoint.get(iterator.next())));
        }
    }
    return bones;
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TFloatArrayList(gnu.trove.list.array.TFloatArrayList) Quaternionf(org.joml.Quaternionf) TIntIntMap(gnu.trove.map.TIntIntMap) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) GLTFNode(org.terasology.engine.rendering.gltf.model.GLTFNode) Bone(org.terasology.engine.rendering.assets.skeletalmesh.Bone) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 13 with TIntIntMap

use of gnu.trove.map.TIntIntMap in project GregTech by GregTechCE.

the class MetaBlockIdRemapCache method deserialize.

public static MetaBlockIdRemapCache deserialize(String newNamePrefix, NBTTagCompound tag) {
    int[] idMapSer = tag.getIntArray(KEY_ID_MAPPING);
    TIntIntMap idToIndex = new TIntIntHashMap(idMapSer.length, 1.1F, -1, -1);
    TIntIntMap indexToId = new TIntIntHashMap(idMapSer.length, 1.1F, -1, -1);
    for (int entrySer : idMapSer) {
        // 26-bit block ID, 6-bit meta block index
        int id = (entrySer & SER_MASK_ID) >>> 6;
        int index = entrySer & SER_MASK_INDEX;
        idToIndex.put(id, index);
        indexToId.put(index, id);
    }
    return new MetaBlockIdRemapCache(newNamePrefix, idToIndex, indexToId);
}
Also used : TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) TIntIntMap(gnu.trove.map.TIntIntMap)

Aggregations

TIntIntMap (gnu.trove.map.TIntIntMap)13 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)6 Test (org.junit.Test)4 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)4 Graph (org.opentripplanner.routing.graph.Graph)4 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)4 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)3 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)3 GenericLocation (org.opentripplanner.common.model.GenericLocation)3 AStar (org.opentripplanner.routing.algorithm.AStar)3 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 BitSet (java.util.BitSet)2 LocalDate (org.joda.time.LocalDate)2 TaskStatistics (org.opentripplanner.analyst.cluster.TaskStatistics)2 ProfileRequest (org.opentripplanner.profile.ProfileRequest)2 RaptorWorkerData (org.opentripplanner.profile.RaptorWorkerData)2 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)2 State (org.opentripplanner.routing.core.State)2 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)2