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