出于对web端3D技术的对比,以及WebGL的发展现状和WebGPU的发展前景,我觉得有必要涉猎一下babylon.js了。

可以参考一下下列文章:

1⃣️下一代web端图形接口现状与前景:https://zhuanlan.zhihu.com/p/59691803

今天就先在react里面测试一下官方demo:

demo的核心代码如下:

import {MiddleComponent,React} from '../../../utils/MiddleComponent'
import * as BABYLON from 'babylonjs'; export class babylon1 extends MiddleComponent {
constructor(props){
    super(props);
    }

  render() {
return (
<canvas id="renderCanvas" style={{width:'100%',height:'100%',position:'relative'}}></canvas>
);
} componentDidMount() {
this.init();
} init = ()=> {
// Get the canvas DOM element
var canvas = document.getElementById('renderCanvas');
// Load the 3D engine
var engine = new BABYLON.Engine(canvas, true, {preserveDrawingBuffer: true, stencil: true});
// Create a basic BJS Scene object
var scene = new BABYLON.Scene(engine);
// Create a FreeCamera, and set its position to {x: 0, y: 5, z: -10}
var camera = new BABYLON.ArcRotateCamera("Camera", ,,, BABYLON.Vector3.Zero(), scene);
// Target the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// Attach the camera to the canvas
camera.attachControl(canvas, false);
// Create a basic light, aiming 0, 1, 0 - meaning, to the sky
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(, , ), scene);
// Create a built-in "sphere" shape; its constructor takes 6 params: name, segment, diameter, scene, updatable, sideOrientation
var sphere = BABYLON.Mesh.CreateSphere('sphere1', , , scene, false, BABYLON.Mesh.FRONTSIDE);
// Move the sphere upward 1/2 of its height
sphere.position.y = ;
// Create a built-in "ground" shape; its constructor takes 6 params : name, width, height, subdivision, scene, updatable
var ground = BABYLON.Mesh.CreateGround('ground1', , , , scene, false);
// run the render loop
engine.runRenderLoop(function(){
scene.render();
});
// the canvas/window resize event handler
window.addEventListener('resize', function(){
engine.resize();
});
}
}

如果你接触过three.js的话,其实上述代码并没有什么值得讲解的地方,并且你也会发现babylon.js和three.js还是有一些差异的。

如果没有接触过three.js或者其他webgl类库或者引擎,那就先学习一下webgl相关知识吧。

注意:

MiddleComponent 是我自己封装的组件,你可以选择在你的react程序里继承自Component。

点击当前页面右上角箭头,有我自制的babylon相关api文档
 

最新文章

  1. C# - 多线程 之 异步编程
  2. Npoi导出Excel 实战篇(Webform)
  3. 用FireFox火狐浏览器的3D Tilt 插件查看网页3D视图效果
  4. FineUI第十二天---锚点布局
  5. Centos5下安装监控工具nmon
  6. Oracle SQL优化一(常见方法)
  7. Web 在线文件管理器学习笔记与总结(3)创建文件
  8. 夺命雷公狗—angularjs—10—angularjs里面的内置函数
  9. Kafka之Purgatory Redesign Proposal (翻译)
  10. python函数介绍
  11. Android 按钮按下效果
  12. Java学习之国际化程序
  13. 201521123029《Java程序设计》第1周学习总结
  14. ngRoute路径出现#!#解决方案
  15. 如何修改Recovery的字符串资源
  16. 【原创】驱动卸载之DeleteService
  17. Python 解决: from pip import main ImportError: cannot import name &#39;main&#39;
  18. CSS---伪类选择器
  19. 混合pyqt和qtcreator
  20. ThinkPHP widge使用示例

热门文章

  1. Lambda使用深入解析
  2. redis,windows设置记录
  3. Android利用json进行网络解析
  4. 通过自动回复机器人学Mybatis---加强版
  5. Linux的正则练习
  6. Linux权限操作(用户和组)
  7. redis四种部署方式
  8. 【Linux】解决用vi修改文件,保存文件时,提示“readonly option is set”
  9. centos6 mini安装图形界面,并vnc远程控制
  10. Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)