Jump to content

question about load glb files


feilong
 Share

Recommended Posts

I have try to load a glb file generate by microsoft 3d paint.

my file is in here.

i test createScene function in http://www.babylonjs-playground.com/#6MZV8R and it works well.but use my code it doesn't work.?  

![](chrome_2017-11-13_22-45-31.jpg)

 

console show me

![](chrome_2017-11-13_22-58-27.jpg)

my js code is before,and div with class name 'gltfobj'.

"use strict";

function setGltf(gltfarea) {
	//$(".gltfobj")[0].id.match(/(.*\/)(.*\.gl(?:b|tf))/)
	var rooturl = gltfarea.id.match(/(.*\/)(.*\.gl(?:b|tf))/)[1];
	var gltfname = gltfarea.id.match(/(.*\/)(.*\.gl(?:b|tf))/)[2];
	console.log('root: ' + rooturl + ' ,name: ' + gltfname);

	var canvas = document.createElement("CANVAS");
	canvas.width = 400;
	canvas.height = 400;
	gltfarea.appendChild(canvas);

	var engine = new BABYLON.Engine(canvas, true);

	var createScene = function () {
		// This creates a basic Babylon Scene object (non-mesh)
		var scene = new BABYLON.Scene(engine);
		// glTF Files use right handed system
		scene.useRightHandedSystem = true;

		// Configuring camera
		var camera = new BABYLON.ArcRotateCamera("camera", 1.55, 1.6, 2, BABYLON.Vector3(0, 0, 0), scene);
		camera.attachControl(canvas, true);
		camera.wheelPrecision = 100.0;
		camera.minZ = 0.01;
		camera.maxZ = 1000;

		// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
		var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
		// Default intensity is 1. Let's dim the light a small amount
		light.intensity = 0.7;

		// Append sample glTF model to scene
		BABYLON.SceneLoader.Append("https://raw.githubusercontent.com/feilongfl/pic-bed/master/201711/", "%E6%BB%91%E7%A8%BD.glb", scene, function (scene) {}, null, function (scene) {
			console.log("error!")+
		});

		return scene;
	};

	var scene = createScene();

	engine.runRenderLoop(function () {
		scene.render();
	});

	window.addEventListener("resize", function () { // Watch for browser/canvas resize events
		engine.resize();
	});
}


// require(['https://cdnjs.cloudflare.com/ajax/libs/babylonjs/3.0.1-beta/babylon.max.js'], function () {
require(['https://cdn.babylonjs.com/babylon.js'], function () {
	require(['https://cdn.rawgit.com/BabylonJS/Babylon.js/master/dist/preview%20release/loaders/babylon.glTFFileLoader.min.js'], function () {
		for (var i = 0; i < $(".gltfobj").length; i++) {
			setGltf($(".gltfobj")[i]);
			// console.log(i);
		}
	});
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...