使用 NPM 和 Three.js 加载 PCD 文件

发布于 2025-01-13 22:55:19 字数 261 浏览 3 评论 0原文

我是 Three.js 的新手,我正在努力将 PCD 文件导入场景,如果可能的话,我需要一些帮助。

我正在使用 node.module 并使用 npm 安装了“pcd-format”。

这是我的工作空间的图片: 在此处输入图像描述

我想一开始就使用尽可能简单的代码,而不需要使用一些复杂的包来理解原理。

谢谢

I am new with Three.js and I'm struggling to import a PCD file into the scene and I would need some help if possible.

I'm using node.module and I've installed "pcd-format" using npm.

Here is an image of my workspace:
enter image description here

I would like to go with as simple code as possible for the beginning, without using some complex packages in order to understand the principles.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦境 2025-01-20 22:55:19

好吧,我会回答我的问题,因为我在其他平台上得到了类似问题的帮助。这是我所做的:

  1. 在 Visual Studio Code 的终端中: npm create vite ,安装“Vanilla”框架,初始化一个新项目“my-project”。
  2. 创建“my-project”文件夹后,我得到了 main.js 、 package.json 等文件。
  3. 从终端中的“my-project”我安装了三个: npm install Threenpm运行 dev 在 localhost:3000 上为我的应用程序提供服务
  4. 然后我导入了 PCDLoader 和用于加载从 Three.js/docs 复制的 PCD 模型的脚本 (https://thirdjs.org/docs/index.html? q=load#examples/en/loaders/PCDLoader):
document.querySelector('#app').innerHTML = `
  <h1>Ciao</h1>
  <a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
`
import { PCDLoader } from 'three/examples/jsm/loaders/PCDLoader'
console.log(PCDLoader)

const loader = new PCDLoader();

loader.load(
    // resource URL
    'pointcloud.pcd',
    // called when the resource is loaded
    function ( mesh ) {

        scene.add( mesh );

    },
    // called when loading is in progresses
    function ( xhr ) {

        console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );

    },
    // called when loading has errors
    function ( error ) {

        console.log( 'An error happened' );

    }
);

现在它可以工作了,只是当我调试时应用程序崩溃了,并且它说 DevTools 已与页面断开连接......

Well, I'll answer to my question since I got help on similar issue on the other platform. Here's what I've done:

  1. In the Terminal in Visual Studio Code: npm create vite , installed "Vanilla" framework, initialized a new project "my-project".
  2. After creating "my-project" folder I got files such as main.js , package.json , etc.
  3. From "my-project" in Terminal I installed three: npm install three and npm run dev to serve my app on localhost:3000
  4. Then I imported PCDLoader and the script for loading a PCD model that I copied from three.js/docs (https://threejs.org/docs/index.html?q=load#examples/en/loaders/PCDLoader):

document.querySelector('#app').innerHTML = `
  <h1>Ciao</h1>
  <a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
`
import { PCDLoader } from 'three/examples/jsm/loaders/PCDLoader'
console.log(PCDLoader)

const loader = new PCDLoader();

loader.load(
    // resource URL
    'pointcloud.pcd',
    // called when the resource is loaded
    function ( mesh ) {

        scene.add( mesh );

    },
    // called when loading is in progresses
    function ( xhr ) {

        console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );

    },
    // called when loading has errors
    function ( error ) {

        console.log( 'An error happened' );

    }
);

It now works except that the app crashes when I debug and it says that DevTools was disconnected from the page....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文