![](/img/trans.png)
[英]Three.js - Parse binary STL - RangeError: Out of bounds access
[英]STLloader/THREE.js error: "Uncaught RangeError: offset is outside the bounds of the DataView"
I want to code a little viewer of stl files in javascript so for this a use the library three.js with the module STLLoader, for this viewer i use a system of upload make with an API in node.js (I send files by using fetch request and on背面強大的保存文件),對於瀏覽器,頁面通過 fetch 請求地址並獲取 stl 文件內容,現在加載 stl 數據我使用此代碼:
var contents = stl_name;
var geometry = new THREE.STLLoader().parse( contents );
geometry.sourceType = "stl";
var mesh = new THREE.Mesh( geometry, material );
mesh.rotation.x = 5;
mesh.rotation.z = .25;
scene.add( mesh );
但它返回一個錯誤(我只是在 stl 二進制文件中出現此錯誤,ASCII stl 文件工作正常):“未捕獲的 RangeError:偏移量超出了 DataView 的范圍”,我不知道如何出售它,提前謝謝你.
測試文件示例: test.stl
我可以通過拖放成功地將資產導入three.js 編輯器。 因此,您的應用程序似乎存在問題,或者您沒有使用最新版本的three.js
。
無論如何,請嘗試使用與編輯器中類似的代碼。 本質上是這樣的:
const reader = new FileReader();
reader.addEventListener( 'load', function ( event ) {
const contents = event.target.result;
const geometry = new THREE.STLLoader().parse( contents );
const material = new THREE.MeshStandardMaterial();
const mesh = new THREE.Mesh( geometry, material );
mesh.name = filename;
scene.add( mesh );
}, false );
reader.readAsArrayBuffer( file );
我終於通過在我的 API (stl) 中添加 node.js 庫來解決我的問題,將二進制 stl 轉換為 ASCII Z7646B55734E9ECEA240A。 鏈接到圖書館
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.