uni-app使用three

<template>
	<view class="content">

	</view>
</template>

<script>
	import * as THREE from "three"
	import {
		GLTFLoader
	} from 'three/examples/jsm/loaders/GLTFLoader';
	import {
		OrbitControls
	} from "three/examples/jsm/controls/OrbitControls"
	import {
		DRACOLoader
	} from "three/examples/jsm/loaders/DRACOLoader"
	import {
		FBXLoader
	} from "three/examples/jsm/loaders/FBXLoader"

	export default {
		data() {
			return {

			};
		},
		mounted() {
			const content = document.querySelector(".content");
			const canvas = document.createElement("canvas");
			canvas.style.width = '100vw'
			canvas.style.height = '100vh'
			content.appendChild(canvas);




			if (canvas) {
				const scene = new THREE.Scene()
				scene.background = new THREE.Color('#ccc')
				scene.environment = '#ccc'
				const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
				const renderer = new THREE.WebGLRenderer({
					canvas,
					antialias: true
				});
				//开启HiDPI设置 解决模型模糊
				renderer.setPixelRatio(window.devicePixelRatio);
				renderer.setSize(window.innerWidth, window.innerHeight)

				camera.position.z = 20


				const controls = new OrbitControls(camera, renderer.domElement)
				controls.update()
				controls.enableDamping = true;

				const interiorSeats = new THREE.MeshPhysicalMaterial({
					color: "#2073b1",
					metalness: 1, // 金属度
					roughness: 0.5, //粗糙度
					clearcoat: 1, // 光滑
					clearcoatRoughness: 0, // 粗糙度
				})

				const loader = new GLTFLoader()
				// const dracoLoader = new DRACOLoader();
				// dracoLoader.setDecoderPath("/public/draco/gltf");
				// loader.setDRACOLoader(dracoLoader);
				loader.load('./../../static/009.gltf', gltf => {
					console.log(gltf);
					scene.add(gltf.scene)
					gltf.scene.traverse(c => {
						c.material = interiorSeats
					})
				})

				// const fbxLoader = new FBXLoader()
				// fbxLoader.load('./../../static/modelNew.fbx', fbx => {
				// 	console.log(fbx)
				// 	fbx.scale.set(0.01, 0.01, 0.01)
				// 	scene.add(fbx)
				// })

				// 灯光
				// 前灯光
				const light1 = new THREE.DirectionalLight(0xffffff, 1)
				light1.position.set(0, 0, 10)
				scene.add(light1)
				// 后灯光
				const light2 = new THREE.DirectionalLight(0xffffff, 1)
				light2.position.set(0, 0, -10)
				scene.add(light2)
				// 左灯光
				const light3 = new THREE.DirectionalLight(0xffffff, 1)
				light3.position.set(-10, 0, 0)
				scene.add(light3)
				// 右灯光
				const light4 = new THREE.DirectionalLight(0xffffff, 1)
				light4.position.set(10, 0, 0)
				scene.add(light4)
				// 上灯光
				const light5 = new THREE.DirectionalLight(0xffffff, 1)
				light5.position.set(0, 10, 0)
				scene.add(light5)
				// 下灯光
				const light6 = new THREE.DirectionalLight(0xffffff, 1)
				light6.position.set(0, -10, 0)
				scene.add(light6)
				// 添加光源
				const light7 = new THREE.DirectionalLight(0xffffff, 1);
				light7.position.set(0, 10, 5);
				scene.add(light7);

				// 添加光源
				const light8 = new THREE.DirectionalLight(0xffffff, 1);
				light8.position.set(-5, 10, 0);
				scene.add(light8);

				// 添加光源
				const light9 = new THREE.DirectionalLight(0xffffff, 1);
				light9.position.set(0, 10, -5);
				scene.add(light9);

				const light = new THREE.AmbientLight(0x000000)
				scene.add(light)

				const animate = () => {
					requestAnimationFrame(animate);
					controls.update()
					renderer.render(scene, camera);
				}
				animate();

				// canvas.addEventListener('touchstart', e => {
				// 	console.log(e)
				// 	controls.update()
				// 	renderer.render(scene, camera);
				// })
				// canvas.addEventListener('touchmove', e => {
				// 	console.log(e)
				// 	controls.update()
				// 	renderer.render(scene, camera);
				// })


			}
		}
	}
</script>


<style>

</style>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-app使用uni-list,你可以按照以下步骤进行操作: 1. 在页面中引入uni-list组件,可以通过在页面的json文件中添加"usingComponents"字段来引入组件,或者直接在页面的vue文件中使用import语句引入组件。 2. 在页面的template中使用uni-list组件,可以通过在template中添加<uni-list>标签来创建一个列表。 3. 在<uni-list>标签内部,可以使用<uni-list-item>标签来创建列表项。你可以使用v-for指令来循环渲染多个列表项,可以参考\[3\]中的示例。 4. 可以通过在<uni-list-item>标签上设置样式来自定义列表项的外观。根据\[3\]中的描述,如果要设置<uni-list-item>的样式,需要在它外层的view标签上设置才会生效。 总结起来,使用uni-list在uni-app中创建列表的步骤是:引入组件、创建<uni-list>标签、在<uni-list>标签内部使用<uni-list-item>标签循环渲染列表项,并在view标签上设置样式。 #### 引用[.reference_title] - *1* *2* [【uni-app教程】uni-app入门教程](https://blog.csdn.net/beiluoL/article/details/129264321)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [uni-appuni-list列表分割线不显示问题](https://blog.csdn.net/weixin_57375608/article/details/129951060)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值