|
@@ -1,10 +1,7 @@
|
|
|
var SVGRenderer = Renderer.extend
|
|
|
({
|
|
|
- defs: null,
|
|
|
-
|
|
|
- svgImagePool: null,
|
|
|
- svgPatternPool: null,
|
|
|
svgPathPool: null,
|
|
|
+ svgCirclePool: null,
|
|
|
|
|
|
init: function()
|
|
|
{
|
|
@@ -14,23 +11,7 @@ var SVGRenderer = Renderer.extend
|
|
|
this.viewport.style.position = "absolute";
|
|
|
|
|
|
this.svgPathPool = new Array();
|
|
|
- this.svgImagePool = new Array();
|
|
|
-
|
|
|
- this.defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
|
|
|
-
|
|
|
- var texture = document.createElementNS('http://www.w3.org/2000/svg', 'pattern');
|
|
|
- texture.setAttribute('id', 'texture');
|
|
|
- texture.setAttribute('patternUnits', 'userSpaceOnUse');
|
|
|
- texture.setAttribute('width', 552);
|
|
|
- texture.setAttribute('height', 552);
|
|
|
-
|
|
|
- var bitmap = document.createElementNS('http://www.w3.org/2000/svg', 'image');
|
|
|
- bitmap.setAttribute('width', 552);
|
|
|
- bitmap.setAttribute('height', 552);
|
|
|
- bitmap.setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'assets/uvmap.jpg');
|
|
|
- texture.appendChild(bitmap);
|
|
|
-
|
|
|
- this.svgImagePool.push(texture);
|
|
|
+ this.svgCirclePool = new Array();
|
|
|
},
|
|
|
|
|
|
setSize: function( width, height )
|
|
@@ -49,33 +30,65 @@ var SVGRenderer = Renderer.extend
|
|
|
this.viewport.removeChild(this.viewport.childNodes[0]);
|
|
|
}
|
|
|
|
|
|
- this.viewport.appendChild(this.defs);
|
|
|
- this.defs.appendChild(this.svgImagePool[0]);
|
|
|
+ var pathCount = 0, circleCount = 0, svgNode;
|
|
|
|
|
|
for (j = 0; j < this.renderList.length; j++)
|
|
|
{
|
|
|
element = this.renderList[j];
|
|
|
|
|
|
- if (this.svgPathPool[j] == null)
|
|
|
+ if (element instanceof Face3)
|
|
|
{
|
|
|
- this.svgPathPool[j] = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
|
- this.svgPathPool[j].setAttribute('shape-rendering', 'crispEdges'); //optimizeSpeed
|
|
|
+ svgNode = this.getPathNode(pathCount++);
|
|
|
+ svgNode.setAttribute('d', 'M ' + element.a.screen.x + ' ' + element.a.screen.y + ' L ' + element.b.screen.x + ' ' + element.b.screen.y + ' L ' + element.c.screen.x + ',' + element.c.screen.y + 'z');
|
|
|
+ }
|
|
|
+ else if (element instanceof Face4)
|
|
|
+ {
|
|
|
+ svgNode = this.getPathNode(pathCount++);
|
|
|
+ svgNode.setAttribute('d', 'M ' + element.a.screen.x + ' ' + element.a.screen.y + ' L ' + element.b.screen.x + ' ' + element.b.screen.y + ' L ' + element.c.screen.x + ',' + element.c.screen.y + ' L ' + element.d.screen.x + ',' + element.d.screen.y + 'z');
|
|
|
+ }
|
|
|
+ else if (element instanceof Particle)
|
|
|
+ {
|
|
|
+ svgNode = this.getCircleNode(circleCount++);
|
|
|
+ svgNode.setAttribute('cx', element.screen.x);
|
|
|
+ svgNode.setAttribute('cy', element.screen.y);
|
|
|
+ svgNode.setAttribute('r', element.size * element.screen.z);
|
|
|
}
|
|
|
|
|
|
- // this.svgPathPool[j].setAttribute('style', 'fill:url(#texture)');
|
|
|
-
|
|
|
- this.svgPathPool[j].setAttribute('style', 'fill: rgb(' + element.color[0] + ', ' + element.color[1] + ', ' + element.color[2] + ')'); //fill-opacity:' + 0.5); // + ';stroke:' + element.color + ';stroke-width:10;stroke-opacity:0.5;'); //stroke-miterlimit:40;stroke-dasharray:5');
|
|
|
-
|
|
|
- if (element instanceof Face3)
|
|
|
+ if (element.material instanceof ColorMaterial)
|
|
|
{
|
|
|
- this.svgPathPool[j].setAttribute('d', 'M ' + element.a.screen.x + ' ' + element.a.screen.y + ' L ' + element.b.screen.x + ' ' + element.b.screen.y + ' L ' + element.c.screen.x + ',' + element.c.screen.y + 'z');
|
|
|
+ svgNode.setAttribute('style', 'fill: rgb(' + element.material.color.r + ',' + element.material.color.g + ',' + element.material.color.b + ')');
|
|
|
}
|
|
|
- else if (element instanceof Face4)
|
|
|
+ else if (element.material instanceof FaceColorMaterial)
|
|
|
{
|
|
|
- this.svgPathPool[j].setAttribute('d', 'M ' + element.a.screen.x + ' ' + element.a.screen.y + ' L ' + element.b.screen.x + ' ' + element.b.screen.y + ' L ' + element.c.screen.x + ',' + element.c.screen.y + ' L ' + element.d.screen.x + ',' + element.d.screen.y + 'z');
|
|
|
+ svgNode.setAttribute('style', 'fill: rgb(' + element.color.r + ',' + element.color.g + ',' + element.color.b + ')');
|
|
|
}
|
|
|
|
|
|
- this.viewport.appendChild(this.svgPathPool[j]);
|
|
|
+ this.viewport.appendChild(svgNode);
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ getPathNode: function( id )
|
|
|
+ {
|
|
|
+ if (this.svgPathPool[id] == null)
|
|
|
+ {
|
|
|
+ this.svgPathPool[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
|
+ // this.svgPathPool[id].setAttribute('shape-rendering', 'crispEdges'); //optimizeSpeed
|
|
|
+ return this.svgPathPool[id];
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.svgPathPool[id];
|
|
|
+ },
|
|
|
+
|
|
|
+ getCircleNode: function( id )
|
|
|
+ {
|
|
|
+ if (this.svgCirclePool[id] == null)
|
|
|
+ {
|
|
|
+ this.svgCirclePool[id] = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
|
+ // this.svgCirclePool[id].setAttribute('shape-rendering', 'crispEdges'); //optimizeSpeed
|
|
|
+ this.svgCirclePool[id].setAttribute('fill', 'red');
|
|
|
+ return this.svgCirclePool[id];
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.svgCirclePool[id];
|
|
|
}
|
|
|
});
|