首页 > 其他分享 >上传本地pcd文件,并用threejs渲染

上传本地pcd文件,并用threejs渲染

时间:2024-10-08 09:24:26浏览次数:1  
标签:threejs const log console file new input 上传 pcd

页面

<template>
  <div>
    <input type="file" @change="handleFileUpload" accept=".pcd" />
    <input type="file" @change="changeFile"  />
    <div @click="stringToFileClick">测试string转file</div>
    <div ref="viewer"></div>
  </div>
</template>

js部分

<script>
import * as THREE from 'three';
import { PCDLoader } from 'three/examples/jsm/loaders/PCDLoader.js' // 注意是examples/jsm
//  本地上传pcd文件预览
export default {
  data() {
    return {
      pointCloud: null,
    };
  },
  mounted(){
    // 使用例子
    // const input = this.stringToFile('Hello, World!', 'message.txt', 'text/plain');
    // document.body.appendChild(input); // 如果需要将input添加到DOM中
  },
  methods: {
    handleFileUpload(file) {
    //   const file = event.target.files[0];
      console.log(file)
      if (!file) return;
 
      const scene = new THREE.Scene();
      const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
      const renderer = new THREE.WebGLRenderer();
      renderer.setSize(window.innerWidth, window.innerHeight);
      this.$refs.viewer.innerHTML = '';
      this.$refs.viewer.appendChild(renderer.domElement);
 
      camera.position.z = 5;
 
      const loader = new PCDLoader();
      
      console.log(URL.createObjectURL(file))
      loader.load(URL.createObjectURL(file), (loadedPointCloud) => {
        if (this.pointCloud) {
          scene.remove(this.pointCloud);
        }
 
        this.pointCloud = loadedPointCloud;
        scene.add(this.pointCloud);
 
        const animate = () => {
          requestAnimationFrame(animate);
          renderer.render(scene, camera);
        };
 
        animate();
      });
    },
    
    changeFile(event){
        console.log('event----------------------aaa')
        // console.log(event.target.files[0])
        let that = this;
        const file = event.target.files[0];
        const reader = new FileReader();
        reader.onload = (e) => {
            console.log('pcdData--------aaaaaa--------------bbb');
            var byteArray = new Uint8Array(e.target.result.length);
            for (var i = 0; i < e.target.result.length; i++) {
                byteArray[i] = e.target.result.charCodeAt(i);
                // console.log(byteArray[i])
            }
            console.log(byteArray.buffer);
            console.log(e.target.result.length);
            // console.log(typeof e.target.result);
            this.stringToFile(byteArray.buffer, 'message.pcd', 'application/octet-stream');
            // this.stringToFile(e.target.result, 'message.pcd', 'application/octet-stream');
            // this.stringToFile(e.target.result, 'tasks (1).html','text/html');
        };
        reader.readAsBinaryString(file);
        // reader.readAsArrayBuffer(file);
    },
    stringToFileClick(){
        this.stringToFile('Hello, World!', 'message.txt', 'text/plain');
    },
    stringToFile(content, fileName, mimeType) {
        // 创建一个Blob对象,类型为mimeType
        const blob = new Blob([content], { type: mimeType });
        // const blob = new Blob([content]);
    
        // 创建一个File对象
        const file = new File([blob], fileName, {
            type: mimeType,
            lastModified: new Date().getTime(), // 或者使用其他适当的时间戳
        });
        this.handleFileUpload(file)
        console.log(file)
        // // // 创建一个隐藏的input元素
        // const input = document.createElement('input');
        // input.type = 'file';
        // input.style.display = 'none';
    
        // // 触发一个点击事件来设置文件
        // input.addEventListener('change', () => {
        //     // 当input改变时,设置文件
        //     const dataTransfer = new DataTransfer();
        //     dataTransfer.items.add(file);
        //     input.files = dataTransfer.files;
        // });
    
        // // 触发点击事件
        // input.click();
    
        // // 返回input元素,以便可以在需要时添加到DOM中
        // return input;
    }
  },
};
</script>

 

标签:threejs,const,log,console,file,new,input,上传,pcd
From: https://www.cnblogs.com/lst619247/p/18451005

相关文章

  • 文件上传各路径【合集】
    @action(detail=False,methods=['post'],url_path='upload')defupload(self,request):upload_obj=request.FILES.get('file')#print(upload_obj)#178bb3d5cfc06006d1d884951a20ff3.jpg#print(upload......
  • 在浏览器上访问媒体资源配置【文件上传】
    1.根urls.py文件中fromdjango.contribimportadminfromdjango.urlsimportpath,include,re_pathfromdjango.views.staticimportservefromdjango.confimportsettingsurlpatterns=[#path('admin/',admin.site.urls),path('api/shipp......
  • ftp怎么上传文件至指定的目录
    要通过FTP(FileTransferProtocol)上传文件到指定目录,你可以按照以下步骤操作:选择FTP客户端:选择一个FTP客户端软件,如FileZilla、WinSCP或Cyberduck等。配置FTP客户端:打开FTP客户端并进行基本设置,输入FTP服务器的地址、端口号(默认为21)、用户名和密码。连接到FTP服务......
  • 帝国CMS图片集只能上传10张图片的原因及解决办法_max_file_uploads
    在帝国CMS中上传图片时,如果发现上传多张图片但最终只显示部分图片,这通常是由于PHP配置中的 max_file_uploads 参数限制导致的。具体来说,这个参数限制了一个表单最多能上传多少个文件。原因分析在帝国CMS中,每张图片都会生成一张大图和一张缩略图,因此实际上每次上传都会占用两......
  • github上传文件
    长时间不用github,又想增加star,久违的创建了repository,满屏的英文却不知道如何上传代码,打开github,找到了git上传文件的方法:1.下载git(已经下载过的请忽略此步骤)https://git-scm.com/downloads安装时,建议选择gitbash2.打开命令行窗口win+r3.命令行中输入一下命令(1)找到你需要......
  • PbootCms上传图片变模糊、上传图片尺寸受限的解决方案
    在使用PbootCMS的过程中,如果上传的图片被压缩变得模糊,通常是因为上传的图片尺寸过大。PbootCMS默认的上传图片限制宽度为1920像素,缩略图的限制大小为1000×1000像素。可以通过调整这些参数来解决这个问题。解决方案打开 config.php 文件调整 max_width 和 max_heigh......
  • PbootCMS增加可允许上传文件类型,例如webp、mov等文件格式扩展
    在PbootCMS中增加可允许上传的文件类型(例如 webp、mov 等文件格式),需要在多个地方进行配置。以下是详细的步骤:操作步骤1.修改 config.php 文件首先需要修改 config.php 文件,增加允许上传的文件类型。打开 config.php 文件打开 config.php 文件,通常位于 /config......
  • PbootCMS缩略图上传图片被截取变模糊的解决方法
    在PBootCMS中,如果你发现缩略图被自动截取,并且没有匹配到后台设置,而是根据程序中的配置进行截取,可以通过修改配置文件来调整缩略图的大小。具体步骤如下:步骤找到配置文件打开/config/config.php文件。修改缩略图配置调整max_width和max_height参数。详细步骤1.找......
  • PbootCMS上传文件大小限制
    在PBootCMS中,如果需要上传较大的文件,需要对PHP环境进行相应的配置。以下是详细的步骤和配置方法:一、打开并修改php.ini文件开启文件上传ini file_uploads=on确保允许通过HTTP上传文件。设置临时文件夹ini upload_tmp_dir=/tmp设置文件上传至服务器上......
  • 设置nginx中文件上传的大小限制度
    通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题: 用nginx来做webserver的时,上传大文件时需要特别注意client_max_body_size这个参数,否则会中断在nginx的请求中,在php中是无法记录到访问的. 一般上传大文件流程: 首先修改php.ini文件: 参数设置说明 fil......