系统自带的3D模型控件

先自定义SCNView和SCNScene用来作为模型展示的view和场景。

@property (nonatomic,strong) SCNView *QFSceneView;
@property (nonatomic,strong) SCNScene *QFSenePlace;
//声明3D场景
    self.QFSceneView = [[SCNView alloc]init];
    _QFSceneView.allowsCameraControl = YES;//用户可以控制摄像机
    _QFSceneView.showsStatistics = YES;//控制下方的统计栏是否显示
    [self.view addSubview:_QFSceneView];
    _QFSceneView.sd_layout.spaceToSuperView(UIEdgeInsetsMake(NavBarHeight, 0, 0, 0));
    //声明场景中的模型对象
    self.QFSenePlace = [SCNScene scene];
    _QFSceneView.scene = _QFSenePlace;
    _QFSceneView.autoenablesDefaultLighting = true;

将系统的3D模型控件放到根节点处展示出来

//构建3D模型
        self.createNode = [[CreateTreeNode alloc]init];
SCNNode *_model = [_createNode createTreeModel];
        [_QFSenePlace.rootNode addChildNode:model];

下面开始介绍绘制的模型结构
1.绘制方块

SCNNode *present = [SCNNode nodeWithGeometry:[SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0]];
    present.geometry.firstMaterial.diffuse.contents = QFBlueColor;
    present.position = SCNVector3Make(2, -2, 2);
    present.name = @"树下面的方块";
    [_model addChildNode:present];

2.绘制SCNPyramid

SCNNode *pyramidNode = [SCNNode nodeWithGeometry:[SCNPyramid pyramidWithWidth:2 height:2 length:2]];
    pyramidNode.geometry.firstMaterial.diffuse.contents = QFYellowColor;
    pyramidNode.position = SCNVector3Make(-2, -2, -2);
    pyramidNode.name = @"三角锥";
    [_model addChildNode:pyramidNode];

3.绘制SCNSphere

SCNNode *sphereNode = [SCNNode nodeWithGeometry:[SCNSphere sphereWithRadius:1]];
    sphereNode.geometry.firstMaterial.diffuse.contents = QFRedColor;
    sphereNode.position = SCNVector3Make(-2, -1, 2);
    sphereNode.name = @"球体";
    [_model addChildNode:sphereNode];

4.绘制SCNCone

SCNNode *coneNode = [SCNNode nodeWithGeometry:[SCNCone coneWithTopRadius:0.5 bottomRadius:1 height:2]];
    coneNode.geometry.firstMaterial.diffuse.contents = QFBlackColor;
    coneNode.position = SCNVector3Make(2, -1, -2);
    coneNode.name = @"锥柱体";
    [_model addChildNode:coneNode];

5.绘制SCNTube

SCNNode *tubeNode = [SCNNode nodeWithGeometry:[SCNTube tubeWithInnerRadius:0.5 outerRadius:1 height:2]];
    tubeNode.geometry.firstMaterial.diffuse.contents = QFGrayColor;
    tubeNode.position = SCNVector3Make(3, 3, 3);
    tubeNode.name = @"环柱体";
    [_model addChildNode:tubeNode];

6.绘制SCNCapsule

SCNNode *capsuleNode = [SCNNode nodeWithGeometry:[SCNCapsule capsuleWithCapRadius:1 height:2]];
    capsuleNode.geometry.firstMaterial.diffuse.contents = QFDarkGrayColor;
    capsuleNode.position = SCNVector3Make(3, 3, -3);
    capsuleNode.name = @"跟球看着一样";
    [_model addChildNode:capsuleNode];

7.绘制SCNTorus

SCNNode *torusNode = [SCNNode nodeWithGeometry:[SCNTorus torusWithRingRadius:1 pipeRadius:0.5]];
    torusNode.geometry.firstMaterial.diffuse.contents = QFLightGrayColor;
    torusNode.position = SCNVector3Make(-3, 3, 3);
    torusNode.name = @"游泳圈";
    [_model addChildNode:torusNode];

8.绘制SCNText

SCNText *scnText = [SCNText textWithString:@"自构3D模型" extrusionDepth:0.5];
    scnText.font = [UIFont systemFontOfSize:2];
    SCNNode *textNode = [SCNNode nodeWithGeometry:scnText];
    textNode.geometry.firstMaterial.diffuse.contents = QFOrangeColor;
    textNode.position = SCNVector3Make(-5, 8, -5);
    textNode.name = @"3D文字";
    [_model addChildNode:textNode];
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
HelixViewport3D 控件是 WPF 3D 绘图控件,可以用来展示三维模型。要获取或设置模型在 HelixViewport3D 控件中的旋转角度,可以通过修改 HelixViewport3D 的 Camera 属性来实现。 首先,需要获取 HelixViewport3D 控件的 Camera 对象: ```csharp var camera = myHelixViewport3D.Camera; ``` 然后可以使用 Camera 的属性来获取或设置相机的位置、朝向和旋转角度等信息。例如,要获取当前相机的旋转角度,可以使用 Camera 的 LookDirection 和 UpDirection 属性来计算出相机的旋转矩阵,然后从矩阵中提取旋转角度: ```csharp var rotationMatrix = new Matrix3D( camera.LookDirection.X, camera.LookDirection.Y, camera.LookDirection.Z, 0, camera.UpDirection.X, camera.UpDirection.Y, camera.UpDirection.Z, 0, 0, 0, 1, 0, 0, 0, 0, 1); var rotationQuaternion = rotationMatrix.ToQuaternion(); var rotationAngle = rotationQuaternion.Angle; ``` 其中,ToQuaternion() 方法是一个扩展方法,用于将旋转矩阵转换为四元数,Angle 属性则表示四元数的旋转角度。 要设置模型的旋转角度,可以直接修改相机的 LookDirection 和 UpDirection 属性,或者使用 RotateTransform3D 对象来构造一个旋转变换,并将其应用到相机的 Transform 属性中: ```csharp // 直接修改相机的 LookDirection 和 UpDirection 属性 camera.LookDirection = new Vector3D(0, 0, -1); camera.UpDirection = new Vector3D(0, 1, 0); // 使用 RotateTransform3D 构造一个旋转变换 var rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 45)); // 将旋转变换应用到相机的 Transform 属性中 camera.Transform = rotation; ``` 这样就可以实现对 HelixViewport3D 控件模型的旋转角度的获取和设置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值