百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

web端渲染3d模型,ply,stl

lipiwang 2025-03-07 20:35 27 浏览 0 评论

最近在公司里面做一个web功能,需要在页面上渲染3d模型,主要是做口腔扫描。

做web3d,可用的js库还是很多,首先想到的就是vue-3d-model

方便快捷,但是呢ply模型的颜色显示不出来,没有着色。当然渲染的时候可以自己加颜色,但是不是我想要的。



下图是用其他3d浏览软件打开的效果

以为是js库的问题,直接换threeJs,这老大哥,很强大,也很流行了。

实际渲染效果也是一样,都是纯色。

经过我不断尝试,查找资料,终于找到了缘由。

load模型数据之后,里面有属性,我这边的口扫数据属于不同的扫描厂家,有些厂家会把着色的颜色属性打包放数据文件里面,有些厂家是直接生成材质图片,数据文件里面就给出了渲染坐标属性

包含颜色的


包含贴图坐标的


贴图材质

含贴图的,在ply 文件头部会指定贴图名称,如下图

不含贴图的打开如下


附上最终代码,说不定哪天己还来看

three.js webgl - exporter - ply

three.js webgl - exporter - ply


<script type="importmap">

{

"imports": {

"three": "../build/three.module.js",

"three/addons/": "./jsm/"

}

}

</script>


<script type="module">


import * as THREE from 'three';


import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';




let scene, camera, renderer, mesh;


init();


function init() {


camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );

camera.position.set( 4, 2, 4 );

scene = new THREE.Scene();

scene.background = new THREE.Color( 0xa0a0a0 );

scene.fog = new THREE.Fog( 0xa0a0a0, 4, 20 );



const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444, 3 );

hemiLight.position.set( 0, 20, 0 );

scene.add( hemiLight );


const ground = new THREE.Mesh( new THREE.PlaneGeometry( 40, 40 ), new THREE.MeshPhongMaterial( { color: 0xcbcbcb, depthWrite: false } ) );

ground.rotation.x = - Math.PI / 2;

ground.receiveShadow = true;

scene.add( ground );


const grid = new THREE.GridHelper( 40, 20, 0x000000, 0x000000 );

grid.material.opacity = 0.2;

grid.material.transparent = true;

scene.add( grid );

let uvTexture = new THREE.TextureLoader().load("./models/ply/test/zp/UpperJaw.jpg");


const loader = new PLYLoader();

loader.load( './models/ply/test/zp/240930055-upperjaw.ply', function ( geometry) {

console.log('ply',geometry)

geometry.computeVertexNormals();

const material = new THREE.MeshStandardMaterial({

map: uvTexture,

transparent: true

});

const mesh = new THREE.Mesh( geometry, material );

mesh.position.y = - 0;

mesh.position.z = 0;

mesh.rotation.x = - Math.PI / 2;

mesh.scale.multiplyScalar( 0.01 );

mesh.castShadow = true;

mesh.receiveShadow = true;

scene.add( mesh );

});



loader.load( './models/ply/test/yes.ply', function ( geometry) {

console.log('ply',geometry,'color',geometry.getAttribute('color'))

geometry.computeVertexNormals();

const material = new THREE.PointsMaterial({

size: 0.01, vertexColors: true

});

const mesh = new THREE.Points( geometry, material );

mesh.position.y = - 0;

mesh.position.z = 0;

mesh.rotation.x = - Math.PI / 2;

mesh.scale.multiplyScalar( 0.01 );

mesh.castShadow = true;

mesh.receiveShadow = true;

scene.add( mesh );

} );



//


renderer = new THREE.WebGLRenderer( { antialias: true } );

renderer.setPixelRatio( window.devicePixelRatio );

renderer.setSize( window.innerWidth, window.innerHeight );

renderer.setAnimationLoop( animate );

renderer.shadowMap.enabled = true;

document.body.appendChild( renderer.domElement );


//


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

controls.target.set( 0, 0.5, 0 );

controls.update();


//


window.addEventListener( 'resize', onWindowResize );


}


function onWindowResize() {


camera.aspect = window.innerWidth / window.innerHeight;

camera.updateProjectionMatrix();


renderer.setSize( window.innerWidth, window.innerHeight );


}


function animate() {


renderer.render( scene, camera );


}

</script>




最终渲染效果,一个是贴图,一个是颜色。

相关推荐

ubuntu单机安装open-falcon极度详细操作

备注:以下操作均由本人实际操作并得到验证,喜欢的同学可尝试操作安装。步骤一1.1环境准备(使用系统:ubuntu18.04)1.1.1安装redisubuntu下安装(参考借鉴:https://...

Linux搭建promtail、loki、grafana轻量日志监控系统

一:简介日志监控告警系统,较为主流的是ELK(Elasticsearch、Logstash和Kibana核心套件构成),虽然优点是功能丰富,允许复杂的操作。但是,这些方案往往规模复杂,资源占用高,...

一文搞懂,WAF阻止恶意攻击的8种方法

WAF(Web应用程序防火墙)是应用程序和互联网流量之间的第一道防线,它监视和过滤Internet流量以阻止不良流量和恶意请求,WAF是确保Web服务的可用性和完整性的重要安全解决方案。它...

14配置appvolume(ios14.6配置文件)

使用AppVolumes应用程序功能,您可以管理应用程序的整个生命周期,包括打包、更新和停用应用程序。您还可以自定义应用程序分配,以向最终用户提供应用程序的特定版本14.1安装appvolume...

目前流行的缺陷管理工具(缺陷管理方式存在的优缺点)

摘自:https://blog.csdn.net/jasonteststudy/article/details/7090127?utm_medium=distribute.pc_relevant.no...

开源数字货币交易所开发学习笔记(2)——SpringCloud

前言码云(Gitee)上开源数字货币交易所源码CoinExchange的整体架构用了SpringCloud,对于经验丰富的Java程序员来说,可能很简单,但是对于我这种入门级程序员,还是有学习的必要的...

开发JAX-RPC Web Services for WebSphere(下)

在开发JAX-RPCWebServicesforWebSphere(上)一文中,小编为大家介绍了如何创建一个Web服务项目、如何创建一个服务类和Web服务,以及部署项目等内容。接下来小编将为大...

CXF学习笔记1(cxf client)

webservice是发布服务的简单并实用的一种技术了,个人学习了CXF这个框架,也比较简单,发布了一些笔记,希望对笔友收藏并有些作用哦1.什么是webServicewebService让一个程序可...

分布式RPC最全详解(图文全面总结)

分布式通信RPC是非常重要的分布式系统组件,大厂经常考察的Dubbo等RPC框架,下面我就全面来详解分布式通信RPC@mikechen本篇已收于mikechen原创超30万字《阿里架构师进阶专题合集》...

Oracle WebLogic远程命令执行0day漏洞(CVE-2019-2725补丁绕过)预警

概述近日,奇安信天眼与安服团队通过数据监控发现,野外出现OracleWebLogic远程命令执行漏洞最新利用代码,此攻击利用绕过了厂商今年4月底所发布的最新安全补丁(CVE-2019-2725)。由...

Spring IoC Container 原理解析(spring中ioc三种实现原理)

IoC、DI基础概念关于IoC和DI大家都不陌生,我们直接上martinfowler的原文,里面已经有DI的例子和spring的使用示例《InversionofControlContainer...

Arthas线上服务器问题排查(arthas部署)

1Arthas(阿尔萨斯)能为你做什么?这个类从哪个jar包加载的?为什么会报各种类相关的Exception?我改的代码为什么没有执行到?难道是我没commit?分支搞错了?遇到问题无法在...

工具篇之IDEA功能插件HTTP_CLENT(idea2021插件)

工具描述:Java开发人员通用的开发者工具IDEA集成了HTTPClient功能,之后可以无需单独安装使用PostMan用来模拟http请求。创建方式:1)简易模式Tools->HTTPCl...

RPC、Web Service等几种远程监控通信方式对比

几种远程监控通信方式的介绍一.RPCRPC使用C/S方式,采用http协议,发送请求到服务器,等待服务器返回结果。这个请求包括一个参数集和一个文本集,通常形成“classname.meth...

《github精选系列》——SpringBoot 全家桶

1简单总结1SpringBoot全家桶简介2项目简介3子项目列表4环境5运行6后续计划7问题反馈gitee地址:https://gitee.com/yidao620/springbo...

取消回复欢迎 发表评论: