-
Notifications
You must be signed in to change notification settings - Fork 527
Update demo to use flat API #1382
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
base: V3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<html lang="en"> | ||
<head> | ||
<title>Demo Application</title> | ||
<title>Demo Application CommonJS</title> | ||
<style> | ||
#jscad{ | ||
width: 15cm; | ||
|
@@ -12,56 +12,13 @@ | |
</style> | ||
</head> | ||
<body> | ||
<script language="javascript" src="./dist/jscad-regl-renderer.min.js" id="RENDERING"></script> | ||
|
||
<span>How to use regl-renderer as CommonJS module</span> | ||
<div id="jscad"></div> | ||
|
||
<script type="module" id="MODELING"> | ||
// ******************** | ||
// The design to render. | ||
// ******************** | ||
import { booleans, colors, primitives } from "./jscad-modeling.es.js" | ||
|
||
const { intersect, subtract } = booleans | ||
const { colorize } = colors | ||
const { cube, cuboid, line, sphere, star } = primitives | ||
|
||
const main = (parameters) => { | ||
parameters = {scale: 1} | ||
const logo = [ | ||
colorize([1.0, 0.4, 1.0], subtract( | ||
cube({ size: 300 }), | ||
sphere({ radius: 200 }) | ||
)), | ||
colorize([1.0, 1.0, 0], intersect( | ||
sphere({ radius: 130 }), | ||
cube({ size: 210 }) | ||
)) | ||
] | ||
|
||
const transpCube = colorize([1, 0, 0, 0.25], cuboid({ size: [100 * parameters.scale, 100, 210 + (200 * parameters.scale)] })) | ||
const star2D = star({ vertices: 8, innerRadius: 300, outerRadius: 400 }) | ||
const line2D = colorize([1.0, 0, 0], line([[260, 260], [-260, 260], [-260, -260], [260, -260], [260, 260]])) | ||
// some colors are intentionally without alpfa channel to test geom2ToGeometries will add alpha channel | ||
const colorChange = [ | ||
[1, 0, 0, 1], | ||
[1, 0.5, 0], | ||
[1, 0, 1], | ||
[0, 1, 0], | ||
[0, 0, 0.7] | ||
] | ||
star2D.outlines.forEach((outline, i) => { | ||
outline.color = colorChange[i % colorChange.length] | ||
}) | ||
|
||
return [star2D, line2D, ...logo] | ||
} | ||
// HACK... export the results of the design to global space | ||
window.shapes = main() | ||
</script> | ||
<script type="module" id="MODELING" src="model.js"></script> | ||
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. I'd prefer NOT to mix Common JS (require) and ES (import) in the same example. Let's keep these separated. 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. Code in the file <script language="javascript" src="./dist/jscad-regl-renderer.min.js" id="RENDERING"></script>
<div id="jscad"></div>
<script type="module" id="MODELING">
// ********************
// The design to render.
// ********************
import { booleans, colors, primitives } from "./jscad-modeling.es.js"
.... in the origin, which is dedicated for CommonJS. |
||
|
||
|
||
<script type="module", id="RENDERING"> | ||
<script src="./dist/jscad-regl-renderer.min.js"></script> | ||
<script type="module" id="RENDERING"> | ||
// ******************** | ||
// Renderer configuration and initiation. | ||
// ******************** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// ******************** | ||
// The design to render. | ||
// This file is used in both demo.es.html and demo.html to show that | ||
// nothing has to be changed by modeling when once changes used API from common global | ||
// (demo.html) to ES6 Module (demo.es.html) | ||
// ******************** | ||
import { | ||
intersect, subtract, | ||
cube, cuboid, line, sphere, star, | ||
colorize | ||
} from './jscad-modeling.es.js'; | ||
|
||
|
||
export const main = (parameters) => { | ||
parameters = {scale: 1} | ||
const logo = [ | ||
colorize([1.0, 0.4, 1.0], subtract( | ||
cube({ size: 300 }), | ||
sphere({ radius: 200 }) | ||
)), | ||
colorize([1.0, 1.0, 0], intersect( | ||
sphere({ radius: 130 }), | ||
cube({ size: 210 }) | ||
)) | ||
] | ||
|
||
const transpCube = colorize([1, 0, 0, 0.25], cuboid({ size: [100 * parameters.scale, 100, 210 + (200 * parameters.scale)] })) | ||
const star2D = star({ vertices: 8, innerRadius: 300, outerRadius: 400 }) | ||
const line2D = colorize([1.0, 0, 0], line([[260, 260], [-260, 260], [-260, -260], [260, -260], [260, 260]])) | ||
// some colors are intentionally without alpfa channel to test geom2ToGeometries will add alpha channel | ||
const colorChange = [ | ||
[1, 0, 0, 1], | ||
[1, 0.5, 0], | ||
[1, 0, 1], | ||
[0, 1, 0], | ||
[0, 0, 0.7] | ||
] | ||
star2D.outlines.forEach((outline, i) => { | ||
outline.color = colorChange[i % colorChange.length] | ||
}) | ||
|
||
return [star2D, line2D, transpCube, ...logo] | ||
} | ||
// HACK... export the results of the design to global space | ||
window.shapes = main() |
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.
All the DOC changes are good but probably better in a separate set of changes, and pull request. I'll chat about the doc changes in the discussion.
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.
Okay, let chat about it!