* parses the TMX shape definition and returns a corresponding array of shape objects * @private * @returns {Polygon[]|Line[]|Ellipse[]|RoundRect[]} an array of shape objects
()
| 226 | * @returns {Polygon[]|Line[]|Ellipse[]|RoundRect[]} an array of shape objects |
| 227 | */ |
| 228 | parseTMXShapes() { |
| 229 | const shapes = []; |
| 230 | |
| 231 | switch (this.shapeType) { |
| 232 | case "ellipse": |
| 233 | shapes.push( |
| 234 | ellipsePool |
| 235 | .get(this.width / 2, this.height / 2, this.width, this.height) |
| 236 | .rotate(this.rotation), |
| 237 | ); |
| 238 | break; |
| 239 | |
| 240 | case "capsule": { |
| 241 | const radius = Math.min(this.width, this.height) / 2; |
| 242 | shapes.push( |
| 243 | roundedRectanglePool |
| 244 | .get(0, 0, this.width, this.height, radius) |
| 245 | .rotate(this.rotation), |
| 246 | ); |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | case "point": |
| 251 | shapes.push(pointPool.get(this.x, this.y)); |
| 252 | break; |
| 253 | |
| 254 | case "polygon": { |
| 255 | const polygon = polygonPool.get(0, 0, this.points); |
| 256 | const isConvex = polygon.isConvex(); |
| 257 | |
| 258 | if (isConvex === true) { |
| 259 | shapes.push(polygon.rotate(this.rotation)); |
| 260 | } else if (isConvex === false) { |
| 261 | // decompose concave polygon into convex triangles |
| 262 | console.warn( |
| 263 | "melonJS: concave collision polygon detected, decomposing into convex triangles", |
| 264 | ); |
| 265 | const indices = polygon.getIndices(); |
| 266 | const pts = polygon.points; |
| 267 | for (let t = 0; t < indices.length; t += 3) { |
| 268 | shapes.push( |
| 269 | polygonPool |
| 270 | .get(0, 0, [ |
| 271 | vector2dPool.get(pts[indices[t]].x, pts[indices[t]].y), |
| 272 | vector2dPool.get( |
| 273 | pts[indices[t + 1]].x, |
| 274 | pts[indices[t + 1]].y, |
| 275 | ), |
| 276 | vector2dPool.get( |
| 277 | pts[indices[t + 2]].x, |
| 278 | pts[indices[t + 2]].y, |
| 279 | ), |
| 280 | ]) |
| 281 | .rotate(this.rotation), |
| 282 | ); |
| 283 | } |
| 284 | polygonPool.release(polygon); |
| 285 | } else { |
no test coverage detected