Skip to content

Commit

Permalink
deprecated Composites.softBody and added to softBody and cloth examples
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 6, 2021
1 parent cd9c5d4 commit 818f354
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
43 changes: 38 additions & 5 deletions examples/cloth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ Example.cloth = function() {
var runner = Runner.create();
Runner.run(runner, engine);

// add bodies
var group = Body.nextGroup(true),
particleOptions = { friction: 0.00001, collisionFilter: { group: group }, render: { visible: false }},
constraintOptions = { stiffness: 0.06 },
cloth = Composites.softBody(200, 200, 20, 12, 5, 5, false, 8, particleOptions, constraintOptions);
// see cloth function defined later in this file
var cloth = Example.cloth.cloth(200, 200, 20, 12, 5, 5, false, 8);

for (var i = 0; i < 20; i++) {
cloth.bodies[i].isStatic = true;
Expand Down Expand Up @@ -87,6 +84,42 @@ Example.cloth = function() {
Example.cloth.title = 'Cloth';
Example.cloth.for = '>=0.14.2';

/**
* Creates a simple cloth like object.
* @method cloth
* @param {number} xx
* @param {number} yy
* @param {number} columns
* @param {number} rows
* @param {number} columnGap
* @param {number} rowGap
* @param {boolean} crossBrace
* @param {number} particleRadius
* @param {} particleOptions
* @param {} constraintOptions
* @return {composite} A new composite cloth
*/
Example.cloth.cloth = function(xx, yy, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) {
var Body = Matter.Body,
Bodies = Matter.Bodies,
Common = Matter.Common,
Composites = Matter.Composites;

var group = Body.nextGroup(true);
particleOptions = Common.extend({ inertia: Infinity, friction: 0.00001, collisionFilter: { group: group }, render: { visible: false }}, particleOptions);
constraintOptions = Common.extend({ stiffness: 0.06, render: { type: 'line', anchors: false } }, constraintOptions);

var cloth = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) {
return Bodies.circle(x, y, particleRadius, particleOptions);
});

Composites.mesh(cloth, columns, rows, crossBrace, constraintOptions);

cloth.label = 'Cloth Body';

return cloth;
};

if (typeof module !== 'undefined') {
module.exports = Example.cloth;
}
41 changes: 38 additions & 3 deletions examples/softBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ Example.softBody = function() {
};

World.add(world, [
Composites.softBody(250, 100, 5, 5, 0, 0, true, 18, particleOptions),
Composites.softBody(400, 300, 8, 3, 0, 0, true, 15, particleOptions),
Composites.softBody(250, 400, 4, 4, 0, 0, true, 15, particleOptions),
// see softBody function defined later in this file
Example.softBody.softBody(250, 100, 5, 5, 0, 0, true, 18, particleOptions),
Example.softBody.softBody(400, 300, 8, 3, 0, 0, true, 15, particleOptions),
Example.softBody.softBody(250, 400, 4, 4, 0, 0, true, 15, particleOptions),
// walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Expand Down Expand Up @@ -88,6 +89,40 @@ Example.softBody = function() {
Example.softBody.title = 'Soft Body';
Example.softBody.for = '>=0.14.2';

/**
* Creates a simple soft body like object.
* @method softBody
* @param {number} xx
* @param {number} yy
* @param {number} columns
* @param {number} rows
* @param {number} columnGap
* @param {number} rowGap
* @param {boolean} crossBrace
* @param {number} particleRadius
* @param {} particleOptions
* @param {} constraintOptions
* @return {composite} A new composite softBody
*/
Example.softBody.softBody = function(xx, yy, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) {
var Common = Matter.Common,
Composites = Matter.Composites,
Bodies = Matter.Bodies;

particleOptions = Common.extend({ inertia: Infinity }, particleOptions);
constraintOptions = Common.extend({ stiffness: 0.2, render: { type: 'line', anchors: false } }, constraintOptions);

var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) {
return Bodies.circle(x, y, particleRadius, particleOptions);
});

Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);

softBody.label = 'Soft Body';

return softBody;
};

if (typeof module !== 'undefined') {
module.exports = Example.softBody;
}
2 changes: 2 additions & 0 deletions src/factory/Composites.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ var deprecated = Common.deprecated;

/**
* Creates a simple soft body like object.
* @deprecated moved to softBody and cloth examples
* @method softBody
* @param {number} xx
* @param {number} yy
Expand Down Expand Up @@ -328,4 +329,5 @@ var deprecated = Common.deprecated;
return softBody;
};

deprecated(Composites, 'softBody', 'Composites.softBody ➤ moved to softBody and cloth examples');
})();

0 comments on commit 818f354

Please sign in to comment.