国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

uniapp通過(guò)renderjs加載3D模型,支持FBX、GLB和GLTF模型,模型可自動(dòng)適應(yīng)。

這篇具有很好參考價(jià)值的文章主要介紹了uniapp通過(guò)renderjs加載3D模型,支持FBX、GLB和GLTF模型,模型可自動(dòng)適應(yīng)。。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

組件模板

  1. n-text-loading是我的自定義loading組件,可以自行替換
  2. id是threeView是模型顯示的位置,
  3. props里面的url是模型鏈接,cameraZ是相機(jī)位置,默認(rèn)100,一般不需要改,有些z軸很長(zhǎng)的模型旋轉(zhuǎn)的時(shí)候會(huì)有一部分相機(jī)看不到這個(gè)時(shí)候就需要調(diào)整這個(gè)值了,這兩個(gè)要從后臺(tái)上傳。
  4. :prop=“url”,url就是你傳給renderjs的值,不傳的話renderjs中拿不到,
  5. :change:prop=“thress.updataModelUrl”,這個(gè)表示prop改變了會(huì)執(zhí)行模塊thress中的updataModelUrl方法,這個(gè)方法接收四個(gè)參數(shù)newValue, oldValue, ownerInstance, instance
<template>
    <view class="collection-bg">
		<n-text-loading v-if="loading"></n-text-loading>
        <view id="threeView" 
            @click="thress.onClick" 
            :prop="url" 
            :change:prop="thress.updataModelUrl"
            :propz="cameraZ" 
            :change:propz="thress.updataModelZ"
            class="media-wrap" 
            ></view>
    </view>
</template>
<script>
	export default{
		props:{
			url: String,
            cameraZ: Number
		},
		data(){
			return{
				loading: true,
			}
		},
        methods:{
            completed(option){
                this.loading = option.loading || false;
            }
        }
	}
</script>

renderjs

  1. script里面的module="thress"和上面template里面的thress是對(duì)應(yīng)的,別寫錯(cuò)了
  2. three自己npm下載就可以了
  3. template里面是用不了renderjs中的data的值的,所以控制加載中的屬性loading我是放在上面的,加載完成之后調(diào)用id為threeView的點(diǎn)擊事件,然后會(huì)執(zhí)行renderjs中onClick方法,onClick會(huì)收到兩個(gè)參數(shù)event, ownerInstance,再使用ownerInstance.callMethod()方法,可以傳兩個(gè)參數(shù),第一個(gè)是上面方法名,第二個(gè)是你要傳遞的參數(shù),比如這樣: ownerInstance.callMethod(‘completed’, { loading: false });
  4. 好像也沒(méi)啥了,其他直接復(fù)制就OK了。
<script module="thress" lang="renderjs">
	// import THREE from 'three/build/three.min.js'
	const THREE = require('three')
    import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
    import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
    import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
	export default {
    name:"ModelScale",
    data(){
        return{
            scene:null,
            camera:null,
            renderer:null,  
            cube:null,
            sphere:null,
            step:0,
            stats:null, 
            group:null,
			orbitcontrols: null,
        }
    },
    props:{
        width:{type:Number,default: 375},
        height:{type:Number,default: 380},
    },
    methods:{
        updataModelUrl(newValue, oldValue, ownerInstance, instance) {
            // 監(jiān)聽 service 層數(shù)據(jù)變更
            console.log(newValue,'層數(shù)據(jù)變更');
        },
        updataModelZ(newValue, oldValue, ownerInstance, instance){
           console.log(newValue,'層數(shù)據(jù)變更2');
        },
        onClick(event, ownerInstance){
            ownerInstance.callMethod('completed', {
                loading: false
            })
        },
        init(){
            const cameraZ = this.cameraZ <= 0 ? 100 : this.cameraZ;
            console.log(cameraZ,'cameraZ');
            this.scene = new THREE.Scene();
            this.camera = new THREE.PerspectiveCamera(45,this.width/this.height,0.1,1000);
            this.camera.position.set(0,0,cameraZ);
            this.renderer = new THREE.WebGLRenderer({antialias: true });           
			this.renderer.setClearColor(0xffffff,0);
            this.renderer.setSize(this.width/1.2,this.height/1.2);
            this.renderer.setPixelRatio(window.devicePixelRatio);
            this.renderer.shadowMapEnabled = true; 
            document.getElementById("threeView").appendChild(this.renderer.domElement);

            this.orbitcontrols = new OrbitControls(this.camera, this.renderer.domElement);  //移動(dòng)控件
			this.orbitcontrols.enabled = true;
			this.orbitcontrols.enableRotate =true;
			this.orbitcontrols.enableZoom = false;
			this.orbitcontrols.autoRotate = true;
            this.orbitcontrols.minPolarAngle = Math.PI / 4;  
            this.orbitcontrols.maxPolarAngle = 3 - (Math.PI / 4);  

            // let axes = new THREE.AxesHelper(100);//輔助線
            // this.scene.add(axes);

			if(this.url.endsWith('gltf') || this.url.endsWith('glb')){
				//設(shè)置了六個(gè)平行光  有些材質(zhì)不接受環(huán)境光會(huì)很暗
				const directionLight1 = new THREE.DirectionalLight(0xffffff, 1);
				directionLight1.position.set(-300,0,0)
				this.scene.add(directionLight1);
		
				const directionLight2 = new THREE.DirectionalLight(0xffffff, 1);
				directionLight2.position.set(300,0,0)
				this.scene.add(directionLight2);
				
				const directionLight3 = new THREE.DirectionalLight(0xffffff, 1);
				directionLight3.position.set(0,300,0)
				this.scene.add(directionLight3);
				
				const directionLight4 = new THREE.DirectionalLight(0xffffff, 1);
				directionLight4.position.set(0,300,0)
				this.scene.add(directionLight4);
		
				const directionLight5 = new THREE.DirectionalLight(0xffffff, 1);
				directionLight5.position.set(0,0,-300)
				this.scene.add(directionLight5);
		
				const directionLight6 = new THREE.DirectionalLight(0xffffff, 1);
				directionLight6.position.set(0,0,300)
				this.scene.add(directionLight6);
			}
			let Sun = new THREE.DirectionalLight(0xffffff, 1);
			Sun.position.set(0,300,0);
			Sun.castShadow = true;
			
			let Ambient = new THREE.AmbientLight(0xffffff, 1);
			this.scene.add(Ambient);
			this.scene.add(Sun);
        },
        loadModel(){
            let self = this; //這一點(diǎn)很重要。。
            let loader1 = new GLTFLoader();
			let FBXloader = new FBXLoader();
           	let rotateObj = [];
			const loadLoader = this.url.endsWith('fbx') ? FBXloader : loader1;
            loadLoader.load(this.url,function (gltf){
				
                const loadscene = gltf.scene || gltf;               
                
                loadscene.scale.set(1,1,1);   
                
                let group = new THREE.Group();
                group.add(loadscene);
                
                let bbox = new THREE.Box3().setFromObject(group);
                // console.log(bbox,'bbox---');
                let mdlen=bbox.max.x-bbox.min.x; //邊界的最小坐標(biāo)值 邊界的最大坐標(biāo)值
                let mdhei=bbox.max.y-bbox.min.y; 
                let mdwid=bbox.max.z-bbox.min.z;     
                group.position.set(0,0,0); 
                // console.log(self.camera,'相機(jī)的信息',group,'組的信息');
                let dist =Math.abs(self.camera.position.z - group.position.z- (mdwid/2));
                //console.log('dist值為:' + dist );
                let vFov = self.camera.fov * Math.PI/180;  //弧度=角度*Math.PI/180
                //console.log('vFov值為:' + vFov );
                let vheight = 2 * Math.tan(vFov * 0.5) *dist;
                //console.log('vheight值為:' + vheight );
                let fraction = mdhei / vheight;
                // console.log('fraction值為:' + fraction );
                let finalHeight = self.height * fraction ;                
                //console.log('finalHeight值為:' + finalHeight);
                let finalWidth = (finalHeight*mdlen) /mdhei;             
                //console.log('finalWidth值為:' + finalWidth );                

                let value1 = self.width/finalWidth;
                // console.log('value1縮放比例值為:' + value1);
                let value2 = self.height/finalHeight;
                // console.log('value2縮放比例值為:' + value2);

                if(value1 >= value2){
                    group.scale.set(value2,value2,value2);
                }
                else{
                    group.scale.set(value1 /2,value1/2,value1/2);
                    // group.scale.set(value1,value1,value1);
                } 
                let bbox2= new THREE.Box3().setFromObject(group)
				// console.log(bbox2,'bbox2');
                let mdlen2=bbox2.max.x-bbox2.min.x;
                let mdhei2=bbox2.max.y-bbox2.min.y;
                let mdwid2=bbox2.max.z-bbox2.min.z;
                group.position.set(-(bbox2.max.x+bbox2.min.x)/2,
                -(bbox2.max.y+bbox2.min.y)/2,
                -(bbox2.max.z+bbox2.min.z)/2);
                document.getElementById("threeView").click(); //去掉加載效果
                self.scene.add(group);
                // let boxhelper = new THREE.BoxHelper(group,0xbe1915); //輔助線外面紅色框
                // self.scene.add(boxhelper);  
            });                       
        },
        animate(){
            requestAnimationFrame(this.animate);
			this.orbitcontrols.update();  //自動(dòng)旋轉(zhuǎn)
            this.renderer.render(this.scene,this.camera);  
        }
    },
    mounted(){
        window.ob = this;
        this.init();
        this.animate(); 
        this.loadModel();      
    }
}
</script>

文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-628422.html

到了這里,關(guān)于uniapp通過(guò)renderjs加載3D模型,支持FBX、GLB和GLTF模型,模型可自動(dòng)適應(yīng)。的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 3dmax模型完美轉(zhuǎn)glb模型,gltf格式模型轉(zhuǎn)fbx格式轉(zhuǎn)obj格式

    3dmax模型完美轉(zhuǎn)glb模型,gltf格式模型轉(zhuǎn)fbx格式轉(zhuǎn)obj格式

    現(xiàn)在好多模型都是3dmax模型,但是客戶要求是glb或者gltf模型 這個(gè)時(shí)候好多人直接導(dǎo)出glb模型,是沒(méi)有顏色貼圖的,這樣的 這個(gè)時(shí)候是不能用的,怎么辦,咱們要回到3dmax,把VR材質(zhì)一個(gè)個(gè)重新上普通材質(zhì) 當(dāng)然也可以用插件一鍵轉(zhuǎn)換 沒(méi)有插件可以聯(lián)系QQ 424081801也可以制作glb模

    2024年02月12日
    瀏覽(33)
  • Easy3dviewer三維模型(gltf/glb、osgb、fbx、x、shp、dxf)超輕量瀏覽和轉(zhuǎn)換工具軟件分享

    Easy3dviewer三維模型(gltf/glb、osgb、fbx、x、shp、dxf)超輕量瀏覽和轉(zhuǎn)換工具軟件分享

    工作中經(jīng)常需要用到不同格式的三維模型,比如3dmiax建模的3ds,傾斜攝影的osgb、bim轉(zhuǎn)換的fbx,二維gis需要的shp、cad建模的dxf、三維gis需要的gltf等等,需要能快速方便的瀏覽和查看這些三維模型,也需要能將三維模型格式轉(zhuǎn)換成其他三維模型格式。對(duì)三維瀏覽和轉(zhuǎn)換的需求非

    2024年02月04日
    瀏覽(36)
  • Babylonjs Playground中動(dòng)態(tài)加載自己的glb gltf模型(github、dropbox)

    Babylonjs Playground中動(dòng)態(tài)加載自己的glb gltf模型(github、dropbox)

    目錄 以下提供兩種常用的方法 (使用科學(xué)梯子) 先說(shuō)總結(jié):對(duì)比 github和dropbox github外鏈?zhǔn)褂梅椒?方法一:rootUrl添加鏈接路徑。sceneFilename必須置空 方法二:rootUrl填寫文件夾路徑,sceneFileName填寫對(duì)應(yīng)的文件名字 方法三:gltf+bin文件 見案例: 額外補(bǔ)充:群友盲猜大佬整理的

    2024年02月04日
    瀏覽(20)
  • OpenGL Assimp加載各類型模型(.obj、.fbx、.glb、.3ds)

    OpenGL Assimp加載各類型模型(.obj、.fbx、.glb、.3ds)

    1.簡(jiǎn)介 本博客以.glb格式為例,加載glb格式的3d模型,網(wǎng)上找了一圈,基本上都是根據(jù)OpenGL官方示例,加載.obj格式的3d模型。 下面以.obj和.glb格式的3D模型簡(jiǎn)單介紹一下。 常見的.obj格式的3D模型如下所示:紋理都已經(jīng)被剝離出來(lái)了。所以在使用Assimp庫(kù)加載的時(shí)候,加載了指定的

    2024年01月19日
    瀏覽(24)
  • open3d,讀取stl/ply/obj/off/gltf/glb三維模型,并轉(zhuǎn)換成點(diǎn)云,保存

    open3d,讀取stl/ply/obj/off/gltf/glb三維模型,并轉(zhuǎn)換成點(diǎn)云,保存

    可以自己用建模軟件建立一個(gè)模型 本案例使用模型的下載地址 可以從free3d免費(fèi)下載,無(wú)需注冊(cè) 效果: 效果: 均勻采樣會(huì)在表面出現(xiàn)采樣點(diǎn)聚集的現(xiàn)象,open3d實(shí)現(xiàn)了一種基于poisson_disk方法的采樣,能實(shí)現(xiàn)表面的均勻采樣 原理 :參數(shù)umber_of_points是最終采樣的點(diǎn)數(shù)量,實(shí)際會(huì)先

    2024年02月11日
    瀏覽(270)
  • Unity加載gltf/glb文件

    Unity加載gltf/glb文件

    1.打開包管理器窗口 2.點(diǎn)擊添加 3.點(diǎn)擊“按名稱添加包” 4. 輸入 com.unity.nuget.newtonsoft-json 包名稱和 3.0.1 版本 第一種方法: 通過(guò)PackageManager的Git url的方式添加: \\\"com.siccity.gltfutility\\\": \\\"https://github.com/siccity/gltfutility.git\\\" 如果git訪問(wèn)不了,你可以用第二種方式手動(dòng)下載; 第二種方

    2024年02月15日
    瀏覽(21)
  • 如何把glb格式模型gltf格式模型導(dǎo)入3dmax和C4D,U3D,UE4這些主流軟件中

    如何把glb格式模型gltf格式模型導(dǎo)入3dmax和C4D,U3D,UE4這些主流軟件中

    咱有時(shí)候去glbxz.com添加鏈接描述 官網(wǎng)下載免費(fèi)glb格式模型,gltf模型下載時(shí)候是沒(méi)有通用格式,例如fbx,obj,這個(gè)時(shí)候3dmax和C4D直接打開導(dǎo)入是不行的,也可以制作glb模型,扣扣:424081801 這個(gè)時(shí)候,咱們用 glbxz.com 平臺(tái)在線編輯功能,先導(dǎo)入glb 導(dǎo)入進(jìn)來(lái)看看glb格式模型或者g

    2024年02月12日
    瀏覽(145)
  • cesium加載glb格式的3d模型

    cesium加載glb格式的3d模型

    官方示例: Cesium Sandcastle https://sandcastle.cesium.com/?src=3D%20Models.htmllabel=Tutorials glb模型下載:https://sandcastle.cesium.com/SampleData/models/CesiumAir/Cesium_Air.glb? ?

    2024年02月11日
    瀏覽(22)
  • 【Cesium學(xué)習(xí)(六)】Cesium加載3D模型(3D tiles和glTF模型)

    【Cesium學(xué)習(xí)(六)】Cesium加載3D模型(3D tiles和glTF模型)

    前面我們學(xué)習(xí)到了繪制基本的形狀,但是Cesium還可以加載3D模型,因?yàn)橄窀叩碌貓D這種的技術(shù)來(lái)加載大型復(fù)雜的建筑模型性能不加,所有只能想Cesium這種專門做3D地圖的技術(shù)。接下來(lái)就學(xué)習(xí)一下如何加載模型。 Cesium目前支持兩種模型方案,一個(gè)是使用3D tiles, 另一個(gè)是加載g

    2024年02月07日
    瀏覽(26)
  • threejs加載.Fbx .OBJ 3D模型文件

    threejs加載.Fbx .OBJ 3D模型文件

    在threejs官網(wǎng)下載threejs的文件,可以選擇直接下載,也可以跳轉(zhuǎn)到GitHub拉取 拉取下來(lái)的完整文件就是這個(gè)樣子 拉取成功后我們?cè)诒镜匕惭b啟動(dòng)服務(wù),這樣就能很快速的查看threejs的各種例子了 可以先看看官網(wǎng)里的例子,你想要的東西官方里面都有 后期在開發(fā)的時(shí)候需要用到b

    2023年04月08日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包