| 1 |
define(["dojo/_base/lang","./matrix","./vector"], |
| 2 |
function(lang,m,v){ |
| 3 |
|
| 4 |
var gfx3d = lang.getObject("dojox.gfx3d",true); |
| 5 |
|
| 6 |
var dist = function(a, b){ return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2)); }; |
| 7 |
var N = 32; |
| 8 |
|
| 9 |
gfx3d.gradient = function(model, material, center, radius, from, to, matrix){ |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
var mx = m.normalize(matrix), |
| 30 |
f = m.multiplyPoint(mx, radius * Math.cos(from) + center.x, radius * Math.sin(from) + center.y, center.z), |
| 31 |
t = m.multiplyPoint(mx, radius * Math.cos(to) + center.x, radius * Math.sin(to) + center.y, center.z), |
| 32 |
c = m.multiplyPoint(mx, center.x, center.y, center.z), step = (to - from) / N, r = dist(f, t) / 2, |
| 33 |
mod = model[material.type], fin = material.finish, pmt = material.color, |
| 34 |
colors = [{offset: 0, color: mod.call(model, v.substract(f, c), fin, pmt)}]; |
| 35 |
|
| 36 |
for(var a = from + step; a < to; a += step){ |
| 37 |
var p = m.multiplyPoint(mx, radius * Math.cos(a) + center.x, radius * Math.sin(a) + center.y, center.z), |
| 38 |
df = dist(f, p), dt = dist(t, p); |
| 39 |
colors.push({offset: df / (df + dt), color: mod.call(model, v.substract(p, c), fin, pmt)}); |
| 40 |
} |
| 41 |
colors.push({offset: 1, color: mod.call(model, v.substract(t, c), fin, pmt)}); |
| 42 |
|
| 43 |
return {type: "linear", x1: 0, y1: -r, x2: 0, y2: r, colors: colors}; |
| 44 |
}; |
| 45 |
|
| 46 |
return gfx3d.gradient; |
| 47 |
}); |