ThreeJS 官方案例学习(webgl_clipping_stencil)
1.效果图

2.源码
<template>
<div>
<div id="container"></div>
</div>
</template>
<script>
import * as THREE from 'three';
import {
OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import {
RoomEnvironment } from 'three/examples/jsm/environments/RoomEnvironment.js';
import Stats from 'three/examples/jsm/libs/stats.module.js';
import {
GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import {
DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader'
import {
GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
import gsap from 'gsap';
export default {
data() {
return {
container: null,
scene: null,
camera: null,
renderer: null,
controller: null,
stats: null,
model: null,
clock: new THREE.Clock(),
params: {
animate: true,
planeX: {
constant: 0,
negated: false,
displayHelper: false,
},
planeY: {
constant: 0,
negated: false,
displayHelper: false,
},
planeZ: {
constant: 0,
negated: false,
displayHelper: false,
},
},
planeHelpers: null,
planeObjects: [],
planes: [
new THREE.Plane(new THREE.Vector3(- 1, 0, 0), 0),
new THREE.Plane(new THREE.Vector3(0, - 1, 0), 0),
new THREE.Plane(new THREE.Vector3(0, 0, - 1), 0),
],
};
},
mounted() {
this.init()
this.animate()
window.addEventListener("resize", this.onWindowSize)
},
beforeUnmount() {
console.log('beforeUnmount===============');
this.container = null
this.scene = null
this.camera = null
this.renderer = null
this.controller = null
this.stats = null
this.object = null
},
methods: {
init() {
this.container = document.getElementById('container')
this.startTime = Date.now();
this.setScene()
this.setCamera()
this.setRenderer()
this.setController()
this.addHelper()
this.setLight()
this.setMesh()
this.addStatus()
},
setScene() {