|
989 | 989 | {
|
990 | 990 | "type": "BuiltinCommonInstructions::JsCode",
|
991 | 991 | "inlineCode": [
|
992 |
| - "gdjs.__collisionDetectorExtension = gdjs.__collisionDetectorExtension || {};", |
| 992 | + "/**", |
| 993 | + " * @param {gdjs.BehaviorRBushAABB} fatAABB", |
| 994 | + " * @param {gdjs.AABB} aabb", |
| 995 | + " */", |
| 996 | + "const includesAABB = function(fatAABB, aabb) {", |
| 997 | + " return fatAABB.minX <= aabb.min[0] && aabb.max[0] <= fatAABB.maxX", |
| 998 | + " && fatAABB.minY <= aabb.min[1] && aabb.max[1] <= fatAABB.maxY;", |
| 999 | + "}", |
993 | 1000 | "",
|
994 | 1001 | "/**",
|
995 | 1002 | " * ",
|
996 | 1003 | " */",
|
997 |
| - "gdjs.__collisionDetectorExtension.SolidManager = /** @class */ (function () {", |
| 1004 | + "const SolidManager = /** @class */ (function () {", |
998 | 1005 | " /**",
|
999 | 1006 | " * Create a manager.",
|
1000 | 1007 | " */",
|
|
1003 | 1010 | " }",
|
1004 | 1011 | "",
|
1005 | 1012 | " /**",
|
1006 |
| - " * Add a boid to the R-Tree.", |
| 1013 | + " * Add an object to the R-Tree.", |
1007 | 1014 | " * @param {gdjs.RuntimeBehavior} behavior",
|
1008 | 1015 | " */",
|
1009 | 1016 | " SolidManager.prototype.add = function (behavior) {",
|
1010 |
| - " if (behavior.currentRBushAABB) {", |
1011 |
| - " behavior.currentRBushAABB.updateAABBFromOwner();", |
1012 |
| - " }", |
1013 |
| - " else {", |
| 1017 | + " if (!behavior.currentRBushAABB) {", |
1014 | 1018 | " behavior.currentRBushAABB = new gdjs.BehaviorRBushAABB(",
|
1015 | 1019 | " behavior",
|
1016 | 1020 | " );",
|
1017 | 1021 | " }",
|
| 1022 | + " //behavior.currentRBushAABB.updateAABBFromOwner();", |
| 1023 | + " const aabb = behavior.owner.getAABB();", |
| 1024 | + " const fatFactor = behavior._getFatFactor();", |
| 1025 | + " const marginX = fatFactor * (aabb.min[0] - aabb.max[0]);", |
| 1026 | + " const marginY = fatFactor * (aabb.min[1] - aabb.max[1]);", |
| 1027 | + " const fatAABB = behavior.currentRBushAABB;", |
| 1028 | + " fatAABB.minX = aabb.min[0] - marginX;", |
| 1029 | + " fatAABB.minY = aabb.min[1] - marginY;", |
| 1030 | + " fatAABB.maxX = aabb.max[0] + marginX;", |
| 1031 | + " fatAABB.maxY = aabb.max[1] + marginY;", |
| 1032 | + " ", |
1018 | 1033 | " const rBush = this.getRBush(behavior.owner.getName());",
|
1019 |
| - " rBush.insert(behavior.currentRBushAABB);", |
| 1034 | + " rBush.insert(fatAABB);", |
1020 | 1035 | " }",
|
1021 | 1036 | "",
|
1022 | 1037 | " /**",
|
1023 |
| - " * Remove a boid from the R-Tree.", |
| 1038 | + " * Remove an object from the R-Tree.", |
1024 | 1039 | " * @param {gdjs.RuntimeBehavior} behavior",
|
1025 | 1040 | " */",
|
1026 | 1041 | " SolidManager.prototype.remove = function (behavior) {",
|
1027 | 1042 | " const rBush = this.getRBush(behavior.owner.getName());",
|
1028 | 1043 | " rBush.remove(behavior.currentRBushAABB);",
|
1029 | 1044 | " }",
|
| 1045 | + " ", |
| 1046 | + " /**", |
| 1047 | + " * Update an object to the R-Tree.", |
| 1048 | + " * @param {gdjs.RuntimeBehavior} behavior", |
| 1049 | + " */", |
| 1050 | + " SolidManager.prototype.update = function (behavior) {", |
| 1051 | + " const fatAABB = behavior.currentRBushAABB;", |
| 1052 | + " const aabb = behavior.owner.getAABB();", |
| 1053 | + "", |
| 1054 | + " if (!includesAABB(fatAABB, aabb)) {", |
| 1055 | + " const rBush = this.getRBush(behavior.owner.getName());", |
| 1056 | + " this.remove(behavior);", |
| 1057 | + " this.add(behavior);", |
| 1058 | + " }", |
| 1059 | + " }", |
1030 | 1060 | "",
|
1031 | 1061 | " SolidManager.prototype.getRBush = function (objectName) {",
|
1032 | 1062 | " let rBush = this.rBushes.get(objectName);",
|
|
1049 | 1079 | " */",
|
1050 | 1080 | " SolidManager.prototype.getAllInstancesInRectangle = function (objectName, left, top, right, bottom, results) {",
|
1051 | 1081 | " const searchArea = gdjs.staticObject(",
|
1052 |
| - " gdjs.__collisionDetectorExtension.SolidManager.prototype.getAllInstancesInRectangle", |
| 1082 | + " SolidManager.prototype.getAllInstancesInRectangle", |
1053 | 1083 | " );",
|
1054 | 1084 | " searchArea.minX = left;",
|
1055 | 1085 | " searchArea.minY = top;",
|
|
1065 | 1095 | "",
|
1066 | 1096 | " return SolidManager;",
|
1067 | 1097 | "}());",
|
| 1098 | + "", |
| 1099 | + "gdjs.__collisionDetectorExtension = gdjs.__collisionDetectorExtension || {};", |
| 1100 | + "gdjs.__collisionDetectorExtension.SolidManager = SolidManager;", |
1068 | 1101 | ""
|
1069 | 1102 | ],
|
1070 | 1103 | "parameterObjects": "",
|
|
1284 | 1317 | "useStrict": true,
|
1285 | 1318 | "eventsSheetExpanded": false
|
1286 | 1319 | },
|
| 1320 | + { |
| 1321 | + "type": "BuiltinCommonInstructions::Standard", |
| 1322 | + "conditions": [ |
| 1323 | + { |
| 1324 | + "type": { |
| 1325 | + "value": "CollisionDetector::Solid::PropertySolidType" |
| 1326 | + }, |
| 1327 | + "parameters": [ |
| 1328 | + "Object", |
| 1329 | + "Behavior", |
| 1330 | + "=", |
| 1331 | + "\"Static\"" |
| 1332 | + ] |
| 1333 | + } |
| 1334 | + ], |
| 1335 | + "actions": [ |
| 1336 | + { |
| 1337 | + "type": { |
| 1338 | + "value": "CollisionDetector::Solid::SetPropertyFatFactor" |
| 1339 | + }, |
| 1340 | + "parameters": [ |
| 1341 | + "Object", |
| 1342 | + "Behavior", |
| 1343 | + "=", |
| 1344 | + "0" |
| 1345 | + ] |
| 1346 | + } |
| 1347 | + ] |
| 1348 | + }, |
1287 | 1349 | {
|
1288 | 1350 | "type": "BuiltinCommonInstructions::Standard",
|
1289 | 1351 | "conditions": [],
|
|
1437 | 1499 | "sentence": "",
|
1438 | 1500 | "events": [
|
1439 | 1501 | {
|
| 1502 | + "type": "BuiltinCommonInstructions::Standard", |
| 1503 | + "conditions": [], |
| 1504 | + "actions": [ |
| 1505 | + { |
| 1506 | + "type": { |
| 1507 | + "value": "CollisionDetector::Solid::UpdateInTree" |
| 1508 | + }, |
| 1509 | + "parameters": [ |
| 1510 | + "Object", |
| 1511 | + "Behavior", |
| 1512 | + "" |
| 1513 | + ] |
| 1514 | + } |
| 1515 | + ] |
| 1516 | + }, |
| 1517 | + { |
| 1518 | + "disabled": true, |
1440 | 1519 | "type": "BuiltinCommonInstructions::Standard",
|
1441 | 1520 | "conditions": [
|
1442 | 1521 | {
|
|
1596 | 1675 | "sentence": "Update _PARAM0_ in the tree",
|
1597 | 1676 | "events": [
|
1598 | 1677 | {
|
1599 |
| - "type": "BuiltinCommonInstructions::Standard", |
1600 |
| - "conditions": [], |
1601 |
| - "actions": [ |
1602 |
| - { |
1603 |
| - "type": { |
1604 |
| - "value": "CollisionDetector::Solid::RemoveFromTree" |
1605 |
| - }, |
1606 |
| - "parameters": [ |
1607 |
| - "Object", |
1608 |
| - "Behavior", |
1609 |
| - "" |
1610 |
| - ] |
1611 |
| - }, |
1612 |
| - { |
1613 |
| - "type": { |
1614 |
| - "value": "CollisionDetector::Solid::AddToTree" |
1615 |
| - }, |
1616 |
| - "parameters": [ |
1617 |
| - "Object", |
1618 |
| - "Behavior", |
1619 |
| - "" |
1620 |
| - ] |
1621 |
| - } |
1622 |
| - ] |
| 1678 | + "type": "BuiltinCommonInstructions::JsCode", |
| 1679 | + "inlineCode": [ |
| 1680 | + "const object = objects[0];\r", |
| 1681 | + "const behaviorName = eventsFunctionContext.getBehaviorName(\"Behavior\");\r", |
| 1682 | + "const behavior = object.getBehavior(behaviorName);\r", |
| 1683 | + "\r", |
| 1684 | + "runtimeScene.__collisionDetectorExtension.solidManager.update(behavior);" |
| 1685 | + ], |
| 1686 | + "parameterObjects": "Object", |
| 1687 | + "useStrict": true, |
| 1688 | + "eventsSheetExpanded": false |
1623 | 1689 | }
|
1624 | 1690 | ],
|
1625 | 1691 | "parameters": [
|
|
1762 | 1828 | "extraInformation": [],
|
1763 | 1829 | "hidden": true,
|
1764 | 1830 | "name": "PreviousAngle"
|
| 1831 | + }, |
| 1832 | + { |
| 1833 | + "value": "0.5", |
| 1834 | + "type": "Number", |
| 1835 | + "label": "", |
| 1836 | + "description": "", |
| 1837 | + "group": "", |
| 1838 | + "extraInformation": [], |
| 1839 | + "hidden": true, |
| 1840 | + "name": "FatFactor" |
| 1841 | + }, |
| 1842 | + { |
| 1843 | + "value": "Automatic", |
| 1844 | + "type": "Choice", |
| 1845 | + "label": "Type", |
| 1846 | + "description": "", |
| 1847 | + "group": "", |
| 1848 | + "extraInformation": [ |
| 1849 | + "Automatic", |
| 1850 | + "Mobile", |
| 1851 | + "Static" |
| 1852 | + ], |
| 1853 | + "hidden": false, |
| 1854 | + "name": "SolidType" |
1765 | 1855 | }
|
1766 | 1856 | ],
|
1767 | 1857 | "sharedPropertyDescriptors": []
|
|
0 commit comments