效果
threejs按照指定曲线效果逐渐增长
全部代码
主要思路是先创建指定曲线路径,并将其分为1000个点,然后按照自定义路线拉伸三维物体,从头遍历点的位置,然后放入物体拉伸路径中,实现缓慢增长效果
全部代码如下:
<template>
<div class="threejs">
<div id="containerId" />
</div>
</template>
<script setup>
import * as THREE from 'three';
import {
OrbitControls } from 'three/addons/controls/OrbitControls';
import {
ref, onMounted } from 'vue';
let scene;
const camera = ref();
const renderer = ref();
const container = ref();
const controls = ref();
function initScene() {
scene = new THREE.Scene();
}
function initCamera() {
camera.value = new THREE.PerspectiveCamera(
65,
window.innerWidth / window.innerHeight,
0.1,
10000
);
camera.value.position.set(0, 0, 1000);
}
function initLight() {
//添加两个平行光