three.js加载有贴图的三维模型(亲测,已实现)

该博客介绍了如何使用three.js库加载具有贴图的三维模型。首先,创建场景、灯光、相机和渲染器,并设置相机位置、渲染器尺寸等。然后,使用GLTFLoader加载gltf格式的3D模型,并将其添加到场景中。同时,添加 OrbitControls 实现视角控制,以及地板几何体以增加场景背景。最后,实现了鼠标点击事件,以便于交互操作。
摘要由CSDN通过智能技术生成

<template>

  <div class="earth-container">

    <div

      id="container"

      class="container"

      ref="container"

    />

  </div>

</template>

 

<script>

import * as THREE from "three";

import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";

 

export default {

  name: "Index",

  data() {

    return {

      scene: "",

      light: "",

      camera: "",

      controls: "",

      renderer: "",

      clickObjects:[],

    };

  },

  methods: {

    // 初始化three.js相关内容

    init() {

      this.scene = new THREE.Scene();

      this.scene.add(new THREE.AmbientLight(0x999999)); // 环境光

      // this.scene.background

      this.light = new THREE.DirectionalLight(0xdfebff, 0.45); // 从正上方(不是位置)照射过来的平行光,0.45的强度

      this.light.position.set(100, 100, 400);

      this.light.position.multiplyScalar(0.3);

      this.light.shadow.camera.near = 20; // 产生阴影的最近距离

      this.light.shado

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值