Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented support for unlooped animations, and an AnimEndEvent.

Moved rendering components and systems into the rendering package.
Added a NOTICE file.
  • Loading branch information...
commit fc7ee307dedad8fd8fcd03614ac30a92166f5c21 1 parent b5a4dac
@immortius immortius authored
Showing with 123 additions and 46 deletions.
  1. +5 −0 NOTICE
  2. +1 −1  src/main/java/org/terasology/componentSystem/controllers/LocalPlayerSystem.java
  3. +1 −1  src/main/java/org/terasology/entityFactory/DroppedBlockFactory.java
  4. +1 −1  src/main/java/org/terasology/entityFactory/GelatinousCubeFactory.java
  5. +3 −0  src/main/java/org/terasology/entitySystem/EntityManager.java
  6. +17 −0 src/main/java/org/terasology/entitySystem/pojo/PojoEntityManager.java
  7. +7 −4 src/main/java/org/terasology/logic/commands/Commands.java
  8. +1 −1  src/main/java/org/terasology/logic/console/GroovyManager.java
  9. +1 −1  src/main/java/org/terasology/mods/miniions/componentsystem/entityfactory/MiniionFactory.java
  10. +35 −0 src/main/java/org/terasology/rendering/logic/AnimEndEvent.java
  11. +1 −1  src/main/java/org/terasology/{components/rendering → rendering/logic}/MeshComponent.java
  12. +2 −2 src/main/java/org/terasology/{componentSystem/rendering → rendering/logic}/MeshRenderer.java
  13. +1 −1  src/main/java/org/terasology/{components/rendering → rendering/logic}/SkeletalMeshComponent.java
  14. +46 −32 src/main/java/org/terasology/{componentSystem/rendering → rendering/logic}/SkeletonRenderer.java
  15. +1 −1  src/main/java/org/terasology/rendering/world/WorldRenderer.java
View
5 NOTICE
@@ -0,0 +1,5 @@
+ Terasology
+ Copyright 2011-2012 MovingBlocks
+
+ This product includes software developed by
+ MovingBlocks (http://www.movingblocks.net/).
View
2  src/main/java/org/terasology/componentSystem/controllers/LocalPlayerSystem.java
@@ -23,7 +23,7 @@
import org.terasology.rendering.gui.widgets.UIImage;
import org.terasology.world.block.BlockComponent;
import org.terasology.world.block.BlockItemComponent;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entityFactory.DroppedBlockFactory;
import org.terasology.entitySystem.EntityManager;
View
2  src/main/java/org/terasology/entityFactory/DroppedBlockFactory.java
@@ -18,7 +18,7 @@
import javax.vecmath.Vector3f;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.utility.LifespanComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entitySystem.EntityManager;
View
2  src/main/java/org/terasology/entityFactory/GelatinousCubeFactory.java
@@ -17,7 +17,7 @@
import javax.vecmath.Vector3f;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entitySystem.EntityManager;
import org.terasology.entitySystem.EntityRef;
View
3  src/main/java/org/terasology/entitySystem/EntityManager.java
@@ -17,6 +17,7 @@
import java.util.Map;
+import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import org.terasology.entitySystem.metadata.ComponentLibrary;
@@ -71,6 +72,8 @@
*/
EntityRef create(Prefab prefab, Vector3f position);
+ EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation);
+
/**
* @param other
* @return A new entity with a copy of each of the other entity's components
View
17 src/main/java/org/terasology/entitySystem/pojo/PojoEntityManager.java
@@ -29,6 +29,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import org.terasology.components.world.LocationComponent;
@@ -133,6 +134,22 @@ public EntityRef create(String prefabName, Vector3f position) {
}
@Override
+ public EntityRef create(Prefab prefab, Vector3f position, Quat4f rotation) {
+ List<Component> components = Lists.newArrayList();
+ for (Component component : prefab.listComponents()) {
+ Component newComp = componentLibrary.copy(component);
+ components.add(newComp);
+ if (newComp instanceof LocationComponent) {
+ LocationComponent loc = (LocationComponent) newComp;
+ loc.setWorldPosition(position);
+ loc.setWorldRotation(rotation);
+ }
+ }
+ components.add(new EntityInfoComponent(prefab.getName()));
+ return create(components);
+ }
+
+ @Override
public EntityRef create(Prefab prefab, Vector3f position) {
List<Component> components = Lists.newArrayList();
for (Component component : prefab.listComponents()) {
View
11 src/main/java/org/terasology/logic/commands/Commands.java
@@ -22,8 +22,10 @@
import java.util.Iterator;
import java.util.List;
+import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
+import com.bulletphysics.linearmath.QuaternionUtil;
import org.lwjgl.input.Keyboard;
import org.terasology.asset.Asset;
import org.terasology.asset.AssetManager;
@@ -33,7 +35,7 @@
import org.terasology.components.ItemComponent;
import org.terasology.components.PlayerComponent;
import org.terasology.components.SimpleAIComponent;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entityFactory.BlockItemFactory;
import org.terasology.entitySystem.EntityManager;
@@ -384,13 +386,14 @@ public void AZERTY() {
public void spawnPrefab(String prefabName) {
Camera camera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
Vector3f spawnPos = camera.getPosition();
- Vector3f offset = camera.getViewingDirection();
- offset.scale(3);
+ Vector3f offset = new Vector3f(camera.getViewingDirection());
+ offset.scale(2);
spawnPos.add(offset);
+ Quat4f rotation = QuaternionUtil.shortestArcQuat(new Vector3f(0,0,1), camera.getViewingDirection() , new Quat4f());
Prefab prefab = CoreRegistry.get(PrefabManager.class).getPrefab(prefabName);
if (prefab != null && prefab.getComponent(LocationComponent.class) != null) {
- CoreRegistry.get(EntityManager.class).create(prefab, spawnPos);
+ CoreRegistry.get(EntityManager.class).create(prefab, spawnPos, rotation);
}
}
View
2  src/main/java/org/terasology/logic/console/GroovyManager.java
@@ -32,7 +32,7 @@
import org.terasology.components.ItemComponent;
import org.terasology.components.PlayerComponent;
import org.terasology.components.SimpleAIComponent;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entityFactory.BlockItemFactory;
import org.terasology.entitySystem.EntityManager;
View
2  src/main/java/org/terasology/mods/miniions/componentsystem/entityfactory/MiniionFactory.java
@@ -17,7 +17,7 @@
import javax.vecmath.Vector3f;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entitySystem.EntityManager;
import org.terasology.entitySystem.EntityRef;
View
35 src/main/java/org/terasology/rendering/logic/AnimEndEvent.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 Benjamin Glatzel <benjamin.glatzel@me.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.terasology.rendering.logic;
+
+import org.terasology.entitySystem.AbstractEvent;
+import org.terasology.rendering.assets.animation.MeshAnimation;
+
+/**
+ * @author Immortius
+ */
+public class AnimEndEvent extends AbstractEvent {
+ private MeshAnimation animation;
+
+ public AnimEndEvent(MeshAnimation animation) {
+ this.animation = animation;
+ }
+
+ public MeshAnimation getAnimation() {
+ return animation;
+ }
+}
View
2  ...y/components/rendering/MeshComponent.java → ...sology/rendering/logic/MeshComponent.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.terasology.components.rendering;
+package org.terasology.rendering.logic;
import javax.vecmath.Color4f;
View
4 ...mponentSystem/rendering/MeshRenderer.java → ...asology/rendering/logic/MeshRenderer.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.terasology.componentSystem.rendering;
+package org.terasology.rendering.logic;
import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
import static org.lwjgl.opengl.GL11.GL_NORMAL_ARRAY;
@@ -55,7 +55,7 @@
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.terasology.componentSystem.RenderSystem;
-import org.terasology.components.rendering.MeshComponent;
+import org.terasology.rendering.logic.MeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entitySystem.EntityManager;
import org.terasology.entitySystem.EntityRef;
View
2  ...ents/rendering/SkeletalMeshComponent.java → ...endering/logic/SkeletalMeshComponent.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.terasology.components.rendering;
+package org.terasology.rendering.logic;
import org.terasology.entitySystem.Component;
import org.terasology.entitySystem.EntityRef;
View
78 ...entSystem/rendering/SkeletonRenderer.java → ...ogy/rendering/logic/SkeletonRenderer.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.terasology.componentSystem.rendering;
+package org.terasology.rendering.logic;
import com.bulletphysics.linearmath.QuaternionUtil;
import com.bulletphysics.linearmath.Transform;
@@ -24,7 +24,8 @@
import org.lwjgl.opengl.GL11;
import org.terasology.componentSystem.RenderSystem;
import org.terasology.componentSystem.UpdateSubscriberSystem;
-import org.terasology.components.rendering.SkeletalMeshComponent;
+import org.terasology.rendering.assets.animation.MeshAnimation;
+import org.terasology.rendering.logic.SkeletalMeshComponent;
import org.terasology.components.world.LocationComponent;
import org.terasology.entitySystem.EntityManager;
import org.terasology.entitySystem.EntityRef;
@@ -34,7 +35,6 @@
import org.terasology.entitySystem.event.AddComponentEvent;
import org.terasology.game.CoreRegistry;
import org.terasology.logic.LocalPlayer;
-import org.terasology.logic.manager.ShaderManager;
import org.terasology.rendering.assets.animation.MeshAnimationFrame;
import org.terasology.rendering.assets.skeletalmesh.Bone;
import org.terasology.rendering.world.WorldRenderer;
@@ -47,11 +47,7 @@
import java.util.logging.Logger;
import static org.lwjgl.opengl.GL11.glBegin;
-import static org.lwjgl.opengl.GL11.glColor4f;
-import static org.lwjgl.opengl.GL11.glDisable;
-import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEnd;
-import static org.lwjgl.opengl.GL11.glLineWidth;
import static org.lwjgl.opengl.GL11.glMultMatrix;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
@@ -109,37 +105,33 @@ public void newSkeleton(AddComponentEvent event, EntityRef entity) {
@Override
public void update(float delta) {
- Vector3f newPos = new Vector3f();
- Quat4f newRot = new Quat4f();
-
for (EntityRef entity : entityManager.iteratorEntities(SkeletalMeshComponent.class, LocationComponent.class)) {
SkeletalMeshComponent skeletalMeshComp = entity.getComponent(SkeletalMeshComponent.class);
- LocationComponent loc = entity.getComponent(LocationComponent.class);
if (skeletalMeshComp.animation != null && skeletalMeshComp.animation.getFrameCount() > 0) {
skeletalMeshComp.animationTime += delta * skeletalMeshComp.animationRate;
float framePos = skeletalMeshComp.animationTime / skeletalMeshComp.animation.getTimePerFrame();
- while ((int) framePos >= skeletalMeshComp.animation.getFrameCount()) {
- framePos -= skeletalMeshComp.animation.getFrameCount();
- }
- int frameId = (int) framePos;
- MeshAnimationFrame frameA = skeletalMeshComp.animation.getFrame(frameId);
- MeshAnimationFrame frameB = skeletalMeshComp.animation.getFrame((frameId + 1) % skeletalMeshComp.animation.getFrameCount());
- float interpolationVal = framePos - frameId;
-
- for (int i = 0; i < skeletalMeshComp.animation.getBoneCount(); ++i) {
- EntityRef boneEntity = skeletalMeshComp.boneEntities.get(skeletalMeshComp.animation.getBoneName(i));
- if (boneEntity == null) {
- continue;
+
+ if (skeletalMeshComp.loop) {
+ while ((int) framePos >= skeletalMeshComp.animation.getFrameCount()) {
+ framePos -= skeletalMeshComp.animation.getFrameCount();
+ skeletalMeshComp.animationTime -= skeletalMeshComp.animation.getTimePerFrame() * skeletalMeshComp.animation.getFrameCount();
}
- LocationComponent boneLoc = boneEntity.getComponent(LocationComponent.class);
- if (boneLoc != null) {
-
- newPos.interpolate(frameA.getPosition(i), frameB.getPosition(i), interpolationVal);
- boneLoc.setLocalPosition(newPos);
- newRot.interpolate(frameA.getRotation(i), frameB.getRotation(i), interpolationVal);
- newRot.normalize();
- boneLoc.setLocalRotation(newRot);
- boneEntity.saveComponent(boneLoc);
+ int frameId = (int) framePos;
+ MeshAnimationFrame frameA = skeletalMeshComp.animation.getFrame(frameId);
+ MeshAnimationFrame frameB = skeletalMeshComp.animation.getFrame((frameId + 1) % skeletalMeshComp.animation.getFrameCount());
+ updateSkeleton(skeletalMeshComp, frameA, frameB, framePos - frameId);
+ } else {
+ if ((int) framePos >= skeletalMeshComp.animation.getFrameCount()) {
+ updateSkeleton(skeletalMeshComp, skeletalMeshComp.animation.getFrame(skeletalMeshComp.animation.getFrameCount() - 1), skeletalMeshComp.animation.getFrame(skeletalMeshComp.animation.getFrameCount() - 1), 1.0f);
+ MeshAnimation animation = skeletalMeshComp.animation;
+ skeletalMeshComp.animationTime = 0;
+ skeletalMeshComp.animation = null;
+ entity.send(new AnimEndEvent(animation));
+ } else {
+ int frameId = (int) framePos;
+ MeshAnimationFrame frameA = skeletalMeshComp.animation.getFrame(frameId);
+ MeshAnimationFrame frameB = (frameId + 1 >= skeletalMeshComp.animation.getFrameCount()) ? frameA : skeletalMeshComp.animation.getFrame(frameId + 1);
+ updateSkeleton(skeletalMeshComp, frameA, frameB, framePos - frameId);
}
}
entity.saveComponent(skeletalMeshComp);
@@ -147,6 +139,28 @@ public void update(float delta) {
}
}
+ private void updateSkeleton(SkeletalMeshComponent skeletalMeshComp, MeshAnimationFrame frameA, MeshAnimationFrame frameB, float interpolationVal) {
+ Vector3f newPos = new Vector3f();
+ Quat4f newRot = new Quat4f();
+
+ for (int i = 0; i < skeletalMeshComp.animation.getBoneCount(); ++i) {
+ EntityRef boneEntity = skeletalMeshComp.boneEntities.get(skeletalMeshComp.animation.getBoneName(i));
+ if (boneEntity == null) {
+ continue;
+ }
+ LocationComponent boneLoc = boneEntity.getComponent(LocationComponent.class);
+ if (boneLoc != null) {
+
+ newPos.interpolate(frameA.getPosition(i), frameB.getPosition(i), interpolationVal);
+ boneLoc.setLocalPosition(newPos);
+ newRot.interpolate(frameA.getRotation(i), frameB.getRotation(i), interpolationVal);
+ newRot.normalize();
+ boneLoc.setLocalRotation(newRot);
+ boneEntity.saveComponent(boneLoc);
+ }
+ }
+ }
+
@Override
public void renderOpaque() {
boolean carryingTorch = CoreRegistry.get(LocalPlayer.class).isCarryingTorch();
View
2  src/main/java/org/terasology/rendering/world/WorldRenderer.java
@@ -59,7 +59,7 @@
import org.lwjgl.opengl.GL11;
import org.terasology.componentSystem.RenderSystem;
import org.terasology.componentSystem.controllers.LocalPlayerSystem;
-import org.terasology.componentSystem.rendering.MeshRenderer;
+import org.terasology.rendering.logic.MeshRenderer;
import org.terasology.components.PlayerComponent;
import org.terasology.entitySystem.EntityManager;
import org.terasology.game.ComponentSystemManager;
Please sign in to comment.
Something went wrong with that request. Please try again.