|  | 
| 132 | 132 | 
 | 
| 133 | 133 |     if (obj instanceof p2.Body && obj.shapes.length) { | 
| 134 | 134 |       if (obj.concavePath && !this.options.debugPolygons) { | 
| 135 |  | -        var texture = this.drawConvex(obj.concavePath); | 
|  | 135 | +        var texture = this.drawConvex(obj.concavePath, obj.render); | 
| 136 | 136 |         Stage.image(texture).appendTo(obj.ui).pin({ | 
| 137 | 137 |           handle : 0.5, | 
| 138 | 138 |           offsetX : obj.shapeOffsets[i] ? obj.shapeOffsets[i][0] : 0, | 
|  | 
| 143 | 143 |       } else { | 
| 144 | 144 |         for (var i = 0; i < obj.shapes.length; i++) { | 
| 145 | 145 |           var shape = obj.shapes[i]; | 
|  | 146 | +          var options = shape.render || obj.render; | 
| 146 | 147 | 
 | 
| 147 | 148 |           var texture = null; | 
| 148 | 149 |           if (shape instanceof p2.Circle) { | 
| 149 |  | -            texture = this.drawCircle(shape.radius); | 
|  | 150 | +            texture = this.drawCircle(shape.radius, options); | 
| 150 | 151 | 
 | 
| 151 | 152 |           } else if (shape instanceof p2.Particle) { | 
| 152 |  | -            texture = this.drawCircle(2 * this.options.get('lineWidth'), { | 
| 153 |  | -              lineColor : "", | 
| 154 |  | -              fillColor : this.options.lineColor | 
| 155 |  | -            }); | 
|  | 153 | +            texture = this.drawParticle(options); | 
| 156 | 154 | 
 | 
| 157 | 155 |           } else if (shape instanceof p2.Plane) { | 
| 158 |  | -            texture = this.drawPlane(-10, 10, 10); | 
|  | 156 | +            texture = this.drawPlane(-10, 10, 10, options); | 
| 159 | 157 | 
 | 
| 160 | 158 |           } else if (shape instanceof p2.Line) { | 
| 161 |  | -            texture = this.drawLine(shape.length); | 
|  | 159 | +            texture = this.drawLine(shape.length, options); | 
| 162 | 160 | 
 | 
| 163 | 161 |           } else if (shape instanceof p2.Rectangle) { | 
| 164 |  | -            texture = this.drawRectangle(shape.width, shape.height); | 
|  | 162 | +            texture = this.drawRectangle(shape.width, shape.height, options); | 
| 165 | 163 | 
 | 
| 166 | 164 |           } else if (shape instanceof p2.Capsule) { | 
| 167 |  | -            texture = this.drawCapsule(shape.length, shape.radius); | 
|  | 165 | +            texture = this.drawCapsule(shape.length, shape.radius, options); | 
| 168 | 166 | 
 | 
| 169 | 167 |           } else if (shape instanceof p2.Convex) { | 
| 170 | 168 |             if (shape.vertices.length) { | 
| 171 |  | -              texture = this.drawConvex(shape.vertices); | 
|  | 169 | +              texture = this.drawConvex(shape.vertices, options); | 
| 172 | 170 |             } | 
| 173 | 171 |           } | 
| 174 | 172 |           Stage.image(texture).appendTo(obj.ui).pin({ | 
|  | 
| 181 | 179 |       } | 
| 182 | 180 | 
 | 
| 183 | 181 |     } else if (obj instanceof p2.Spring) { | 
| 184 |  | -      var texture = this.drawSpring(obj.restLength); | 
|  | 182 | +      var texture = this.drawSpring(obj.restLength, obj.render); | 
| 185 | 183 |       Stage.image(texture).appendTo(obj.ui).pin({ | 
| 186 | 184 |         handle : 0.5 | 
| 187 | 185 |       }); | 
|  | 
| 195 | 193 | 
 | 
| 196 | 194 |   Viewer.prototype.drawLine = function(length, options) { | 
| 197 | 195 |     options = this.options.extend(options); | 
| 198 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 199 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 196 | +    var lineWidth = options.get('lineWidth'); | 
|  | 197 | +    var lineColor = options.get('lineColor'); | 
|  | 198 | +    var fillColor = options.get('fillColor'); | 
| 200 | 199 | 
 | 
| 201 | 200 |     lineWidth *= 2; | 
| 202 | 201 |     var ratio = options.ratio; | 
|  | 
| 218 | 217 | 
 | 
| 219 | 218 |   Viewer.prototype.drawRectangle = function(w, h, options) { | 
| 220 | 219 |     options = this.options.extend(options); | 
| 221 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 222 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 220 | +    var lineWidth = options.get('lineWidth'); | 
|  | 221 | +    var lineColor = options.get('lineColor'); | 
|  | 222 | +    var fillColor = options.get('fillColor'); | 
| 223 | 223 | 
 | 
| 224 | 224 |     var width = w + 2 * lineWidth; | 
| 225 | 225 |     var height = h + 2 * lineWidth; | 
|  | 
| 243 | 243 | 
 | 
| 244 | 244 |   Viewer.prototype.drawCircle = function(radius, options) { | 
| 245 | 245 |     options = this.options.extend(options); | 
| 246 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 247 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 246 | +    var lineWidth = options.get('lineWidth'); | 
|  | 247 | +    var lineColor = options.get('lineColor'); | 
|  | 248 | +    var fillColor = options.get('fillColor'); | 
|  | 249 | + | 
|  | 250 | +    var width = radius * 2 + lineWidth * 2; | 
|  | 251 | +    var height = radius * 2 + lineWidth * 2; | 
|  | 252 | +    var ratio = options.ratio; | 
|  | 253 | + | 
|  | 254 | +    return Stage.canvas(function(ctx) { | 
|  | 255 | +      this.size(width, height, ratio); | 
|  | 256 | + | 
|  | 257 | +      ctx.scale(ratio, ratio); | 
|  | 258 | +      ctx.beginPath(); | 
|  | 259 | +      ctx.arc(width / 2, height / 2, radius, 0, 2 * Math.PI); | 
|  | 260 | +      if (fillColor) { | 
|  | 261 | +        ctx.fillStyle = fillColor; | 
|  | 262 | +        ctx.fill(); | 
|  | 263 | +      } | 
|  | 264 | + | 
|  | 265 | +      if (lineColor) { | 
|  | 266 | +        ctx.moveTo(radius + lineWidth, radius + lineWidth); | 
|  | 267 | +        ctx.lineTo(lineWidth, radius + lineWidth); | 
|  | 268 | + | 
|  | 269 | +        ctx.lineWidth = lineWidth; | 
|  | 270 | +        ctx.strokeStyle = lineColor; | 
|  | 271 | +        ctx.stroke(); | 
|  | 272 | +      } | 
|  | 273 | +    }); | 
|  | 274 | +  }; | 
|  | 275 | + | 
|  | 276 | +  Viewer.prototype.drawParticle = function(options) { | 
|  | 277 | +    options = this.options.extend(options); | 
|  | 278 | + | 
|  | 279 | +    var lineWidth = options.get('lineWidth'); | 
|  | 280 | +    var lineColor = ''; | 
|  | 281 | +    var fillColor = options.get('fillColor') || options.get('lineColor'); | 
|  | 282 | + | 
|  | 283 | +    var radius = 2 * options.get('lineWidth'); | 
| 248 | 284 | 
 | 
| 249 | 285 |     var width = radius * 2 + lineWidth * 2; | 
| 250 | 286 |     var height = radius * 2 + lineWidth * 2; | 
|  | 
| 274 | 310 | 
 | 
| 275 | 311 |   Viewer.prototype.drawCapsule = function(len, radius, options) { | 
| 276 | 312 |     options = this.options.extend(options); | 
| 277 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 278 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 313 | +    var lineWidth = options.get('lineWidth'); | 
|  | 314 | +    var lineColor = options.get('lineColor'); | 
|  | 315 | +    var fillColor = options.get('fillColor'); | 
| 279 | 316 | 
 | 
| 280 | 317 |     var width = len + 2 * radius + 2 * lineWidth; | 
| 281 | 318 |     var height = 2 * radius + 2 * lineWidth; | 
|  | 
| 306 | 343 | 
 | 
| 307 | 344 |   Viewer.prototype.drawSpring = function(length, options) { | 
| 308 | 345 |     options = this.options.extend(options); | 
| 309 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 310 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 346 | +    var lineWidth = options.get('lineWidth'); | 
|  | 347 | +    var lineColor = options.get('lineColor'); | 
|  | 348 | +    var fillColor = options.get('fillColor'); | 
| 311 | 349 | 
 | 
| 312 | 350 |     length = Math.max(length, lineWidth * 10); | 
| 313 | 351 | 
 | 
|  | 
| 346 | 384 | 
 | 
| 347 | 385 |   Viewer.prototype.drawPlane = function(x0, x1, max, options) { | 
| 348 | 386 |     options = this.options.extend(options); | 
| 349 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 350 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 387 | +    var lineWidth = options.get('lineWidth'); | 
|  | 388 | +    var lineColor = options.get('lineColor'); | 
|  | 389 | +    var fillColor = options.get('fillColor'); | 
| 351 | 390 | 
 | 
| 352 | 391 |     var ratio = options.ratio; | 
| 353 | 392 | 
 | 
|  | 
| 381 | 420 | 
 | 
| 382 | 421 |   Viewer.prototype.drawConvex = function(verts, options) { | 
| 383 | 422 |     options = this.options.extend(options); | 
| 384 |  | -    var lineWidth = options.get('lineWidth'), lineColor = options | 
| 385 |  | -        .get('lineColor'), fillColor = options.get('fillColor'); | 
|  | 423 | +    var lineWidth = options.get('lineWidth'); | 
|  | 424 | +    var lineColor = options.get('lineColor'); | 
|  | 425 | +    var fillColor = options.get('fillColor'); | 
| 386 | 426 | 
 | 
| 387 | 427 |     if (!verts.length) { | 
| 388 | 428 |       return; | 
|  | 
0 commit comments