forked from xeolabs/scenejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas_capture_customSize.html
125 lines (101 loc) · 3.92 KB
/
canvas_capture_customSize.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<title>SceneJS Example</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 {
background: white;
margin: 0;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
}
</style>
<script src="../api/latest/scenejs.min.js"></script>
<link href="css/styles.css" rel="stylesheet"/>
</head>
<body>
<div id="infoDark">
<a href="http://scenejs.org">SceneJS</a> - canvas capture at custom size every 100ms<br><br>
</div>
<!-- Canvas containing our scene -->
<canvas id="mySceneCanvas" width="600px" height="600px"></canvas>
<!-- Image element displaying the captured image -->
<img id="myCapturedImage" width="400px" height="400px"/>
<script>
// Demonstrates the 'canvas/capture' node, which is implemented by plugin in
// http://scenejs.org/api/latest/plugins/node/canvas/capture.js
//
// This example periodically makes the node capture the scene canvas
// and copy the captured image data to an image element.
//
// We've set up an external canvas for our scene, instead of relying on
// the scene to provide it's own default canvas, because we want to
// arrange the canvas and image beside each other in the page.
//
// Point SceneJS to the bundled plugins
SceneJS.setConfigs({
pluginPath:"../api/latest/plugins"
});
// Create scene containing our capture node
var scene = SceneJS.createScene({
// Link to our canvas element
canvasId:"mySceneCanvas",
nodes:[
// Mouse-orbited camera, implemented by plugin at
// http://scenejs.org/api/latest/plugins/node/cameras/orbit.js
{
type:"cameras/orbit",
yaw:30,
pitch:-30,
zoom:500,
zoomSensitivity:10.0,
spin: 0.1, // Slowly spin
nodes:[
// City, implemented by plugin at
// http://scenejs.org/api/latest/plugins/node/models/buildings/city.js
{
type:"models/buildings/city",
width:600
}
]
},
// The capture node, implemented by plugin at
// http://scenejs.org/api/latest/plugins/node/canvas/capture.js
{
type:"canvas/capture",
id:"myCanvasCapture",
width: 400,
height: 400
}
]
});
//--------------------------------------------------------
// Periodically capture the canvas to the image element
//--------------------------------------------------------
var imageElement = document.getElementById("myCapturedImage");
// Get the 'canvas/capture' node instance
scene.getNode("myCanvasCapture",
function (myCanvasCapture) {
// Subscribe to the image it captures
// and copy it to the image element
myCanvasCapture.on("image",
function (data) {
imageElement.src = data.src;
});
// Do a screen capture every two seconds
setInterval(function () {
myCanvasCapture.capture({
// These capture params can also be set on the node
// definition. They will override those when specified here
format:"jpeg", // Default - also supports "png" and "bmp"
width:600, // Defaults to current canvas width
height:600 // Defaults to current canvas height
});
}, 100);
});
</script>
</body>
</html>