-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLAnimation #105
Open
trusktr
wants to merge
12
commits into
main
Choose a base branch
from
WebGLAnimation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WebGLAnimation #105
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a5231d5
update comments on this.
p3nGu1nZz 4f765ff
Merge pull request #101 from lume/master
p3nGu1nZz fef28c4
Implemented .setContext of WebGLAnimation class and created two place…
p3nGu1nZz 07be577
Added WebGLAnimationFrame to recusrively call itself.
p3nGu1nZz e98ff59
update index.spec.ts with new test
p3nGu1nZz 97aefbc
BufferGeometry addGroup and clearGroups methods
trusktr aa7a674
initial BoxBufferGeometry class completed
trusktr 81a190b
port MeshPhongMaterial
trusktr 3ae84b4
Strongly type BufferGeometryGroup as an Array over any[]; added addit…
p3nGu1nZz 8e4ca09
added shorthand for 'new Arrays' AS will optimize this to the proper …
p3nGu1nZz 6e8c949
added shortcut for creating or reusing array memory.
p3nGu1nZz 245ac3f
Merge pull request #106 from lume/master
p3nGu1nZz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @author Kara Rawson / [email protected] | ||
*/ | ||
|
||
import { WebGL2RenderingContext } from "./WebGL2RenderingContext"; | ||
|
||
/** | ||
* Test class used to verify that we have the WebGL2RenderingContext placeholder | ||
* within GLAS. This will be replaced with the real WebGLRenderingContext class. | ||
*/ | ||
describe('Renderers', () => { | ||
test('WebGL2RenderingContext_', (): void => { | ||
var context: WebGL2RenderingContext = new WebGL2RenderingContext() | ||
expect(context.context).toBe(2, | ||
"Make sure we are using version 2.x of WebGL in the 'WebGL2RenderingContext' class") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @author Kara Rawson / [email protected] | ||
*/ | ||
|
||
import { WebGLAnimationFrame } from "./webgl/WebGLAnimation"; | ||
|
||
/** | ||
* simple placeholder class until we get support with AS web glue which is meant | ||
* to provide access to the underlying context canvas element that exposes the | ||
* GL layer of the browser. | ||
*/ | ||
export class WebGL2RenderingContext { | ||
context: i8 = 2 // version placeholder | ||
|
||
//// TODO needs ASGLue module to access native context canvas of GL in the browser | ||
|
||
// functions or properties required for testing | ||
|
||
requestAnimationFrame(animationLoop: WebGLAnimationFrame): void { | ||
// ... | ||
} | ||
} | ||
|
||
/* lib.dom.d.ts -- interface reference from the domlib | ||
interface WebGL2RenderingContext extends WebGL2RenderingContextBase, WebGL2RenderingContextOverloads, WebGLRenderingContextBase { | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @author Kara Rawson / [email protected] | ||
*/ | ||
|
||
import { WebGLRenderingContext } from "./WebGLRenderingContext"; | ||
|
||
/** | ||
* Test class used to verify that we have the WebGLRenderingContext placeholder | ||
* within GLAS. This will be replaced with the real WebGLRenderingContext class. | ||
*/ | ||
describe('Renderers', () => { | ||
test('WebGLRenderingContext_', (): void => { | ||
var context: WebGLRenderingContext = new WebGLRenderingContext() | ||
expect(context.context).toBe(1, | ||
"Make sure we are using version 1.x of WebGL in the 'WebGLRenderingContext' class") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @author Kara Rawson / [email protected] | ||
*/ | ||
|
||
import { WebGLAnimationFrame } from './webgl/WebGLAnimation' | ||
|
||
/** | ||
* simple placeholder class until we get support with AS web glue which is meant | ||
* to provide access to the underlying context canvas element that exposes the | ||
* GL layer of the browser. | ||
*/ | ||
export class WebGLRenderingContext { | ||
context: i8 = 1 // version placeholder | ||
|
||
//// TODO needs ASGLue module to access native context canvas of GL in the browser | ||
|
||
// functions or properties required for testing | ||
|
||
requestAnimationFrame(animationLoop: WebGLAnimationFrame): void { | ||
// animationLoop.onAnimationFrame(0,0,animationLoop) | ||
} | ||
} | ||
|
||
/* lib.dom.d.ts -- interface reference from the domlib | ||
interface WebGL2RenderingContext extends WebGL2RenderingContextBase, WebGL2RenderingContextOverloads, WebGLRenderingContextBase { | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import './webgl/index.spec' | ||
import './WebGLRenderingContext.spec' | ||
import './WebGL2RenderingContext.spec' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @author Kara Rawson / [email protected] | ||
*/ | ||
|
||
import { WebGLAnimation } from './WebGLAnimation' | ||
import { WebGLRenderingContext } from "../WebGLRenderingContext"; | ||
import { WebGL2RenderingContext } from "../WebGL2RenderingContext"; | ||
|
||
/** | ||
* @todo make sure we test the WebGLAnimationFrame | ||
*/ | ||
|
||
describe('Renderers', () => { | ||
describe('WebGL', () => { | ||
describe('WebGLAnimation', () => { | ||
todo('start') | ||
todo('stop') | ||
todo('setAnimationLoop') | ||
todo('WebGlAnimationFrame_callback') | ||
test('setContext', (): void => { | ||
var animation = new WebGLAnimation() | ||
var gl: WebGLRenderingContext = new WebGLRenderingContext() | ||
var gl2: WebGL2RenderingContext = new WebGL2RenderingContext() | ||
|
||
animation.setContext(gl, null) | ||
|
||
expect(animation.context).not.toBeNull("WebGLRenderingContext should not be null") | ||
expect(animation.context2).toBeNull("WebGL2RenderingContext should be null") | ||
expect(animation.context).toStrictEqual(gl, "WebGLRenderingContext should be type gl") | ||
|
||
animation.setContext(null, gl2) | ||
|
||
expect(animation.context).toBeNull("WebGLRenderingContext should be null") | ||
expect(animation.context2).not.toBeNull("WebGL2RenderingContext should not be null") | ||
expect(animation.context2).toStrictEqual(gl2, "WebGLRenderingContext should be type gl2") | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* @author mrdoob / http://mrdoob.com/ | ||
* @author Kara Rawson / [email protected] | ||
*/ | ||
|
||
import { WebGLRenderingContext } from "../WebGLRenderingContext"; | ||
import { WebGL2RenderingContext } from "../WebGL2RenderingContext"; | ||
|
||
/** | ||
* our requestion animation frames root callback function. Recusrively calls itself | ||
* unless isAnimating flag is set to false | ||
* | ||
* @todo this could be optimized to not have an if check.. make two types of animators for gl and gl2 | ||
*/ | ||
export class WebGLAnimationFrame { | ||
|
||
/** | ||
* recursive callback function which is called by the WebGLRenderingContext for gl or gl2 | ||
* @param time the current time as an unsigned integer. This could overflow.. really big number | ||
* @param frame the amount of times the gl_scene has rendered within our context | ||
* @param animator the webgl animation class that handles the recursive callback | ||
*/ | ||
onAnimationFrame(time: u64, frame: u64, animator: WebGLAnimation): void { | ||
if (!animator.isAnimating) return; | ||
|
||
this.onAnimationFrame(time, frame, animator); | ||
|
||
if (animator.context) { | ||
animator.context.requestAnimationFrame(animator.animationLoop); | ||
return | ||
} | ||
if (animator.context2) { | ||
animator.context2.requestAnimationFrame(animator.animationLoop); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* a general purpose classes without a constructor for animating geometry within | ||
* GLAS. This class requires explicitly setting either the 'WebGLRenderingContext' or | ||
* 'WebGL2RenderingContext' depending on the version of GL and GLSL you with to use. | ||
* | ||
* NOTE: This is a terribly overloaded term. Animation in this case actually refers to | ||
* the callback function which is passed by reference into the requestAnimationFrame. | ||
* This is a bit confusing with a mesh's animation sequence which is completely different | ||
* uses the same wording. | ||
*/ | ||
export class WebGLAnimation { | ||
|
||
context: WebGLRenderingContext | null = null | ||
context2: WebGL2RenderingContext | null = null | ||
|
||
isAnimating: bool = false | ||
animationLoop: WebGLAnimationFrame = new WebGLAnimationFrame() | ||
|
||
/** | ||
* starts our animation loop in gl land | ||
*/ | ||
start(): void { | ||
|
||
if (this.isAnimating) return | ||
if (this.setAnimationLoop === null) return | ||
|
||
if (this.context) { | ||
this.context.requestAnimationFrame(this.animationLoop) | ||
} | ||
else if (!this.context && this.context2) { | ||
this.context2.requestAnimationFrame(this.animationLoop) | ||
} | ||
|
||
this.isAnimating = true | ||
} | ||
|
||
/** | ||
* stops our animation loop in gl land | ||
*/ | ||
stop(): void { | ||
this.isAnimating = false | ||
} | ||
|
||
/** | ||
* a recursive call back function that is used to call itself to loop the update of the | ||
* GLAS webgl scene and gl_objects | ||
* @param callback sets our animation frame that is looped. aka animation loop | ||
*/ | ||
setAnimationLoop(callback: WebGLAnimationFrame): void { | ||
this.animationLoop = callback | ||
} | ||
|
||
/** | ||
* sets our local redering context which is used by our animator that calls rendering animation | ||
* frame recursively | ||
* @param gl version 1 of webgl used by most browsers | ||
* @param gl2 version 2 of webgl which supports additional texture features and custom XR and VR devices | ||
*/ | ||
setContext(gl: WebGLRenderingContext | null, gl2: WebGL2RenderingContext | null): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discriminated union. :) |
||
if (gl) { | ||
this.context = gl | ||
this.context2 = null | ||
return | ||
|
||
} | ||
else if (gl2) { | ||
this.context = null | ||
this.context2 = gl2 | ||
return | ||
} | ||
|
||
/// TODO exception handling not yet supported | ||
//else { | ||
// throw new Exception("webgl or webgl2 must be provided to 'setContext()'") | ||
//} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASWebGLue
in fact now providesWebGLRenderingContext
(we could addWebGLRenderingContext
at some point, but for now I just want to get things running).For
requestAnimationFrame
, see https://github.com/trusktr/ecmassembly.