forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti-application.html
More file actions
124 lines (106 loc) · 3.5 KB
/
Copy pathmulti-application.html
File metadata and controls
124 lines (106 loc) · 3.5 KB
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
<!DOCTYPE html>
<html>
<head>
<title>PlayCanvas Multiple Applications</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="icon" type="image/png" href="../playcanvas-favicon.png" />
<script src="../../build/playcanvas.js"></script>
<style>
#canvas-1 {
position: absolute;
width: 45%;
left: 0px;
margin: 0 0;
}
#canvas-2 {
position: absolute;
width: 45%;
right: 0px;
margin: 0 0;
}
</style>
</head>
<body>
<!-- The canvas element -->
<canvas id="canvas-1"></canvas>
<canvas id="canvas-2"></canvas>
<!-- The script -->
<script>
var canvas = document.getElementById("canvas-1");
// Create the app and start the update loop
var app1 = new pc.Application(canvas);
app1.start();
app1.setCanvasResolution(pc.RESOLUTION_AUTO);
var entity, light, camera;
// Create an Entity with a box component
entity = new pc.Entity(app1);
entity.name = "Box 1";
entity.addComponent("model", {
type: "box"
});
app1.root.addChild(entity);
// Create an Entity with a camera component
var camera = new pc.Entity(app1);
camera.addComponent("camera", {
clearColor: new pc.Color(0.4, 0.45, 0.5)
});
camera.translate(0, 0, 4);
app1.root.addChild(camera);
// Create an Entity with a omni light component
var light = new pc.Entity(app1);
light.addComponent("light", {
type: "omni",
color: new pc.Color(1, 1, 1),
range: 100
});
light.translate(5, 0, 15);
app1.root.addChild(light);
app1.on("update", function (dt) {
var entity = app1.root.findByName("Box 1");
if (entity) {
entity.rotate(0, 10 * dt, 0);
}
});
var canvas = document.getElementById("canvas-2");
// Create the app and start the update loop
var app2 = new pc.Application(canvas);
app2.start();
app2.setCanvasResolution(pc.RESOLUTION_AUTO);
var entity, light, camera;
// Create an Entity with a box component
entity = new pc.Entity(app2);
entity.name = "Box 2";
entity.addComponent("model", {
type: "box"
});
app2.root.addChild(entity);
// Create an Entity with a camera component
var camera = new pc.Entity(app2);
camera.addComponent("camera", {
clearColor: new pc.Color(0.4, 0.45, 0.5)
});
camera.translate(0, 0, 4);
app2.root.addChild(camera);
// Create an Entity with a omni light component
var light = new pc.Entity(app2);
light.addComponent("light", {
type: "omni",
color: new pc.Color(1, 1, 1),
range: 100
});
light.translate(5, 0, 15);
app2.root.addChild(light);
app2.on("update", function (dt) {
// var entity = app2.root.findByName("Box 2");
if (entity) {
entity.rotate(0, 10 * dt, 0);
}
});
window.addEventListener("resize", function () {
app1.resizeCanvas(canvas.width, canvas.height);
app2.resizeCanvas(canvas.width, canvas.height);
});
</script>
</body>
</html>