iOS开发之SceneKit框架--SCNScene.h

1、SCNScene

  SCNScene是一个场景图——具有附加几何形状、光照、摄像机和其他属性的节点的层次结构,共同形成可显示的3D场景。

 

2、相关API简介

  • 初始化方法
//懒加载
+ (instancetype)scene;

//name:3D文件的路径
+ (nullable instancetype)sceneNamed:(NSString *)name API_AVAILABLE(macos(10.9));

/**
 @param name 3D文件路径
 @param directory 要搜索的路径子目录的名称
 @param options 字典,相关秘钥记录在SCNSceneSource类中
 */
+ (nullable instancetype)sceneNamed:(NSString *)name inDirectory:(nullable NSString *)directory options:(nullable NSDictionary<SCNSceneSourceLoadingOption, id> *)options API_AVAILABLE(macos(10.10));

/**
 @param url 3D文件路径
 @param options 字典,相关秘钥记录在SCNSceneSource类中
 @param error 错误信息
 */
+ (nullable instancetype)sceneWithURL:(NSURL *)url options:(nullable NSDictionary<SCNSceneSourceLoadingOption, id> *)options error:(NSError **)error;
  • 控制场景的动画
//暂停场景将暂停动画、动作、粒子和物理。默认为NO。
@property(nonatomic, getter=isPaused) BOOL paused API_AVAILABLE(macos(10.10));
  • 获取场景内容
//获取根节点
@property(nonatomic, readonly) SCNNode *rootNode;

//获取背景
//背景在场景渲染之前出现
//通过设置SCNMaterialProperty.h 中描述的多维数据集映射,可以将背景渲染成天空盒
@property(nonatomic, readonly) SCNMaterialProperty *background API_AVAILABLE(macos(10.9));

//获取灯光环境
//环境应该是SCNMaterialProperty.h中所述的立方体映射
@property(nonatomic, readonly) SCNMaterialProperty *lightingEnvironment API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0));
  • 管理场景属性
//检索场景属性
- (nullable id)attributeForKey:(NSString *)key;

//设置场景属性
- (void)setAttribute:(nullable id)attribute forKey:(NSString *)key;
//场景属性
#if defined(SWIFT_SDK_OVERLAY2_SCENEKIT_EPOCH) && SWIFT_SDK_OVERLAY2_SCENEKIT_EPOCH >= 3
typedef NSString * SCNSceneAttribute NS_STRING_ENUM;
#else
typedef NSString * SCNSceneAttribute;
#endif
FOUNDATION_EXTERN SCNSceneAttribute const SCNSceneStartTimeAttributeKey;                          //一个浮点值,封装在NSNumber中,包含场景的开始时间
FOUNDATION_EXTERN SCNSceneAttribute const SCNSceneEndTimeAttributeKey;                            // 一个浮点值,封装在NSNumber中,包含场景的结束时间
FOUNDATION_EXTERN SCNSceneAttribute const SCNSceneFrameRateAttributeKey;                          // 一个浮点值,封装在NSNumber中,包含场景的帧速率
FOUNDATION_EXTERN SCNSceneAttribute const SCNSceneUpAxisAttributeKey API_AVAILABLE(macos(10.10)); //一个包含x,y,z向量[结构体]值,封装在NSValue中,包含场景的上轴.这仅仅是为了信息,设置上轴没有任何效果

#define SCNSceneAttributeStartTime SCNSceneStartTimeAttributeKey
#define SCNSceneAttributeEndTime   SCNSceneEndTimeAttributeKey
#define SCNSceneAttributeFrameRate SCNSceneFrameRateAttributeKey
#define SCNSceneAttributeUpAxis    SCNSceneUpAxisAttributeKey
  • 导出场景文件
/**
 将场景及其内容导出到指定URL的文件中。

 @param url 指定的URL
 @param options 一个字典选项.有效的key在"场景书写选项"部分中有所描述
 @param delegate 一个可选的代理,用于管理外部引用.例如图片
 @param API_UNAVAILABLE progressHandler(进度处理程序) 一个可选的块来处理操作的进度
 @return 如果操作成功就返回YES,否则就返回NO.错误检查可以通过"progressHandler"的"error"参数来完成.
 @讨论   macOS 10.10 和 更低的版本只支持导出 .DAE 文件.
        开启 macOS 10.11 支持导出 .dae, .scn 以及模型I/O支持的文件所有格式.
        开启 iOS 10 支持导出 .scn 以及模型I/O支持的文件所有格式.
 
 */
- (BOOL)writeToURL:(NSURL *)url options:(nullable NSDictionary<NSString *, id> *)options delegate:(nullable id <SCNSceneExportDelegate>)delegate progressHandler:(nullable SCNSceneExportProgressHandler)progressHandler API_AVAILABLE(macos(10.9), ios(10.0), tvos(10.0)) API_UNAVAILABLE(watchos);

/**
 场景导出期间调用的block块

 @param totalProgress 进度0-1
 @param error 错误信息
 @param stop 是否终止 设置*stop为YES停止
 */
typedef void (^SCNSceneExportProgressHandler)(float totalProgress, NSError * _Nullable error, BOOL *stop);
API_AVAILABLE(macos(10.9), ios(10.0), tvos(10.0)) API_UNAVAILABLE(watchos)
@protocol SCNSceneExportDelegate <NSObject>
@optional
/**
 在代理上调用写入引用的图像并返回目标网址

 @param image 这个图片是白色
 @param documentURL  这个URL是场景现在导出的
 @param API_UNAVAILABLE  图像的原始网址.如果图像之前未从网址加载,则可能为nil
 @return 委托必须返回导出的图像网址,如果未导出任何图像,则返回nil。 如果返回的值为nil,则图像将以默认格式导出到默认目标。
 */
- (nullable NSURL *)writeImage:(UIImage *)image withSceneDocumentURL:(NSURL *)documentURL originalImageURL:(nullable NSURL *)originalImageURL API_AVAILABLE(macos(10.9), ios(10.0), tvos(10.0)) API_UNAVAILABLE(watchos);
@end
//场景导出目标URL
FOUNDATION_EXTERN NSString * const SCNSceneExportDestinationURL API_AVAILABLE(macos(10.9));
  • 给场景添加雾
//开始雾距离
@property(nonatomic) CGFloat fogStartDistance API_AVAILABLE(macos(10.10));

//结束雾距离
@property(nonatomic) CGFloat fogEndDistance API_AVAILABLE(macos(10.10));

//雾密度指数
//(控制开始和结束雾距之间的衰减.0表示恒定雾,1表示线性雾,2表示二次雾,但任何正值都将起作用
@property(nonatomic) CGFloat fogDensityExponent API_AVAILABLE(macos(10.10));

//雾颜色、默认为白色
@property(nonatomic, retain) id fogColor API_AVAILABLE(macos(10.10));
  • 场景的物理信息
//物理世界
//每个场景自动创建一个物理世界对象,以模拟场景中节点上的物理现象.你可以使用此属性来访问场景的全局物理属性,例如重力.要向特定节点添加物理现象,请看physicsBody
@property(nonatomic, readonly) SCNPhysicsWorld *physicsWorld API_AVAILABLE(macos(10.10));

 

posted @ 2018-04-28 15:35  ForeverGuard  阅读(603)  评论(0编辑  收藏  举报