function filter(p, isAdd) { /* Filter in which you define a zone that no entites can enter */ /* Default box coordinates correspond to stage area in dev-demo */ if (p.position) { /* Define the points that create the "NO ENTITIES ALLOWED" box */ var BigStageMin = {x: 90, y: -1, z: 23}; var BigStageMax = {x: 109, y: 10, z: 31}; var ProceniumMin = {x: 97.5, y: -1, z: 31}; var ProceniumMax = {x: 102, y: 10, z: 33.5}; /* Exclude the two mats underneath the whiteboards on stage, used for the demo on Friday, 2017-02-03 */ var WhiteboardMat1Min = {x: 94.03635, y: -0.9196, z: 27.78185}; var WhiteboardMat1Max = {x: 98.08725, y: 4, z: 30.59055}; var WhiteboardMat2Min = {x: 100.83045, y: -0.9196, z: 27.78185}; var WhiteboardMat2Max = {x: 104.88135, y: 4, z: 30.59055}; var x = p.position.x; var y = p.position.y; var z = p.position.z; var isOnStage = (((x > BigStageMin.x && x < BigStageMax.x) && (y > BigStageMin.y && y < BigStageMax.y) && (z > BigStageMin.z && z < BigStageMax.z)) || ((x > ProceniumMin.x && x < ProceniumMax.x) && (y > ProceniumMin.y && y < ProceniumMax.y) && (z > ProceniumMin.z && z < ProceniumMax.z))); var isOnWhiteboardMat1 = ((x > WhiteboardMat1Min.x && x < WhiteboardMat1Max.x) && (y > WhiteboardMat1Min.y && y < WhiteboardMat1Max.y) && (z > WhiteboardMat1Min.z && z < WhiteboardMat1Max.z)); var isOnWhiteboardMat2 = ((x > WhiteboardMat2Min.x && x < WhiteboardMat2Max.x) && (y > WhiteboardMat2Min.y && y < WhiteboardMat2Max.y) && (z > WhiteboardMat2Min.z && z < WhiteboardMat2Max.z)); if (isOnStage && !(isOnWhiteboardMat1 || isOnWhiteboardMat2)) { /* this basically makes the offending entity go away. Feels like * overkill, but a place to start given changes we've seen recently */ p.collisionless = 1; p.lifetime = 1.0; } } /* Only apply the filters below if the entity is inside the theater */ /* AND if this entity wasn't just spawned */ var WholeTheaterMin = {x: 79.0, y: -2.9, z: 14.0}; var WholeTheaterMax = {x: 119, y: 13.0, z: 56}; if ((x > WholeTheaterMin.x && x < WholeTheaterMax.x) && (y > WholeTheaterMin.y && y < WholeTheaterMax.y) && (z > WholeTheaterMin.z && z < WholeTheaterMax.z) && !isAdd) { /* together the density, dimensions and velocity filters cap momentum, which * helps with how griefed you are by someone whacking you with things */ var MAX_DENSITY = 1500; var MAX_EXTENT = 0.6; var MAX_VELOCITY = 4.0; /* cap density at standard 1 kg/m^3) */ if (p.density && p.density > MAX_DENSITY) { p.density = MAX_DENSITY; } /* cap bounding box */ if (p.dimensions) { function capDimension(d) { if (d > MAX_EXTENT) { return MAX_EXTENT; } return d; } p.dimensions.x = capDimension(p.dimensions.x); p.dimensions.y = capDimension(p.dimensions.y); p.dimensions.z = capDimension(p.dimensions.z); } /* Clamp magnitude of the velocity vector * for now, not changing acceleration */ if (p.velocity) { function magnitude(v) { return Math.sqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z)); } var magV = magnitude(p.velocity); if (magV > MAX_VELOCITY) { var ratio = MAX_VELOCITY/magV; // reduce it proportionally p.velocity.x = p.velocity.x * ratio; p.velocity.y = p.velocity.y * ratio; p.velocity.z = p.velocity.z * ratio; } } /* Reject if modifications made to Model properties, OR */ /* Reject if modifications made to source URL (for Web entities) OR */ /* Reject if modifications made to dimensions */ if (p.modelURL !== undefined || p.compoundShapeURL || p.shape || p.shapeType || p.url || p.fps || p.currentFrame || p.running || p.loop || p.firstFrame || p.lastFrame || p.hold || p.textures !== undefined || p.xTextureURL !== undefined || p.yTextureURL !== undefined || p.zTextureURL !== undefined || p.sourceUrl !== undefined || p.dimensions) { return false; } } return p; }