Skip to content

Commit 7ca54f9

Browse files
committed
Add 3d Tests
1 parent 98cc61d commit 7ca54f9

2 files changed

Lines changed: 153 additions & 5 deletions

File tree

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/**
2+
* Copyright ysle ( http://wonderfl.net/user/ysle )
3+
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
4+
* Downloaded from: http://wonderfl.net/c/qGQZ
5+
* Downloaded from: https://github.com/biliscript-syndicate/examples/blob/master/Sphere.as
6+
*
7+
* --Modified slightly to remove unnecessary code & hardcode screen size/lifeTime
8+
* --Modified so that GlowFilter is added too.
9+
*/
10+
11+
/**
12+
* Works well with filters off at 200,40,9
13+
* or with filters on at 200, 20, 5
14+
**/
15+
/*** CONFIG ****/
16+
17+
var fill = true;
18+
var wireframe = true;
19+
var filters = false;
20+
var radius = 200;
21+
var detail = 40;
22+
var stripes = 9;
23+
24+
/*** /CONFIG ***/
25+
26+
var unload = $G._get('unload');
27+
if (unload) unload();
28+
Vector3D = ($.createVector3D()).constructor;
29+
30+
var screen = $.createShape({
31+
lifeTime: 1000
32+
});
33+
screen.transform.matrix3D = null;
34+
screen.x = 640 / 2;
35+
screen.y = 400 / 2;
36+
37+
function getR(a, c) {
38+
return Math.sqrt(c * c - a * a);
39+
}
40+
var rules = [
41+
{r:0xff, g:0, b:0, dr:0, dg:1, db:0 },
42+
{r:0xff, g:0xff, b:0, dr: -1, dg:0, db:0 },
43+
{r:0, g:0xff, b:0, dr:0, dg:0, db: +1 },
44+
{r:0, g:0xff, b:0xff, dr:0, dg: -1, db:0 },
45+
{r:0, g:0, b:0xff, dr: +1, dg:0, db:0 },
46+
{r:0xff, g:0, b:0xff, dr:0, dg:0, db: -1 }
47+
];
48+
function getColor(value) {
49+
var d = (value = value % 0x5fa) % 0xff;
50+
var r = rules[(value / 0xff) | 0];
51+
return ((r.r+r.dr*d)<<16)+((r.g+r.dg*d)<<8)+(r.b+r.db*d);
52+
}
53+
54+
var vertices = $.toNumberVector([]);
55+
var indices = $.toIntVector([]);
56+
var uvtData = $.toNumberVector([]);
57+
var projectedVertices = $.toNumberVector([]);
58+
function init() {
59+
var frh = radius * 2 / (stripes * 2 +1);
60+
var yc = -radius;
61+
var rad, last, yUp, yDown, rUp, rDown, i;
62+
63+
for (var s = 0; s < stripes; s++) {
64+
yUp = yc += frh ;
65+
yDown = yc += frh;
66+
rUp = getR(yUp, radius);
67+
rDown = getR(yDown, radius);
68+
i = detail*2*s;
69+
70+
for (var c = 0; c < detail; c++) {
71+
rad = (2 * Math.PI) / detail * c;
72+
vertices.push(Math.cos(rad) * rUp, Math.sin(rad) * rUp, yUp );
73+
vertices.push(Math.cos(rad) * rDown, Math.sin(rad) * rDown, yDown );
74+
75+
last = c == (detail - 1);
76+
indices.push(i + c * 2, i + c * 2 + 1, i + (last?0:c * 2 + 2));
77+
indices.push(i + c * 2 + 1, i + (last?1:c * 2 + 3), i + (last?0:c * 2 + 2));
78+
}
79+
}
80+
81+
uvtData.length = indices.length;
82+
projectedVertices.length = vertices.length / 3 * 2;
83+
projectedVertices.fixed = true;
84+
vertices.fixed = true;
85+
indices.fixed = true;
86+
uvtData.fixed = true;
87+
}
88+
89+
var counter = 0;
90+
var rx = 0;
91+
var ry = 0;
92+
var frames = 0;
93+
var fpsText = $.createComment('', {fontsize:12, lifeTime:1000});
94+
var frameCount = 0;
95+
var nextUpdate = getTimer() + 1000;
96+
var lastTime = getTimer();
97+
var matrix3D = $.createMatrix3D([]);
98+
if(filters)
99+
screen.filters = [$.createGlowFilter(0xff0000,1,40,40,20)];
100+
var mrgb = 0xff0000;
101+
102+
103+
function render() {
104+
var now = getTimer();
105+
frameCount++;
106+
if (now >= nextUpdate) {
107+
fps = ((frameCount / (now - lastTime) * 1000 * 10) | 0) / 10;
108+
fpsText.text = 'FPS:' + fps;
109+
lastTime = now;
110+
frameCount = 0;
111+
nextUpdate = getTimer() + 1000;
112+
}
113+
matrix3D.identity();
114+
matrix3D.prependRotation(rx+=0.5, Vector3D.X_AXIS);
115+
matrix3D.prependRotation(ry+=1.25, Vector3D.Y_AXIS);
116+
$.projectVectors(matrix3D, vertices, projectedVertices, uvtData);
117+
screen.graphics.clear();
118+
var color = getColor(counter++);
119+
if(frameCount === 0 && filters){
120+
var r = Math.floor(color / 65536), g = Math.floor((color % 65536) / 256), b = color % 256;
121+
nmrgb = Utils.rgb(255 * (r > 128 ? 1 : 0), 255 * (g > 128 ? 1 : 0), 255 * (b > 128 ? 1 : 0));
122+
if(nmrgb !== mrgb){
123+
mrgb = nmrgb;
124+
screen.filters = [$.createGlowFilter(mrgb,1,40,40,20)];
125+
}
126+
}
127+
128+
if (wireframe)
129+
screen.graphics.lineStyle(0.4, fill?0xffffff:color,1);
130+
if (fill)
131+
screen.graphics.beginFill(0xffffff);
132+
screen.graphics.drawTriangles(projectedVertices, indices, null, 'negative');
133+
if(fill)
134+
screen.graphics.beginFill(color);
135+
screen.graphics.drawTriangles(projectedVertices, indices, null, 'positive');
136+
screen.graphics.endFill();
137+
}
138+
139+
init();
140+
screen.addEventListener('enterFrame', render);
141+
$G._set('unload', function(){
142+
screen.removeEventListener('enterFrame', render);
143+
ScriptManager.clearEl();
144+
$G._set('unload', undefined);
145+
});

experimental/scripting/index.htm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<meta http-equiv="X-UA-Compatible" value="IE=9">
66
<title>CCL-Compat BScript Test</title>
77
<style>
8-
#codediv{width:48%; float:left;}
9-
#playerdiv{width:48%; float:right;}
8+
#codediv{width:48%; position:absolute; left:10px;}
9+
#playerdiv{width:48%; float:right; position:absolute; right:10px;}
1010
#output{font-family:Consolas, 'Courier New', monospace; font-size:12px;padding:10px; background:#000;
1111
position:fixed; bottom:0; left:0; right:0; height:150px; overflow:auto; color:#ccc;border-top:1px dotted #fff;}
1212
#player{border:1px solid #f88; width:100%;background-color:#100;position:relative;}
1313
#code-input{width:100%;height:340px;display:block; border:1px solid #f88; padding:10px;background:#000;color:#f88;font-size:20px;}
14-
.s-button, .button{display:block; border:1px solid #f88; padding:10px; background:#000; color:#f88; float:left;-moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; -o-user-select: none; user-select: none; cursor:default;}
14+
.s-button, .button{display:block; border:1px solid #f88; padding:8px 6px 8px 6px; background:#000; color:#f88; float:left;-moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; -o-user-select: none; user-select: none; cursor:default;}
1515
.s-button:hover,.button:hover{background:#f88; color:#000;}
1616
.button{font-size:12px;z-index:99;}
1717
pre{margin:0;}
@@ -24,8 +24,8 @@
2424
<body style="background:#000;">
2525
<h2 style="color:#fff">CCL Scripting Demo</h2>
2626
<div id="codediv">
27-
<div style="clear:both;">
28-
<button class="s-button" id="evaluate">Execute (Sandbox)</button><button class="s-button" id="debug-basic">Debug Basic</button><button class="s-button" id="debug-svg">Debug SVGDraw GreenDam</button><button class="s-button" id="debug-svg-madoka">Debug Madoka</button><button class="s-button" id="debug-clear">Clear.Runtime</button>
27+
<div style="clear:both;overflow:auto;width:110%;">
28+
<button class="s-button" id="evaluate">Execute (Sandbox)</button><button class="s-button" id="debug-basic">Debug Basic</button><button class="s-button" id="debug-svg">Debug SVGDraw GreenDam</button><button class="s-button" id="debug-svg-madoka">Debug Madoka</button><button class="s-button" id="debug-3dsphere">Debug 3D</button><button class="s-button" id="debug-clear">Clear.Runtime</button>
2929
</div>
3030
<textarea id="code-input"></textarea>
3131
</div>
@@ -73,6 +73,9 @@ <h2 style="color:#fff">CCL Scripting Demo</h2>
7373
$("debug-svg").addEventListener("click", function(){
7474
fetchFile("greendam.biliscript");
7575
});
76+
$("debug-3dsphere").addEventListener("click", function(){
77+
fetchFile("3dsphere.biliscript");
78+
});
7679
$("debug-clear").addEventListener("click", function(){
7780
//bscripter.clear();
7881
});

0 commit comments

Comments
 (0)