马黑PHP整站系统

ThreeJS:纹理流动的直管道

位置: 首页 > 代码集锦[ 发布时间: 2025.6.24  作者: 马黑  阅读: 175 ]
<script type="module">
	import { THREE, scene, camera, renderer, clock, basic3 } from 'https://638183.freep.cn/638183/3dev/3/3basic.js';
	basic3();

	// 加载纹理
	const texture = new THREE.CanvasTexture(drawTexture());
	texture.colorSpace = THREE.SRGBColorSpace;
	texture.wrapS = THREE.RepeatWrapping;
	texture.wrapT = THREE.RepeatWrapping;
	texture.repeat.x = 8;
	texture.repeat.y = 2;
		
	//绘制直管道
	const path = new THREE.LineCurve3(new THREE.Vector3(-2, 1, 0), new THREE.Vector3(2, -1, 0));
	const geometry = new THREE.TubeGeometry(path, 32, 0.2, 32, false);
	const material = new THREE.MeshBasicMaterial({ color: 0xefefee, map: texture, side: THREE.DoubleSide });
	const mesh = new THREE.Mesh(geometry, material);
	mesh.rotateY(-Math.PI / 3);
	scene.add(mesh);

	// 纹理动画
	function animate() {
		requestAnimationFrame(animate);
		const delta = clock.getDelta();
		texture.offset.x += delta;
		renderer.render(scene, camera);
	}

	// 绘制canvas纹理
	function drawTexture () {
		const canv = document.createElement('canvas');
		canv.width = 100;
		canv.height = 100;
		canv.style.border = '1px solid gray';
		const ctx = canv.getContext('2d');
		ctx.fillStyle = 'yellow';
		ctx.fillRect(0, 0, 50, 100);
		ctx.fillStyle = 'teal';
		ctx.fillRect(50, 0, 100, 100);
		return canv;
	}

	animate();
</script>

前一篇: ThreeJS加载外部模型并运行其自带动画
下一篇: Tween动画链接补间及其播放停止暂停继续

发表评论:

       

评论列表 [1条]

#1 | 知名不具 于 2025-6-25 21:44 发布: 这个好像有点奇怪,连续的感觉并不好,可能细密纹路的图图流动效果更好?

Copyright © 2023 All Right Reserved 马黑PHP文章管理整站系统v1.8
联系我们: gxblk@163.com