google glb 模型的 webXR 演示

演示链接 - mritunjay.vercel.app/dog

(webXR 目前仅在 android for chrome 中支持)

以前有 webVR,现在被新的 webXR api 弃用。这里的 XR 代表它提供的混合现实功能。webXR api 仅处理用于 3D 模型渲染和操作的会话时间、调度和周围环境信息,我们将使用threejs。

我将假设您至少具备 3D 的基本知识,并且对 JavaScript 有一定的熟练程度。

快速开始在您的项目 yarn add three 中为 3d 模型添加 threejs 模块,我们使用的是 google glb 格式的 beagle(dog) 模型。您可以从storage.googleapis.com/ar-answers-in-search 下载它。

首先,我们将初始化一些向前推进的变量,我们将为它赋值

// index.js component file
import React from 'react';
import * as THREE from 'three';


export function BeagleARView() {
  let renderer = null;
  let scene = null;
  let camera = null;
  let model = null;
  let mixer = null;
  let action = null;
  let reticle = null;
  let lastFrame = Date.now();
  let spotLight;

  // light variables
  let lightSpotColor = 0xDDDDDD;
  let lightSpotIntensity = 0.7;

我们将在这里添加一个初始化函数来更新值,然后我们将了解一些使用threejs的3D基础知识。关于threejs的事情:

  • 场景:场景就像虚拟空间,具有坐标信息并设置渲染的内容和位置。因此,我们可以添加多个对象(3D 模型)、灯光并移除它们。

  • 渲染器:它显示/绘制场景。Threejs 使用 webGL 进行渲染和图像处理。

  • 相机:有多种类型的相机。我们将使用透视相机,它可以根据您的观察点工作并根据观察位置改变对象大小。

// inside BeagleARView component 
  const initScene = (gl, session) => {
    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera(
      75, // fov (angle, field of view)
      window.innerWidth / window.innerHeight, // aspect
      0.1, // frustum near length
      1000, // frustu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值
>