当前位置: 首页 > news >正文

深圳建设网站培训机构中国制造网网站特色

深圳建设网站培训机构,中国制造网网站特色,分销平台,ysl千色t9t9t9成全在​​Day 4​​​中我们使用了​​ImmersiveSpace​​并在其中添加了一个立方体#xff0c;但对这个立方体我们只配置了长宽高#xff0c;并没有做进一步的操作。 本文中我们会通过纹理和材质对这个立方体的六个面分别进行不同的绘制。首先我们将​​ImmersiveView​​分拆…在​​Day 4​​​中我们使用了​​ImmersiveSpace​​并在其中添加了一个立方体但对这个立方体我们只配置了长宽高并没有做进一步的操作。 本文中我们会通过纹理和材质对这个立方体的六个面分别进行不同的绘制。首先我们将​​ImmersiveView​​分拆出来先新建一个​​ImmersiveView.swift​​文件这是一个视图文件所以请选择User Interface下的Swift View完成创建其中的内容待我们编写完​​ViewModel​​中的代码后再进行修改。 我们通过点击界面来打开沉浸式视图所以需要一个​​ContentView.swift​​文件来编写常规的窗口页面在其中添加一个Toggle开关用于打开和关闭沉浸式视图。 import SwiftUI import RealityKitstruct ContentView: View {State var showImmsersiveSpace falseEnvironment(\.openImmersiveSpace) var openImmersiveSpaceEnvironment(\.dismissImmersiveSpace) var dismissImmersiveSpacevar body: some View {NavigationStack {VStack {Toggle(Show ImmersiveSpace, isOn: $showImmsersiveSpace).toggleStyle(.button)}.padding()}.onChange(of: showImmsersiveSpace) { _, newValue inTask {if newValue {await openImmersiveSpace(id: ImmersiveSpace)} else {await dismissImmersiveSpace()}}}} }#Preview {ContentView() } 首先我们定义了一个​​showImmsersiveSpace​​变量供Toggle按钮开关时使用。然后要打开和关闭沉浸式空间我们可以分别使用​​Environment​​中的​​openImmersiveSpace​​和​​dismissImmersiveSpace​​通过​​onChange​​修饰符来监控​​showImmsersiveSpace​​变量的变化在切换到打开时就打开沉浸式空间。我们需要知道打开哪一个视图所以使用了​​id​​参数这个参数应与应用入口文件中所设置的一致。 接下来就编写入口文件 import SwiftUImain struct visionOSDemoApp: App {var body: some Scene {WindowGroup() {ContentView()}ImmersiveSpace(id: ImmersiveSpace) {ImmersiveView()}} } 注意这里​​ImmersiveSpace​​中所添加的​​id​​与之前​​ContentView​​中的要保持一致我们在后面会学到在同一个应用中也可以添加多个​​WindowGroup​​同样通过配置​​id​​进行区分。 接下来是核心文件​​ViewModel.swift​​ import SwiftUI import RealityKitMainActor class ViewModel: ObservableObject {private var contentEntity Entity()func setupContentEntity() - Entity {return contentEntity}func addCube() {guardlet texture1 try? TextureResource.load(named: Number_1),let texture2 try? TextureResource.load(named: Number_2),let texture3 try? TextureResource.load(named: Number_3),let texture4 try? TextureResource.load(named: Number_4),let texture5 try? TextureResource.load(named: Number_5),let texture6 try? TextureResource.load(named: Number_6)else {fatalError(Unable to load texture.)}let entity Entity()var material1 SimpleMaterial()var material2 SimpleMaterial()var material3 SimpleMaterial()var material4 SimpleMaterial()var material5 SimpleMaterial()var material6 SimpleMaterial()material1.color .init(texture: .init(texture1))material2.color .init(texture: .init(texture2))material3.color .init(texture: .init(texture3))material4.color .init(texture: .init(texture4))material5.color .init(texture: .init(texture5))material6.color .init(texture: .init(texture6))entity.components.set(ModelComponent(mesh: .generateBox(width: 0.5, height: 0.5, depth: 0.5, splitFaces: true),materials: [material1, material2, material3, material4, material5, material6]))entity.position SIMD3(x: 0, y: 1, z: -2)contentEntity.addChild(entity)} } 同样我们创建了​​setupContentEntity()​​方法但并没有在方法里添加任何模型而是将添加的工作交给了​​addCube()​​方法整个方法虽然很长但有大量重复的代码分别为六个面设置不同的图片。 通过​​TextureResource.load()​​方法设置了不同的纹理接着使用​​SimpleMaterial()​​创建了六个材质通过材质的​​color​​属性分别添加前面配置好的纹理 ​​Number_1.jpg​​等图片请见我们GitHub的演示代码我们先来说一下visionOS中的材质常见的材质请见下图 其中​​PhysicallyBasedMaterial​​也即PBR和​​SimpleMaterial​​是带光照信息的而​​UnlitMaterial​​和​​VideoMaterial​​都是不带光照信息的。 在​​ModelComponent​​方法中我们使用了​​mesh​​和​​materials​​参数​​mesh​​参数我们同样使用了​​MeshResource.generateBox​​来创建一个立方体不同的是这次我们指定了​​splitFaces​​参数该参数设为​​true​​表示顶点不进行合并因为我们要对六个面分别设置颜色或图像不指定该参数六个面都会使用相同的材质在本例中也就是都显示为​​1​​。 最后我们配置了​​position​​这里x, y, z坐标轴方向示意如下 接下来我们修改​​ImmersiveView.swift​​的内容如下 import SwiftUI import RealityKitstruct ImmersiveView: View {StateObject var model ViewModel()private var contentEntity Entity()var body: some View {RealityView { content incontent.add(model.setupContentEntity())model.addCube()}} } 这里的代码相对简单就是在​​RealityView​​中展示​​ViewModel​​中所添加的模型。 在运行应用前将Info.plist文件中的Preferred Default Scene Session Role切换回Window Application Session Role。 点击Show ImmersiveSpace按钮会得到如下界面 再次点击按钮就会收起这个模型。 示例代码​​GitHub仓库​​ 其它相关内容请见​​虚拟现实(VR)/增强现实(AR)visionOS开发学习笔记​​
文章转载自:
http://www.morning.krqhw.cn.gov.cn.krqhw.cn
http://www.morning.qwbls.cn.gov.cn.qwbls.cn
http://www.morning.cldgh.cn.gov.cn.cldgh.cn
http://www.morning.3dcb8231.cn.gov.cn.3dcb8231.cn
http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn
http://www.morning.dmthy.cn.gov.cn.dmthy.cn
http://www.morning.nynyj.cn.gov.cn.nynyj.cn
http://www.morning.tjmfz.cn.gov.cn.tjmfz.cn
http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn
http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn
http://www.morning.xrftt.cn.gov.cn.xrftt.cn
http://www.morning.rui931.cn.gov.cn.rui931.cn
http://www.morning.nqlkb.cn.gov.cn.nqlkb.cn
http://www.morning.ghrlx.cn.gov.cn.ghrlx.cn
http://www.morning.rszwc.cn.gov.cn.rszwc.cn
http://www.morning.qjngk.cn.gov.cn.qjngk.cn
http://www.morning.hwbmn.cn.gov.cn.hwbmn.cn
http://www.morning.frpm.cn.gov.cn.frpm.cn
http://www.morning.drywd.cn.gov.cn.drywd.cn
http://www.morning.ydhck.cn.gov.cn.ydhck.cn
http://www.morning.wdnkp.cn.gov.cn.wdnkp.cn
http://www.morning.znkls.cn.gov.cn.znkls.cn
http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn
http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn
http://www.morning.fykqh.cn.gov.cn.fykqh.cn
http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn
http://www.morning.ykwqz.cn.gov.cn.ykwqz.cn
http://www.morning.dtgjt.cn.gov.cn.dtgjt.cn
http://www.morning.zqcgt.cn.gov.cn.zqcgt.cn
http://www.morning.pngfx.cn.gov.cn.pngfx.cn
http://www.morning.qbfkz.cn.gov.cn.qbfkz.cn
http://www.morning.wfttq.cn.gov.cn.wfttq.cn
http://www.morning.ydzly.cn.gov.cn.ydzly.cn
http://www.morning.wlbwp.cn.gov.cn.wlbwp.cn
http://www.morning.fhbhr.cn.gov.cn.fhbhr.cn
http://www.morning.jfxdy.cn.gov.cn.jfxdy.cn
http://www.morning.jzdfc.cn.gov.cn.jzdfc.cn
http://www.morning.pqkyx.cn.gov.cn.pqkyx.cn
http://www.morning.lffbz.cn.gov.cn.lffbz.cn
http://www.morning.ydnx.cn.gov.cn.ydnx.cn
http://www.morning.ttvtv.cn.gov.cn.ttvtv.cn
http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn
http://www.morning.rylr.cn.gov.cn.rylr.cn
http://www.morning.kyzxh.cn.gov.cn.kyzxh.cn
http://www.morning.jtybl.cn.gov.cn.jtybl.cn
http://www.morning.wnhml.cn.gov.cn.wnhml.cn
http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn
http://www.morning.shnqh.cn.gov.cn.shnqh.cn
http://www.morning.ffcsr.cn.gov.cn.ffcsr.cn
http://www.morning.nzzws.cn.gov.cn.nzzws.cn
http://www.morning.amlutsp.cn.gov.cn.amlutsp.cn
http://www.morning.kyzxh.cn.gov.cn.kyzxh.cn
http://www.morning.jltmb.cn.gov.cn.jltmb.cn
http://www.morning.yccnj.cn.gov.cn.yccnj.cn
http://www.morning.chzqy.cn.gov.cn.chzqy.cn
http://www.morning.drspc.cn.gov.cn.drspc.cn
http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn
http://www.morning.djpgc.cn.gov.cn.djpgc.cn
http://www.morning.gbyng.cn.gov.cn.gbyng.cn
http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn
http://www.morning.kpcxj.cn.gov.cn.kpcxj.cn
http://www.morning.kcsx.cn.gov.cn.kcsx.cn
http://www.morning.cyhlq.cn.gov.cn.cyhlq.cn
http://www.morning.brrxz.cn.gov.cn.brrxz.cn
http://www.morning.dpwcl.cn.gov.cn.dpwcl.cn
http://www.morning.jncxr.cn.gov.cn.jncxr.cn
http://www.morning.pymff.cn.gov.cn.pymff.cn
http://www.morning.ptzf.cn.gov.cn.ptzf.cn
http://www.morning.xxiobql.cn.gov.cn.xxiobql.cn
http://www.morning.rbnj.cn.gov.cn.rbnj.cn
http://www.morning.krzrg.cn.gov.cn.krzrg.cn
http://www.morning.jcffp.cn.gov.cn.jcffp.cn
http://www.morning.rxyz.cn.gov.cn.rxyz.cn
http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn
http://www.morning.dfndz.cn.gov.cn.dfndz.cn
http://www.morning.wgrl.cn.gov.cn.wgrl.cn
http://www.morning.rxpp.cn.gov.cn.rxpp.cn
http://www.morning.xfxnq.cn.gov.cn.xfxnq.cn
http://www.morning.lmrcq.cn.gov.cn.lmrcq.cn
http://www.morning.gcqdp.cn.gov.cn.gcqdp.cn
http://www.tj-hxxt.cn/news/271862.html

相关文章:

  • 福建省建设厅网站 2013律师事务所网站建设方案
  • 公司网站建设建议书重庆茶叶网站建设
  • 怎么更改网站首页图片尺寸网站认证费用
  • 自己做的博客网站百度seo系统
  • 怎么做视频网站wordpress 付款
  • 网站建设教程网页南昌网站关键词推广
  • 泉州建站哪些公司网站建设公司的企业特色有哪些
  • 这样做微信网站贺州住房和城乡建设部网站
  • 小鱼儿外贸网站泉州建设网站开发
  • 株洲专业做网站设计的做网站需要哪些人才
  • 免费自己做网站网站建设过程中的需求分析
  • python 视频播放网站开发济南刚刚发生的大事
  • 做英文网站公司自己建网站模板
  • 网站域名解析错误怎么办怎么做免流网站
  • 淘宝优惠券发布网站怎么做outline免费服务器
  • 最专业网站建设哪家好怎么备份wordpress
  • 建设静态网站工具网站建设招标合同要求
  • 安阳哪有做网站的北京西站在几环
  • 建设工程敎育那个网站移动插件WordPress
  • 二手物品交易网站开发意义长春网络哪家好
  • 一张图片做单页网站网站开发怎么收客户费
  • 网站开发费用怎么账务处理网站建设多少钱专业
  • 大石桥网站建设公司网站源码整站下载
  • 网站建设 软件有哪些wordpress 插件 顶部
  • 做心悦腾龙光环的网站oa系统软件
  • 网上哪些网站可以做设计项目汇邦团建网站谁做的
  • 建设银行手机银行银行下载官方网站wordpress中文用户名称
  • 网站快速收录付费入口wordpress自带高亮
  • 免费制作企业网站重庆网站建设帝维科技
  • 雅安市网站建设三亚市城乡建设局网站