【three.js】

three.js场景三要素:场景,相机和渲染器

官方文档:
https://www.wenjiangs.com/wp-content/uploads/three.js/docs/index.html#manual/zh/introduction/Creating-a-scene

一个完整版的three.js的demo
https://blog.csdn.net/m0_55145031/article/details/120163574

camera要素介绍及其属性
https://www.fengjinwei.com/blog-1367564.html

代码就仅仅出来东西 !!!

<template>
  <div>
    <div id="container" ref="container"></div>
  </div>
</template>

<script>
import * as Three from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
export default {
  name: "threeJs",
  data() {
    return {
      camera: null,
      scene: null,
      renderer: null,
      mesh: null,
    }
  },
  mounted() {
    this.init();
    this.animate();
  },
  methods: {

    init() {
      let container = document.getElementById("container");
      this.camera = new Three.PerspectiveCamera(
          70,
          container.clientWidth / container.clientHeight,
          0.01,
          1000
      );
      this.camera.position.z = 0.6;
      this.scene = new Three.Scene();
      let geometry = new Three.CylinderBufferGeometry(0.2, 0.2, 0.2);
      let material = new Three.MeshNormalMaterial();
      this.mesh = new Three.Mesh(geometry, material);
      this.scene.add(this.mesh);
      this.renderer = new Three.WebGLRenderer({antialias: true});
      this.renderer.setSize(container.clientWidth, container.clientHeight);
      container.appendChild(this.renderer.domElement);
      //添加控制器
      var col = new OrbitControls(this.camera,this.renderer.domElement)
      col.addEventListener('change',()=>{
        this.renderer.render(this.scene,this.camera)
      })
      col.enableRotate=true//启用旋转
      col.enablePan=true//启用平移
      col.enableZoom=true//启用缩放
    },
    animate() {
      requestAnimationFrame(this.animate);
      this.mesh.rotation.x += 0.01;
      this.mesh.rotation.y += 0.02;
      this.renderer.render(this.scene, this.camera);
    },
  },
}
</script>

<style scoped>
#container{
  height: 400px;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

就躺了吧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值