本文整理汇总了Java中com.jme3.scene.Mesh.prepareForAnim方法的典型用法代码示例。如果您正苦于以下问题:Java Mesh.prepareForAnim方法的具体用法?Java Mesh.prepareForAnim怎么用?Java Mesh.prepareForAnim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.scene.Mesh
的用法示例。
在下文中一共展示了Mesh.prepareForAnim方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetToBind
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
void resetToBind() {
for (Mesh mesh : targets){
if (isMeshAnimated(mesh)) {
VertexBuffer bi = mesh.getBuffer(Type.BoneIndex);
ByteBuffer bib = (ByteBuffer) bi.getData();
if (!bib.hasArray()) {
mesh.prepareForAnim(true); // prepare for software animation
}
VertexBuffer bindPos = mesh.getBuffer(Type.BindPosePosition);
VertexBuffer bindNorm = mesh.getBuffer(Type.BindPoseNormal);
VertexBuffer pos = mesh.getBuffer(Type.Position);
VertexBuffer norm = mesh.getBuffer(Type.Normal);
FloatBuffer pb = (FloatBuffer) pos.getData();
FloatBuffer nb = (FloatBuffer) norm.getData();
FloatBuffer bpb = (FloatBuffer) bindPos.getData();
FloatBuffer bnb = (FloatBuffer) bindNorm.getData();
pb.clear();
nb.clear();
bpb.clear();
bnb.clear();
pb.put(bpb).clear();
nb.put(bnb).clear();
}
}
}
示例2: trySwitchToHardware
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
/**
* 打开skin的hws,如果角色actor主SkeletonControl已经打开该功能,则该方法将偿试打开skinNode的hws以配合角色骨骼.
* @param actor
* @param skinNode
*/
public static void trySwitchToHardware(Entity actor, Spatial skinNode) {
// 如果hsw未打开,则不需要管,交由sc内部去一起处理就可以.
SkeletonControl sc = actor.getSpatial().getControl(SkeletonControl.class);
if (!sc.isHardwareSkinningUsed()) {
return;
}
// 如果hsw已经开启过了,则需要把skinNode处理后再添加到actor中,否则skinNode将无法启用hsw
final Set<Mesh> targets = new HashSet<Mesh>();
final Set<Material> materials = new HashSet<Material>();
Node tempNode = new Node();
tempNode.attachChild(skinNode);
findTargets(tempNode, targets, materials);
// Next full 10 bones (e.g. 30 on 24 bones)
Skeleton skeleton = sc.getSkeleton();
int numBones = ((skeleton.getBoneCount() / 10) + 1) * 10;
for (Material m : materials) {
m.setInt("NumberOfBones", numBones);
}
for (Mesh mesh : targets) {
if (mesh.isAnimated()) {
mesh.prepareForAnim(false);
}
}
sc.setSpatial(actor.getSpatial());
}
示例3: redirectBoneIndex
import com.jme3.scene.Mesh; //导入方法依赖的package包/类
public static void redirectBoneIndex(String outfitFile, String rigSkeFile) {
AssetManager am = LuoYing.getAssetManager();
Spatial outfit = am.loadModel(outfitFile);
if (outfit.getUserData(REDIRECT_BONE_INDEX_OK) != null) {
logger.log(Level.WARNING, "Outfit name={0} has already Redirect bone index!", outfit.getName());
return;
}
AnimControl outfitAC = outfit.getControl(AnimControl.class);
SkeletonControl outfitSC = outfit.getControl(SkeletonControl.class);
if (outfitSC == null) {
return;
}
// 移除control
outfit.removeControl(outfitAC);
outfit.removeControl(outfitSC);
// 重定向boneIndex
Skeleton rigSke = am.loadModel(rigSkeFile).getControl(SkeletonControl.class).getSkeleton();
// skin中可能存在多个Geometry,每一个都要进行处理.
List<Geometry> geos = GeometryUtils.findAllGeometry(outfit);
Skeleton outfitSke = outfitSC.getSkeleton(); // skin中的骨骼(已丢弃)
for (Geometry geo : geos) {
// 找到Mesh中的骨骼索引
// 这里需要检测并初始化一次就可以, 不能重复做,即使skin是重新load进来的
// 因为geometry或mesh可能进行了缓存,所以即使重新Loader.loadSkin(),可能
// 载入的对象仍然引用相同的mesh.所以这里需要通过判断,避免对skin mesh
// 中的骨骼索引重定向多次,只有第一次是正确的,第二次及后续一定错误,因为数据覆盖了.
Mesh mesh = geo.getMesh();
logger.log(Level.INFO, "==MaxNumWeights={0}", mesh.getMaxNumWeights());
VertexBuffer indices = mesh.getBuffer(VertexBuffer.Type.BoneIndex);
if (!indices.getData().hasArray()) {
// Prepares the mesh for software skinning by converting the bone index and weight buffers to heap buffers.
// 另参考: SkeletonControl => void resetToBind()
mesh.prepareForAnim(true);
}
// 重定向
ByteBuffer ib = (ByteBuffer) indices.getData();
ib.rewind();
byte[] fib = ib.array();
for (int i = 0; i < fib.length; i++) {
int bIndex = fib[i] & 0xff; // bIndex是skin中子骨骼
// 这里一般不会发生, 除非做了第二次骨骼索引的重定向,
// 否则skin中的初始骨骼索引不可能会大于或等于它的骨骼数(最大索引为BoneCount-1)
if (bIndex >= outfitSke.getBoneCount()) {
logger.log(Level.WARNING, "SkinSke bone index big than boneCount, bIndex={0}, totalBone={1}"
, new Object[] {bIndex, outfitSke.getBoneCount()});
continue;
}
String boneName = outfitSke.getBone(bIndex).getName();
// 从父骨骼中找出与skin中当前骨头相同名称的骨头.
int rootBoneIndex = rigSke.getBoneIndex(boneName);
if (rootBoneIndex != -1) {
logger.log(Level.INFO, "update bone index, skin={0}, index update: {1} to {2}"
, new Object[]{outfit.getName(), fib[i], rootBoneIndex});
fib[i] = (byte) rootBoneIndex;
} else {
// 如果skinNode中的骨骼没有在父骨骼中找到,则随便直接绑定到父骨骼的根节点中.
// 出现这种情况主要是skin中存在额外的骨骼,这个骨头不知道要绑定到哪里?!!?
fib[i] = 0;
logger.log(Level.WARNING, "SkinSke found a extra bone, but not know where to bind to! boneName={0}"
, boneName);
}
}
indices.updateData(ib);
}
outfit.setUserData(REDIRECT_BONE_INDEX_OK, "1");
ModelFileUtils.saveTo(outfit, outfitFile);
}