web网页显示点云

index.html

html 复制代码
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>点云库PCL从入门到精通-PCD浏览器端可视化</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				margin: 0px;
				overflow: auto;
			}
			.header {
			background-color: #f1f1f1;
			margin: 0px;
			text-align: center;
			}
			#column {
				width: 100%;
				margin:auto;
				background-color:#f1f1f1;
			}
		</style>
	</head>
	<body>
		<div class="header">
		  <h2 style="padding-top:10px;margin-top:0px;">点云库PCL从入门到精通-PCD浏览器端可视化</h2>
		  <a style="margin:100px" href="https://threejs.org/">ThreeJS</a>
		  <a style="margin:100px" href="http://www.pclcn.org/">PCL中国</a>
		  <div style="text-align:left">
		   <p style="padding:10px;margin:0px"><span style="background-color:Orange">鼠标事件:</span>鼠标左键按住进行旋转、鼠标中间键滑动进行缩放、鼠标右键按住进行移动</p>
		  <p style="padding:10px;margin:0px"><span style="background-color:Orange">键盘事件:</span>+或-改变渲染点的大小、c键改变点云渲染颜色</p>
		  </div>

		</div>
		<div id="column">

		</div>

		<script src="js/three.min.js"></script>
		<script src="js/PCDLoader.js"></script>
		<script src="js/TrackballControls.js"></script>

		<script>
		var camera, controls, scene, renderer;
		init();
		animate();
function init() {

scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 15, window.innerWidth / window.innerHeight, 0.01, 40 );
camera.position.z = -5;
camera.up.set(0,0,1);

controls = new THREE.TrackballControls( camera );

controls.rotateSpeed = 5.0;
controls.zoomSpeed = 2;
controls.panSpeed = 3;

controls.noZoom = false;
controls.noPan = false;

controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;

controls.minDistance = 0.3;
controls.maxDistance = 0.3 * 100;

scene.add( camera );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor( 0xffffff );
renderer.setPixelRatio( window.devicePixelRatio );


renderer.setSize( window.innerWidth*0.8, window.innerHeight*0.8 );
var loader = new THREE.PCDLoader();
loader.load( './pcd/pig.pcd', function ( mesh ) {

scene.add( mesh );
var center = mesh.geometry.boundingSphere.center;
controls.target.set( center.x, center.y, center.z);
controls.update();

} );

object = new THREE.AxisHelper( 0.5 );
object.position.set( 0, 0, 0 );
scene.add( object );


container = document.getElementById("column");
renderer.domElement.style.display ="block";
renderer.domElement.style.margin ="auto";
container.appendChild(renderer.domElement);
window.addEventListener( 'resize', onWindowResize, false );
window.addEventListener('keydown', keyboard);
}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth*0.8, window.innerHeight*0.8 );
controls.handleResize();

}

			function keyboard ( ev ) {

				var pigmesh = scene.getObjectByName( "pig.pcd" );

				switch ( ev.key ) {

					case '+':
						pigmesh.material.size*=1.2;
						pigmesh.material.needsUpdate = true;
						break;

					case '-':
						pigmesh.material.size/=1.2;
						pigmesh.material.needsUpdate = true;
						break;

					case 'c':
						pigmesh.material.color.setHex(Math.random()*0xffffff);
						pigmesh.material.needsUpdate = true;
						break;

				}

			}

		function animate() {
				requestAnimationFrame( animate );
				controls.update();
				renderer.render( scene, camera );
			}
		</script>
	</body>
</html>

打开命令行运行

bash 复制代码
python -m http.server 8080

若输出

bash 复制代码
Serving HTTP on :: port 8080 (http://[::]:8080/) ...

说明本地http服务器正常启动。

此时在浏览器中输入http://127.0.0.1:8080/,若命令行打印

bash 复制代码
::ffff:127.0.0.1 - - [17/Mar/2026 18:53:38] "GET / HTTP/1.1" 304 -

则一般可以正常显示如下画面:

完整代码后续会贴出。

相关推荐
Larcher16 小时前
从 0 到 1:用 Bun + axios 快速搭建 LLM API 客户端
前端·javascript
子午16 小时前
基于DeepSeek的酒店客房管理系统~Python+DeepSeek智能问答+Vue3+Web网站系统
开发语言·前端·python
bkspiderx16 小时前
Boa Web服务器HTTPS支持的源码改造方案
服务器·前端·https·web服务器·boa·https支持
HyperAI超神经16 小时前
深度估计准确率冲上0.9,Meta提出VLM³,论证视觉模型天生会学3D,以Qwen3-VL-4B为基础实现多任务的统一建模
人工智能·3d·大模型·多模态·空间推理·3d感知·3d理解
贺今宵16 小时前
Vue 3 + Capacitor 使用jeep-sqlite,web端使用本地sqlite数据库
前端·数据库·vue.js·sqlite·web
taocarts_bidfans16 小时前
Google Indexing API 外贸独立站主动推送收录实战开发
前端·独立站·外贸独立站·taoify
lichenyang45316 小时前
鸿蒙 Stage 模型到底是什么?一篇讲清 Ability、EntryAbility 和入口文件为什么这么设计
前端
ihuyigui17 小时前
国际商超零售短信接口
大数据·前端·后端·架构·零售
Yan-英杰17 小时前
从零玩转搜索引擎 API: 多引擎整合实战
服务器·前端·microsoft
Spider_Man17 小时前
Claude Code Hooks:给 AI 助手装上"安全带"
前端·ai编程·claude