如何使用JavaScript/FileApi/XHR加载从blender导出的*.babylon?
我很好地使用了.babylon文件格式。 为Blender 3D editor开发的Exporter工作正常,如果要使用下一个代码加载导出的模型:如何使用JavaScript/FileApi/XHR加载从blender导出的*.babylon?,javascript,3d,babylonjs,Javascript,3d,Babylonjs,我很好地使用了.babylon文件格式。 为Blender 3D editor开发的Exporter工作正常,如果要使用下一个代码加载导出的模型: // won't write the full code // because it was fetched from the playground and it's very standard and works BABYLON.SceneLoader.Load("", "fileName.babylon", engine, function (n
// won't write the full code
// because it was fetched from the playground and it's very standard and works
BABYLON.SceneLoader.Load("", "fileName.babylon", engine, function (newScene) {
...
mesh.material = data.multiMaterials[ 0 ];
运行良好,浏览器中的WebGL渲染器显示了我的模型
但是,如果我不想将模型作为静态文件加载,而这些文件必须保存在HTTP服务器IIS、Apache、lighttpd、nginx等的公用文件夹中,该怎么办呢
例如,我想从用户端加载一个.babylon文件,或者在我的后端保护对.babylon文件的访问
好的,让我们来看看情况,如果我在我的web应用程序中使用浏览器中的文件API提供某种上传程序,用户将能够从他们的PC或其他设备加载3D模型
我尝试以这种方式加载模型:
工作正常的输入文件上传文件更改事件:
function handleFiles( event ) {
var uploader = event.srcElement || event.currentTarget;
var files = uploader.files;
var reader = new FileReader();
reader.onload = function( event ) {
var data = JSON.parse( event.target.result );
loadCustomMesh( data );
};
// passing only single mesh because of testing purpose
reader.readAsText( files[ 0 ] );
}
处理几何体并添加到场景:
function loadCustomMesh( data ) {
var mesh = new BABYLON.Mesh( Math.random().toString(), scene );
mesh.setVerticesData( BABYLON.VertexBuffer.PositionKind, data.meshes[ 0 ].positions, true );
mesh.setVerticesData( BABYLON.VertexBuffer.NormalKind, data.meshes[ 0 ].normals, true );
mesh.setIndices( data.meshes[ 0 ].indices );
mesh.position = new BABYLON.Vector3( 0, 0, 0 );
...
很好用!但是没有材料
我从上传的数据中发现了multimaterial:
但如果要使用下一个代码:
// won't write the full code
// because it was fetched from the playground and it's very standard and works
BABYLON.SceneLoader.Load("", "fileName.babylon", engine, function (newScene) {
...
mesh.material = data.multiMaterials[ 0 ];
这对于此示例完全有效,它会引发下一个错误:
Uncaught TypeError: t.needAlphaBlending is not a function
我甚至不知道下一步该怎么办,有什么想法吗?问题在这里解决了: