美文网首页
将封灵街搬到线上-- 使用带LiDAR的iPhone进行3D扫描

将封灵街搬到线上-- 使用带LiDAR的iPhone进行3D扫描

作者: LazyGunner | 来源:发表于2021-11-08 14:04 被阅读0次

1. 使用3D Scanner App + iPhone 12 Pro进行实体空间的扫描

image

示意图中是High Res模式,但是因为实景空间比较大,所以真实情况是用了Low Res模式扫描的。

image

扫码结果:

image image

担心一次性扫描完整内容会导致文件过大,渲染出问题,所以后面有对休息区单独扫描了一次。

image

扫描过后,我们通过导出OBJ格式的文件,并通过Air Drop同步到Mac上

image

我们在Mac上接收到后,可以看到是一个文件夹,文件夹中包含了3个文件:

image

1. xxx.mtl

  1. xxx.jpg
  2. xxx.obj

2. 将OBJ文件导入Unity

2.1. 在Unity中创建一个3D项目

image

2.2. 将OBJ模型导入到Assets文件夹

我们先在Assets文件夹下创建 Models/room1 两个文件夹,再把刚刚导出的文件拖拽到这个文件夹中

image

为了后续不重复,我们统一把三个文件的名称都改为room1

2.3. 将模型导入场景

直接将room1.obj拖入场景中

image

2.4. 给模型贴上材质

选中room1这个对象,然后在 Inspector中点击“Select”按钮

image

之后再Inspector中切换到Material,再展开“On Demand Remap”箭头

image

将Naming下拉框从“By Base Texture Name” 改为 “Model Name + Model Material”

image

之后再点击 “Seach and Remap”, Unity便会在同目录下搜索相同名称的贴图文件,并进行贴图。

image

如果上述方法不行的话,也可以通过自己创建Material的方法:

  1. 在room1文件夹右键,Create->Material,命名为room1
  2. 将图片拖到 Albedo前面的方框中
image
  1. 选中room1对象的子对象 default,将room1的material拖到 Materials-> Element 0中
image

3. 导入任务模型,并增加控制脚本

3.1. 导入角色模型

我之前用RealityComposer做过一个Code47的模型,通过blender导出了fbx格式,这里接直接拖进来就可以用了

image

需要注意的是,要把模型自身的Light禁用掉

3.2. 增加移动控制脚本,通过WASD控制角色移动

选择角色模型,Add Component-> New Script-> Player

image

打开脚本文件,写入代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public CharacterController controller;

    public float speed = 12f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        // keyboard move
        float x = Input.GetAxisRaw("Horizontal"); // A D
        float z = Input.GetAxisRaw("Vertical");   // W S

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

    }
}

之后再在 角色模型上添加一个Character Controller Component,并把Code47这个对象拖拽到 Player Script中的Controller一栏中

image

同时还需要将包裹的Collider调整到和模型一致,主要调整Center,Radius和Height这几个参数。

image

这样就可以通过 AWSD来控制模型的运动了。

3.3. 通过鼠标来控制角色视角

选择Code47模型下面的 Camer对象,并添加脚本MouseLook,代码如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour
{
    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

        playerBody.Rotate(Vector3.up * mouseX);
    }
}

并把Code47模型拖到 MouseLook脚本中的Player Body一栏中,就OK了。

image

4. 给空间模型增加碰撞

在模型->Select->Model中 勾选Generate Colliders来增加空间的碰撞,这样角色就不会穿墙了

image

演示视频可以微信搜索GunnerTalk公众号

相关文章

网友评论

      本文标题:将封灵街搬到线上-- 使用带LiDAR的iPhone进行3D扫描

      本文链接:https://www.haomeiwen.com/subject/dkvuzltx.html