qt使用assimp加载模型_iOS使用assimpKit加载FBX模型步骤详解

本文详细介绍了如何在iOS应用中使用AssimpKit库加载FBX模型,包括加载模型、设置纹理和法线、绘制骨骼动画等步骤,并解决了在集成过程中遇到的动态库、Bitcode设置及动画播放问题。
摘要由CSDN通过智能技术生成

研究背景

体积:一个.dae模型大概有1M那么大 而.fbx模型0.5M

现状

xcode现在不能直接读取.fbx模型

方案

1.使用assimpKit加载

2.使用Wish3D加载

结果

1.使用assimpKit--可行

2.使用Wish3D-- 官方文档有问题,然后咨询还不回复----直接丢弃

原理

1.读取模型的 顶点坐标 纹理坐标 法线 骨骼顶点 骨骼动画

2.调用以下方法画出模型

根据顶点坐标和模型类型画出模型,模型类型可以是点、线、三角形

为什么是三角形呢?因为三角形是最小边几何图形

+ (instancetype)geometrySourceWithVertices:(const SCNVector3 *)vertices count:(NSInteger)count;

3.调用以下方法设置纹理

+ (instancetype)geometrySourceWithNormals:(const SCNVector3 *)normals count:(NSInteger)count;

用以下方法设置模型图片 就是设置node的纹理

SCNGeometry *geo = [SCNGeometry geometryWithSources:sources elements:elements];

UIImage * image = [UIImage imageNamed:@"xy.jpg"];

SCNMaterial *mat = [SCNMaterial material];

mat.diffuse.contents = image;

geo.firstMaterial = mat;

geo.firstMaterial.doubleSided = YES;

4.调用以下方法画出法线

+ (instancetype)geometrySourceWithTextureCoordinates:(const CGPoint *)texcoord count:(NSInteger)count;

5.调用以下方法画出骨骼顶点

+ (instancetype)geometrySourceWithData:(NSData *)data semantic:(SCNGeometrySourceSemantic)semantic vectorCount:(NSInteger)vectorCount floatComponents:(BOOL)floatComponents componentsPerVector:(NSInteger)componentsPerVector bytesPerComponent:(NSInteger)bytesPerComponent dataOffset:(NSInteger)offset dataStride:(NSInteger)stride;

6.调用以下方法设置与骨骼顶点向连接的部分

+ (instancetype)geometrySourceWithData:(NSData *)data semantic:(SCNGeometrySourceSemantic)semantic vectorCount:(NSInteger)vectorCount floatComponents:(BOOL)floatComponents componentsPerVector:(NSInteger)componentsPerVector bytesPerComponent:(NSInteger)bytesPerComponent dataOffset:(NSInteger)offset dataStride:(NSInteger)stride;

7.调用以下方法设置骨骼动画皮肤那方面的

+ (instancetype)geometrySourceWithData:(NSData *)data semantic:(SCNGeometrySourceSemantic)semantic vectorCount:(NSInteger)vectorCount floatComponents:(BOOL)floatComponents componentsPerVector:(NSInteger)componentsPerVector bytesPerComponent:(NSInteger)bytesPerComponent dataOffset:(NSInteger)offset dataStride:(NSInteger)stride

8.调用以下方法设置把骨骼相信存放到一个SCNSkinner类

+ (instancetype)skinnerWithBaseGeometry:(nullable SCNGeometry *)baseGeometry bones:(NSArray *)bones boneInverseBindTransforms:(nullable NSArray *)boneInverseBindTransforms boneWeights:(SCNGeometrySource *)boneWeights boneIndices:(SCNGeometrySource *)boneIndices API_AVAILABLE(macos(10.10));

9.调用以下方法设置骨骼动画的值和类型

+ (SCNAction *)repeatActionForever:(SCNAction *)action;

10.调用以下方法运行骨骼动画

- (void)runAction:(SCNAction *)action API_AVAILABLE(macos(10.10));

把assimpKit接入项目

1.到 assimpKit 下载 文件

文件很大的 要找到ios的

2.把assimpKit.frame 拖入工程里

image.png

3.把下面的文件导入工程里

image.png

image.png

4.然后再设置动态库 (不是静态)

image.png

还有

image.png

如果出现了

"_compress", referenced from:

“_uncompress", referenced from:

"_compress2", referenced from:

"_inflateReset", referenced from:

"inflateInit", referenced from:

"_inflateEnd", referenced from:

"inflateInit2", referenced from:

有两种解决方法

image.png

这个可以添加多个的 就是本来有其他的xxx 还是可以添加-lz的

image.png

主要是assimpKit里有.a 的压缩文件 我们要添加压缩的库区解压

5.设置bitcode为no

image.png

开发中遇到的问题

1.加载fbx模型的动画 只有部分节点有动画

2.控制动画的播放但动画结束的时候会很突兀

解决办法

1.查看源码 他是遍历到每个子节点然后把动画添加上去 但是有一些节点根本加不上去 所以我们需要改一下他的源码

image.png

当了这个bug他们开发团队也知道了 并且标为了bug

image.png

2.查看源码 发现他是没有用到fadeOutDuration这个属性 可能是遗留了

image.png

后记

assimpKit这个库 功能很强 虽然不是很成熟 但我们可以在他们基础上修改一下代码 来实现我们的功能 当然了 如果发现bug 还可以和他们开发团队提一下 让这个框架帮助更多的开发人员

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值