STEM 隨筆︰古典力學︰模擬術【四】

故而為了方便講談之故,依據遵循PyDy 推薦範例

Tutorials

We have a couple of tutorials. The human standing tutorial takes you through an entire workflow for a dynamics and control problem and is a good place to start.

……

的寫法︰

/pydy-tutorial-human-standing

 Introduction

This is the material for a tutorial on analyzing multibody dynamics with scientific Python tools. It was first given as “Simulation and Control of Biomechanical Systems with Python” at the Midwest American Society of Biomechanics Regional meeting on March 4th, 2014 in Akron, Ohio. Modified versions have subsequently been given at PYCON2014, SCIPY2014, and SCIPY2015.

The tutorial covers these main topics:

  • Symbolic derivation of equations of motion for multibody systems.
  • Numerical simulation of the resulting system.
  • 3D visualization of the motion of the system.
  • Optimal feedback control for stabilization.

The attendees will be exposed to various functionality of these Python tools:

License

All materials herein are licensed under Create Commons Attribution 4.0.

Versions

A new version of the tutorial is typically created each time the tutorial is given to incorporate feedback from the attendees and for software updates. These versions can be downloaded from:

https://github.com/pydy/pydy-tutorial-human-standing/releases

Example Problem

The tutorial will go through the PyDy workflow in small steps. At the end the students should have a working 3-link 2D inverted pendulum model of a human that can be used for balancing studies. The free body diagram of the model is shown below:

notebooks/figures/human_balance_diagram.png

………

 

開始後續旅程也!

─── 《STEM 隨筆︰古典力學︰向量【四下】

 

經過了三個多月的深度旅遊,終於抵達了終點站︰

n09_control.ipynb

 In this last notebook, we will create a full state feedback controller that will allow the human model to balance. There isn’t time to give a good overview of controls, but we will use a very common optimal control method to quickly create a controller for our system.

 

相信讀者也對『派生動力學』 PyDy 有了一定的認識!

何不就給自己按個讚吧!!

 

 

 

 

 

 

 

STEM 隨筆︰古典力學︰模擬術【小工具】九《WebGL》 C

待讀者嫻熟 pythreejs 

Animation

………

 

能寫『關鍵格』

Key frame

A keyframe in animation and filmmaking is a drawing that defines the starting and ending points of any smooth transition. The drawings are called “frames” because their position in time is measured in frames on a strip of film. A sequence of keyframes defines which movement the viewer will see, whereas the position of the keyframes on the film, video, or animation defines the timing of the movement. Because only two or three keyframes over the span of a second do not create the illusion of movement, the remaining frames are filled with inbetweens.

Use of keyframes as a means to change parameters

In software packages that support animation, especially 3D graphics, there are many parameters that can be changed for any one object. One example of such an object is a light (In 3D graphics, lights function similarly to real-world lights. They cause illumination, cast shadows, and create specular highlights). Lights have many parameters including light intensity, beam size, light color, and the texture cast by the light. Supposing that an animator wants the beam size of the light to change smoothly from one value to another within a predefined period of time, that could be achieved by using keyframes. At the start of the animation, a beam size value is set. Another value is set for the end of the animation. Thus, the software program automatically interpolates the two values, creating a smooth transition.

 

動畫後,當可跨越 pydy

天下事分分合合,往往各以其理!

搭配起來常常多處不適,於是煩惱生耶?

如今那

/pydy-viz

pydy-viz

Notice

pydy-viz has been merged into the main pydy repository. This independent project is now deprecated, all development and subsequent releases will be from http://github.com/pydy/pydy.

Visualization of multibody systems generated with PyDy.

 

已經合併!

恰巧正逢這

/ipywidgets

Interactive widgets for the Jupyter Notebook https://ipywidgets.readthedocs.io

ipywidgets: Interactive HTML Widgets

Version Build Status Documentation Status Join the chat at https://gitter.im/ipython/ipywidgets

ipywidgets are interactive HTML widgets for Jupyter notebooks and the IPython kernel.

Notebooks come alive when interactive widgets are used. Users gain control of their data and can visualize changes in the data.

Learning becomes an immersive, plus fun, experience. Researchers can easily see how changing inputs to a model impact the results. We hope you will add ipywidgets to your notebooks, and we’re here to help you get started.

Core Interactive Widgets

A demonstration notebook provides an overview of the core interactive widgets, including:

  • sliders
  • progress bars
  • text boxes
  • toggle buttons and checkboxes
  • display areas
  • and more

Jupyter Interactive Widgets as a Framework

Besides the widgets already provided with the library, the framework can be extended with custom widget libraries.

A template project is available in the form of a cookie cutter here.

This project is meant to help custom widget authors get started with the packaging and the distribution of Jupyter interactive widgets.

It produces a project for a Jupyter interactive widget library following the current best practices for using interactive widgets. An implementation for a placeholder “Hello World” widget is provided.

Popular widget libraries such as bqplot, pythreejs and ipyleaflet

follow exactly the same template and directory structure. They can serve as more advanced examples of usage of the Jupyter widget infrastructure.

For detailed information, please refer to the ipywidgets documentation.

 

早定分殊?

此所以整合過程憂報不斷乎?!

‧ Not working across all browsers and OSs #113

‧ ipywidgets 5.0 has been released and is backwards incompatible #348

……

莫說沒有熱忱者開道來告知︰

You can modify the cell like this until a fix has been merged:

scene.display_ipython()
import IPython.display
IPython.display.display(IPython.display.HTML(scene._html_widget.value))

方不方便,宜且不宜,端賴用者矣!?

─── 摘自《STEM 隨筆︰古典力學︰模擬術【可視化】 B

 

viz

Introduction

The viz package in pydy is designed to facilitate browser based animations for PyDy framework.

Typically the plugin is used to generate animations for multibody systems. The systems are defined with sympy.physics.mechanics, solved numerically with the codegen package and scipy, and then visualized with this package. But the required data for the animations can theorectically be generated by other methods and passed into a Scene object.

The frontend is based on three.js, a popular interface to the WebGraphics Library (WegGL). The package provides a Python wrapper for some basic functionality for Three.js i.e Geometries, Lights, Cameras etc.

 

的門檻,自己動手作的呦◎

 

 

 

 

 

 

 

 

STEM 隨筆︰古典力學︰模擬術【小工具】九《WebGL》 B

唐朝白居易〈長恨歌〉寫︰上窮碧落下黃泉,兩處茫茫皆不見。

今文件完備,無須四處谷歌,不過是『從上往下』︰

pythreejs/examples/threejs/

 

打洞固樁,求其一氣貫通也︰

/threejs forked from mrdoob/three.js

threejs/examples/webgl_interactive_voxelpainter.html

<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - interactive - voxel painter</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
			}
			#oldie { background-color: #ddd !important }
		</style>
	</head>
	<body>

		<script src="../build/three.min.js"></script>

		<script src="js/Detector.js"></script>
		<script src="js/libs/stats.min.js"></script>

		<script src='js/libs/DAT.GUI.min.js'></script>

		<script>

………

 

豈不能抵達根本耶?

Three.js

Three.js是一個跨瀏覽器的腳本,使用JavaScript函數庫API來在網頁瀏覽器中創建和展示動畫的三維計算機圖形。Three.js使用WebGL。原始碼託管在GitHub

概述

Three.js允許使用JavaScript創建網頁中的GPU加速的3D動畫元素,而不是使用特定的瀏覽器插件。[3][4]這歸功於WebGL的出現。[5]

高級的JavaScript函數庫例如Three.js或GLGE、SceneJS、PhiloGL或一定數量的其他函數庫使作者在瀏覽器中顯示複雜的三維計算機動畫而不需要使用傳統的獨立應用程式或插件成為可能。[6]

歷史

Three.js由Ricardo Cabello在2010四月於GitHub首次發布。[2]它的起源可以追溯到他在本世紀初演示場景的參與。代碼最初是在ActionScript,稍後2009年移植到JavaScript。在Cabello看來,轉移到JavaScript有兩個優點:每次運行前沒有編譯代碼和平台獨立性。隨著WebGL的到來,Paul Brunt增加渲染功能,這使Three.js的設計與繪製的代碼作為一個模塊,而不是核心本身。[7]Cabello的貢獻包括API的設計、CanvasRenderer、 SVGRenderer並負責合併各種貢獻到該項目。

該項目的二號貢獻者Branislav Ulicny在2010年張貼在自己的網站一些WebGL演示後開始參與Three.js的開發工作。他希望Three.js中的WebGL渲染能力超過CanvasRenderer或SVGRenderer。[7]他的主要貢獻通常涉及素材、著色器和後處理。

稍後在 WebGL 1.0 在2011年引入火狐4後,Joshua Koo開始參與工作。他在2011年9月創建了他的第一個面向3D文本的Three.js樣本。[7] 目前該項目總共有650次貢獻。[7]

特性

Three.js包括以下特性:[8]

  • 效果:浮雕,對眼和視差屏障。
  • 場景:在運行時添加和刪除對象;霧
  • 鏡頭:視角和正字法;控制器:軌跡球、FPS、路徑等
  • 動畫:電樞,運動學,逆運動學,變形和關鍵幀
  • 燈光:環境、方向、點和點光;陰影:投射和接收
  • 材料:Lambert、海防、光滑陰影,紋理和更多
  • 材質:訪問完整的OpenGL著色語言(GLSL)能力:鏡頭光暈,經過深入而廣泛的後置處理庫
  • 對象:網格、粒子、精靈、線、帶、骨頭和更多-所有細節層次
  • 幾何:平面,立方體,球體,圓環,3D文本等;修改器:車床,擠壓和管
  • 數據加載器:二進位,圖像,JSON和場景
  • 事業:全套時間和三維數學函數包括錐、矩陣、四元、UVs等
  • 輸入輸出:three.js-compatible JSON文件:Blender,openctm,FBX,Max,OBJ
  • 支持:API文檔正在建設中,公共論壇和維基全面運作
  • 例子:超過150個文件的編碼例子加字體,模型,紋理,聲音和其他支持文件
  • 調試:Stats.js,[9] WebGL檢查員[10],Three.js檢查員[11]

Three.js在所有支持WebGL 1.0的瀏覽器皆可運行。

Three.js依據MIT公用許可證發布。[1]

───

Main Page

 

 

 

 

 

 

 

 

STEM 隨筆︰古典力學︰模擬術【小工具】九《WebGL》 A

差不多先生傳‧胡適

你知道中國最有名的人是誰?提起此人,人人皆曉,處處聞名,他姓差,名不多,是各省各縣各村人氏。你一定見過他,一定聽過別人談起他,差不多先生的名字,天天掛在大家的口頭,因為他是中國全國人的代表。

差不多先生的相貌,和你和我都差不多。他有一雙眼睛,但看的不很清楚;有兩隻耳朵,但聽的不很分明;有鼻子和嘴,但他對於氣味和口味都不很講究;他的腦子也不小,但他的記性卻不很精明,他的思想也不細密。

他常常說:「凡事只要差不多,就好了。何必太精明呢?」

他小時候,他媽叫他去買紅糖,他買了白糖回來,他媽罵他,他搖搖頭道:「紅糖,白糖,不是差不多嗎?」

他在學堂的時候,先生問他:「直隸省的西邊是哪一省?」他說是陝西。先生說:「錯了,是山西,不是陝西。」他說:「陝西同山西,不是差不多嗎?」

後來他在一個錢鋪裏做夥計;他也會寫,也會算,只是總不會精細 ;十字常常寫成千字,千字常常寫成十字。掌櫃的生氣了,常常罵他,他只笑嘻嘻地賠小心道:「千字比十字多一小撇,不是差不多嗎?」

有 一天,他為了一件要緊的事,要搭火車到上海去,他從從容容地走到火車站,遲了兩分鐘,火車已開走了。他白瞪著眼,望著遠遠的火車上的煤煙,搖搖頭道:「只 好明天再走了,今天走同明天走 ,也還差不多;可是火車公司未免太認真了。八點三十分開,同八點三十二分開,不是差不多嗎?」他一面說,一面慢慢地走回家,心裏總不很明白為甚麼火車不肯 等他兩分鐘。

有 一天,他忽然得一急病,趕快叫家人去請東街的汪先生。那家人急急忙忙跑去,一時尋不著東街的汪大夫,卻把西街的牛醫王大夫請來了。差不多先生病在脇上,知 道尋錯了人;但病急了,身上痛苦,心裏焦急,等不得了,心裏想道:「好在王大夫同汪大夫也差不多,讓他試試看罷。」於是這位牛醫王大夫走近脇前,用醫牛的 法子給差不多先生治病。不上一點鐘,差不多先生就一命嗚呼了。

差不多先生差不多要死的時候,一口氣斷斷續續地說道:「活人同死人也差……差……差……不多,……凡事只要……差……差……不多……就……好了,何……必……太……太認真呢?」他說完了這句格言,就絕了氣。

他死後,大家都很稱讚差不多先生樣樣事情看得破,想得通;大家都說他一生不肯認真,不肯算帳,不肯計較,真是一位有德行的人 。於是大家給他取個死後的法號,叫他做圓通大師。

他的名譽愈傳愈遠,愈久愈大,無數無數的人,都學他的榜樣,於是人人都成了一個差不多先生。──然而中國從此就成了一個懶人國了。

 

試想『相機』所見與『隻眼』相同嗎?之前《光的世界》系列文本已嚐試解說過很多『光學系統』問題哩!

……

─── 《GOPIGO 小汽車︰格點圖像算術《投影幾何》《序》

 

怎樣能不做『差不多』先生耶?請讀 three.js 起始文本第一篇︰

Creating the scene

To actually be able to display anything with three.js, we need three things: scene, camera and renderer, so that we can render the scene with camera.

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

Let’s take a moment to explain what’s going on here. We have now set up the scene, our camera and the renderer.

There are a few different cameras in three.js. For now, let’s use a PerspectiveCamera.

The first attribute is the field of view. FOV is the extent of the scene that is seen on the display at any given moment. The value is in degrees.

The second one is the aspect ratio. You almost always want to use the width of the element divided by the height, or you’ll get the same result as when you play old movies on a widescreen TV – the image looks squished.

The next two attributes are the near and far clipping plane. What that means, is that objects further away from the camera than the value of far or closer than near won’t be rendered. You don’t have to worry about this now, but you may want to use other values in your apps to get better performance.

Next up is the renderer. This is where the magic happens. In addition to the WebGLRenderer we use here, three.js comes with a few others, often used as fallbacks for users with older browsers or for those who don’t have WebGL support for some reason.

In addition to creating the renderer instance, we also need to set the size at which we want it to render our app. It’s a good idea to use the width and height of the area we want to fill with our app – in this case, the width and height of the browser window. For performance intensive apps, you can also give setSize smaller values, like window.innerWidth/2 andwindow.innerHeight/2, which will make the app render at half size.

If you wish to keep the size of your app but render it at a lower resolution, you can do so by calling setSize with false as updateStyle (the third argument). For example,setSize(window.innerWidth/2, window.innerHeight/2, false) will render your app at half resolution, given that your <canvas> has 100% width and height.

Last but not least, we add the renderer element to our HTML document. This is a <canvas> element the renderer uses to display the scene to us.

“That’s all good, but where’s that cube you promised?” Let’s add it now.

var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );

camera.position.z = 5;

To create a cube, we need a BoxGeometry. This is an object that contains all the points (vertices) and fill (faces) of the cube. We’ll explore this more in the future.

In addition to the geometry, we need a material to color it. Three.js comes with several materials, but we’ll stick to the MeshBasicMaterial for now. All materials take an object of properties which will be applied to them. To keep things very simple, we only supply a color attribute of 0x00ff00, which is green. This works the same way that colors work in CSS or Photoshop (hex colors).

The third thing we need is a Mesh. A mesh is an object that takes a geometry, and applies a material to it, which we then can insert to our scene, and move freely around.

By default, when we call scene.add(), the thing we add will be added to the coordinates (0,0,0). This would cause both the camera and the cube to be inside each other. To avoid this, we simply move the camera out a bit.

Rendering the scene

If you copied the code from above into the HTML file we created earlier, you wouldn’t be able to see anything. This is because we’re not actually rendering anything yet. For that, we need what’s called a render or animate loop.

function animate() {
	requestAnimationFrame( animate );
	renderer.render( scene, camera );
}
animate();

This will create a loop that causes the renderer to draw the scene every time the screen is refreshed (on a typical screen this means 60 times per second). If you’re new to writing games in the browser, you might say “why don’t we just create a setInterval ?” The thing is – we could, but requestAnimationFrame has a number of advantages. Perhaps the most important one is that it pauses when the user navigates to another browser tab, hence not wasting their precious processing power and battery life.

Animating the cube

If you insert all the code above into the file you created before we began, you should see a green box. Let’s make it all a little more interesting by rotating it.

Add the following right above the renderer.render call in your animate function:

cube.rotation.x += 0.01;
cube.rotation.y += 0.01;

This will be run every frame (normally 60 times per second), and give the cube a nice rotation animation. Basically, anything you want to move or change while the app is running has to go through the animate loop. You can of course call other functions from there, so that you don’t end up with a animate function that’s hundreds of p.

───

 

細數其中『術語』有多少懂得不懂得!

再讀 pythreejs 簡介

Introduction

The pythreejs API attempts to mimic the three.js API as closely as possible, so any resource on its API should also be helpful for understanding pythreejs. See for example the official three.js documentation.

The major difference between the two is the render loop. As we normally do not want to call back to the kernel for every rendered frame, some helper classes have been created to allow for user interaction with the scene with minimal overhead:

Renderer classes

While the WebGLRenderer class mimics its three.js counterpart in only rendering frames on demand (one frame per call to its render() method), the Renderer class sets up an interactive render loop allowing for Interactive controls and Animation views. Similarly, a Preview widget allows for a quick visualization of various threejs objects.

Interactive controls

These are classes for managing user interaction with the WebGL canvas, and translating that into actions. One example is the OrbitControls class, which allows the user to control the camera by zooming, panning, and orbital rotation around a target. Another example is the Picker widget, which allows for getting the objects and surface coordinates underneath the mouse cursor.

To use controls, pass them to the renderer, e.g.:

Renderer(controls=[OrbitControls(...), ...], ...)

Animation views

The view widgets for the AnimationAction class gives interactive controls to the user for controlling a threejs animation.


Other notable deviations from the threejs API are listed below:

  • Buffers are based on numpy arrays, with their inbuilt knowledge of shape and dtype. As such, most threejs APIs that take a buffer are slightly modified (fewer options need to be specified explicitly).
  • The generative geometry objects (e.g. SphereGeometry and BoxBufferGeometry) do not sync their vertices or similar data by default. To gain acess to the generated data, convert them to either the Geometry or BufferGeometry type with the from_geometry() factory method.
  • Methods are often not mirrored to the Python side. However, they can be executed with theexec_three_obj_method() method. Consider contributing to make methods directly available. Possibly, these can be auto-generated as well.

 

及其範例

Examples

This section contains several examples generated from Jupyter notebooks. The widgets have been embedded into the page.

 

且思可有快速掌握 之法?!作者不知,莫我問也!?

不過若不得不時,會用『倒吃甘蔗』、『反織蛛網』挑戰之矣☆★

 

 

 

 

 

 

 

STEM 隨筆︰古典力學︰模擬術【小工具】九《WebGL》

實現一個長青之程式庫非常不容易︰

OpenGL

OpenGL英語:Open Graphics Library,譯名:開放圖形庫或者「開放式圖形庫」)是用於彩現2D3D向量圖形的跨語言跨平台應用程式編程介面(API)。這個介面由近350個不同的函式呼叫組成,用來從簡單的圖形位元繪製複雜的三維景象。而另一種程式介面系統是僅用於Microsoft Windows上的Direct3D。OpenGL常用於CAD虛擬實境、科學視覺化程式和電子遊戲開發

OpenGL的高效實現(利用了圖形加速硬體)存在於Windows,部分UNIX平台和Mac OS。這些實現一般由顯示裝置廠商提供,而且非常依賴於該廠商提供的硬體。開放原始碼函式庫Mesa是一個純基於軟體的圖形API,它的代碼相容於OpenGL。但是,由於許可證的原因,它只聲稱是一個「非常相似」的API。

OpenGL規範由1992年成立的OpenGL架構評審委員會(ARB)維護。ARB由一些對建立一個統一的、普遍可用的API特別感興趣的公司組成。根據OpenGL官方網站,2002年6月的ARB投票成員包括3DlabsApple ComputerATI TechnologiesDell ComputerEvans & SutherlandHewlett-PackardIBMIntelMatroxNVIDIASGISun MicrosystemsMicrosoft曾是創立成員之一,但已於2003年3月退出。

設計

 圖形管線

OpenGL規範描述了繪製2D和3D圖形的抽象API。儘管這些API可以完全通過軟體實現,但它是為大部分或者全部使用硬體加速而設計的。

OpenGL的API定義了若干可被客戶端程式調用的函式,以及一些具名整型常數(例如,常數GL_TEXTURE_2D對應的十進制整數為3553)。雖然這些函式的定義表面上類似於C編程語言,但它們是語言獨立的。因此,OpenGL有許多語言綁定,值得一提的包括 :JavaScript綁定的WebGL(基於OpenGL ES 2.0在Web瀏覽器中的進行3D彩現的API);C綁定的WGL、GLX和CGL;iOS提供的C綁定;Android提供的Java和C綁定。

OpenGL不僅語言無關,而且平台無關。規範隻字未提獲得和管理OpenGL上下文相關的內容,而是將這些作為細節交給底層的窗口系統。出於同樣的原因,OpenGL純粹專注於彩現,而不提供輸入 、音訊以及窗口相關的API。

OpenGL是一個不斷進化的API。新版OpenGL規範會定期由Khronos Group發布,新版本通過擴展API來支援各種新功能。每個版本的細節由Khronos Group的成員一致決定,包括顯卡廠商、作業系統設計人員以及類似MozillaGoogle的一般性技術公司

除了核心API要求的功能之外,GPU供應商可以通過擴展的形式提供額外功能。擴展可能會引入新功能和新常數,並且可能放鬆或取消現有的OpenGL函式的限制。然後一個擴充功能就分成兩部分發布:包含擴充功能函式原型的表頭檔和作為廠商的裝置驅動。供應商使用擴展公開自定義的API而無需獲得其他供應商或Khronos Group的支援,這大大增加了OpenGL的靈活性。OpenGL Registry負責所有擴展的收集和定義。

每個擴展都與一個簡短的標識符關聯,該標識符基於開發公司的名稱。例如,英偉達(nVidia)的標識符是NV。如果多個供應商同意使用相同的API來實現相同的功能,那麼就用EXT標誌符。這種情況更進一步,Khronos Group的架構評審委員(Architecture Review Board,ARB)正式批准該擴展,那麼這就被稱為一個「標準擴展」,標識符使用ARB。第一個ARB擴展是GL_ARB_multitexture。

OpenGL每個新版本中引入的功能,特別是ARB和EXT類型的擴展,通常由數個被廣泛實現的擴展功能組合而成。

 

推廣一種共通的標準又談何簡單︰

WebGL

WebGL是一種JavaScript API,用於在不使用外掛程式的情況下在任何相容的網頁瀏覽器中呈現互動式2D和3D圖形[2]。WebGL完全整合到瀏覽器的所有網頁標準中,可將影像處理和效果的GPU加速使用方式當做網頁Canvas的一部分。WebGL元素可以加入其他HTML元素之中並與網頁或網頁背景的其他部分混合[3]。WebGL程式由JavaScript編寫的控制代碼和OpenGL Shading Language(GLSL)編寫的著色器代碼組成,該語言類似於CC++,並在電腦的圖形處理器(GPU)上執行。WebGL由非營利Khronos Group設計和維護[4]

設計

WebGL 1.0基於OpenGL ES 2.0,並提供了3D圖形的API[5]。它使用HTML5 Canvas並允許利用文件物件模型介面。WebGL 2.0基於OpenGL ES 3.0,確保了提供許多選擇性的WebGL 1.0擴充功能,並引入新的API[6]。可利用部分Javascript實現自動記憶體管理[4]

歷史

WebGL起源於Mozilla員工弗拉基米爾·弗基西維奇的一項稱為Canvas 3D實驗計畫。2006年,弗基西維奇首次展示了Canvas 3D的原型。2007年底在Firefox[7]和Opera[8]被實作。

在2009年初,非營利技術聯盟Khronos Group啟動了WebGL的工作組,最初的工作成員包括AppleGoogleMozillaOpera[4][9]。2011年3月發布WebGL 1.0規範[1]。截至2012年3月,工作組的主席由肯·羅素(Ken Russell,全名「Kenneth Bradley Russell」)擔任。

WebGL的早期應用包括Zygote Body[10][11]

WebGL 2規範的發展始於2013年,並於2017年1月完成[12]。該規範基於OpenGL ES 3.0[13]。首度實作在Firefox 51、Chrome 56和Opera 43中[14]

 

因著原本打算介紹

pythreejs

Version: 1.1.0

pythreejs is a Jupyter widgets based notebook extension that allows Jupyter to leverage the WebGL capabilities of modern browsers by creating bindings to the javascript library three.js.

By being based on top of the jupyter-widgets infrastructure, it allows for eased integration with other interactive tools for notebooks.

 

。此處先提 three.js ,不過權充啟始引言耳。

three.jsr93

 

【範例】

Creating a scene

The goal of this section is to give a brief introduction to three.js. We will start by setting up a scene, with a spinning cube. A working example is provided at the bottom of the page in case you get stuck and need help.

Before we start

Before you can use three.js, you need somewhere to display it. Save the following HTML to a file on your computer, along with a copy of three.js in the js/ directory, and open it in your browser.

……

 

【稿本】

<html>
	<head>
		<title>My first three.js app</title>
		<style>
			body { margin: 0; }
			canvas { width: 100%; height: 100% }
		</style>
	</head>
	<body>
		<script src="js/three.js"></script>
		<script>
			var scene = new THREE.Scene();
			var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );

			var renderer = new THREE.WebGLRenderer();
			renderer.setSize( window.innerWidth, window.innerHeight );
			document.body.appendChild( renderer.domElement );

			var geometry = new THREE.BoxGeometry( 1, 1, 1 );
			var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
			var cube = new THREE.Mesh( geometry, material );
			scene.add( cube );

			camera.position.z = 5;

			var animate = function () {
				requestAnimationFrame( animate );

				cube.rotation.x += 0.1;
				cube.rotation.y += 0.1;

				renderer.render( scene, camera );
			};

			animate();
		</script>
	</body>
</html>

 

【顯示】