G3D基于 WebGL 的 Javascript 3D 繪圖引擎
G3D 是阿里巴巴開(kāi)源的一款基于 WebGL 的 javascript 3D 繪圖引擎。與其他的 WebGL 3D 引擎相比,G3D 是更加「純粹」的渲染引擎,也就是說(shuō),它完全不依賴(lài)任何 DOM API,而是僅僅依賴(lài)一個(gè) canvas 對(duì)象(或者類(lèi) canvas 對(duì)象)。該特性使得 G3D 不僅能夠運(yùn)行在瀏覽器環(huán)境中,也能夠運(yùn)行在一些非瀏覽器的 js 終端環(huán)境下(hybrid 環(huán)境),比如 GCanvas 環(huán)境(基于 Weex 或 ReactNative)。
Try play with G3D
function run(G3D, canvas){
// create 3d engine
const engine = new G3D.Engine(canvas); // create a scene
const scene = new G3D.Scene(engine);
// create camera
const camera = new G3D.ArcRotateCamera(scene);
camera.alpha = 45;
camera.beta = 30;
camera.radius = 12;
camera.fov = 60;
// create 3 lights
const light1 = new G3D.DirectionalLight(scene);
light1.direction.x = -1;
light1.direction.y = 0;
light1.direction.z = 1;
const light2 = new G3D.HemisphereLight(scene);
// create mesh
const mesh = G3D.MeshBuilder.createCube(scene, 6);
Object.assign(mesh.materials.default.diffuseColor, {r: 200, g: 100, b: 100}); Object.assign(mesh.materials.default.specularColor, {r: 200, g: 100, b: 100});
mesh.materials.default.glossiness = 10;
return function () {
mesh.rotation.y +=1;
scene.render();
}
}評(píng)論
圖片
表情
