像演员一样随时间翻译模型?
Translate model over time like actor?
我最近开始学习 LibGDX 并且喜欢 Actor 系统在 moving/fading/rotating 方面的简单性。很简单!但是,进入 3d,我想知道是否有类似的实现方式。
我看到有人说 "instance.transform(x,y,z)",但它会立即应用并显示在下一个渲染中。我想知道我是否可以使用一些内置框架来插入该转换 "model.addAction(moveTo(x,y,z), duration(0.4f));" 我知道 Model 不像 scene2d 中的大多数元素那样从 Actor 继承。当涉及到上述模型的骨骼动画和导入动画时,我了解当前的动画框架,但我正在寻找一种解决方案,可以在我的游戏世界中移动我的模型,而无需在渲染中执行大量依赖逻辑.
有没有一种方法可以在模型上使用 Action 框架,而不是用自定义插值实现来打乱我的渲染循环?只是像平移、旋转等东西(如果没有,我可能会沿着模型对象上实现动作、池等的路径。)
谢谢!
一个快速而肮脏的技巧是在旁边使用 scene2d 的动作系统。创建一个没有演员的舞台。您可以将您的动作直接发送到舞台并每帧调用一次 stage.update(delta);
来处理您的所有动作。您无需绘制舞台即可执行此操作。 (无论如何,您可能会想要一个 2D UI 东西的舞台。)
您需要创建自己的操作。由于舞台不适用于 3D,因此没有理由尝试使用 Actors。您的 Action 可以直接应用于舞台进行处理,并且设计为不针对任何 Actor。
这是一个示例(未经测试)。由于您主要关注随着时间的推移混合内容,因此您可能会从 TemporalAction 扩展大部分操作。
public class MoveVector3ToAction extends TemporalAction {
private Vector3 target;
private float startX, startY, startZ, endX, endY, endZ;
protected void begin(){
startX = target.x;
startY = target.y;
startZ = target.z;
}
protected void update (float percent) {
target.set(startX + (endX - startX) * percent, startY + (endY - startY) * percent, startZ + (endZ - startZ) * percent);
}
public void reset(){
super.reset();
target = null; //must clear reference for pooling purposes
}
public void setTarget(Vector3 target){
this.target = target;
}
public void setPosition(float x, float y, float z){
endX = x;
endY = y;
endZ = z;
}
}
您可以创建一个类似于 Actions class 的便利工具 class,以便轻松设置使用自动池生成您的操作:
public class MyActions {
public static MoveVector3ToAction moveVector3To (Vector3 target, float x, float y, float z, float duration){
return moveVector3To(target, x, y, z, duration, null);
}
public static MoveVector3ToAction moveVector3To (Vector3 target, float x, float y, float z, float duration, Interpolation interpolation){
MoveVector3ToAction action = Actions.action(MoveVector3ToAction.class);
action.setTarget(target);
action.setPosition(x, y, z);
action.setDuration(duration);
action.setInterpolation(interpolation);
return action;
}
}
示例用法。 ModelInstances 移动起来有点棘手,因为您必须使用它们的 Matrix4 变换来完成它,但您不能安全地返回位置或旋转或缩小变换。所以你需要保留一个单独的 Vector3 位置和四元数旋转,并将它们应用于每一帧以更新实例的变换。
//Static import MyActions to avoid needing to type "MyActions" over and over.
import static com.mydomain.mygame.MyActions.*;
//To move some ModelInstance
stage.addAction(moveVector3To(myInstancePosition, 10, 10, 10, 1f, Interpolation.pow2));
//In render():
stage.update(delta);
myInstance.transform.set(myInstancePosition, myInstanceRotation);
我最近开始学习 LibGDX 并且喜欢 Actor 系统在 moving/fading/rotating 方面的简单性。很简单!但是,进入 3d,我想知道是否有类似的实现方式。
我看到有人说 "instance.transform(x,y,z)",但它会立即应用并显示在下一个渲染中。我想知道我是否可以使用一些内置框架来插入该转换 "model.addAction(moveTo(x,y,z), duration(0.4f));" 我知道 Model 不像 scene2d 中的大多数元素那样从 Actor 继承。当涉及到上述模型的骨骼动画和导入动画时,我了解当前的动画框架,但我正在寻找一种解决方案,可以在我的游戏世界中移动我的模型,而无需在渲染中执行大量依赖逻辑.
有没有一种方法可以在模型上使用 Action 框架,而不是用自定义插值实现来打乱我的渲染循环?只是像平移、旋转等东西(如果没有,我可能会沿着模型对象上实现动作、池等的路径。)
谢谢!
一个快速而肮脏的技巧是在旁边使用 scene2d 的动作系统。创建一个没有演员的舞台。您可以将您的动作直接发送到舞台并每帧调用一次 stage.update(delta);
来处理您的所有动作。您无需绘制舞台即可执行此操作。 (无论如何,您可能会想要一个 2D UI 东西的舞台。)
您需要创建自己的操作。由于舞台不适用于 3D,因此没有理由尝试使用 Actors。您的 Action 可以直接应用于舞台进行处理,并且设计为不针对任何 Actor。
这是一个示例(未经测试)。由于您主要关注随着时间的推移混合内容,因此您可能会从 TemporalAction 扩展大部分操作。
public class MoveVector3ToAction extends TemporalAction {
private Vector3 target;
private float startX, startY, startZ, endX, endY, endZ;
protected void begin(){
startX = target.x;
startY = target.y;
startZ = target.z;
}
protected void update (float percent) {
target.set(startX + (endX - startX) * percent, startY + (endY - startY) * percent, startZ + (endZ - startZ) * percent);
}
public void reset(){
super.reset();
target = null; //must clear reference for pooling purposes
}
public void setTarget(Vector3 target){
this.target = target;
}
public void setPosition(float x, float y, float z){
endX = x;
endY = y;
endZ = z;
}
}
您可以创建一个类似于 Actions class 的便利工具 class,以便轻松设置使用自动池生成您的操作:
public class MyActions {
public static MoveVector3ToAction moveVector3To (Vector3 target, float x, float y, float z, float duration){
return moveVector3To(target, x, y, z, duration, null);
}
public static MoveVector3ToAction moveVector3To (Vector3 target, float x, float y, float z, float duration, Interpolation interpolation){
MoveVector3ToAction action = Actions.action(MoveVector3ToAction.class);
action.setTarget(target);
action.setPosition(x, y, z);
action.setDuration(duration);
action.setInterpolation(interpolation);
return action;
}
}
示例用法。 ModelInstances 移动起来有点棘手,因为您必须使用它们的 Matrix4 变换来完成它,但您不能安全地返回位置或旋转或缩小变换。所以你需要保留一个单独的 Vector3 位置和四元数旋转,并将它们应用于每一帧以更新实例的变换。
//Static import MyActions to avoid needing to type "MyActions" over and over.
import static com.mydomain.mygame.MyActions.*;
//To move some ModelInstance
stage.addAction(moveVector3To(myInstancePosition, 10, 10, 10, 1f, Interpolation.pow2));
//In render():
stage.update(delta);
myInstance.transform.set(myInstancePosition, myInstanceRotation);