overte/script-archive/entity-server-filter-example.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-01-23 13:08:33 -08:00
function filter(p) {
/* block comments are ok, but not double-slash end-of-line-comments */
/* Simple example: if someone specifies name, add an 'x' to it. Note that print is ok to use. */
if (p.name) {p.name += 'x'; print('fixme name', p. name);}
/* This example clamps y. A better filter would probably zero y component of velocity and acceleration. */
if (p.position) {p.position.y = Math.min(1, p.position.y); print('fixme p.y', p.position.y);}
/* Can also reject altogether */
if (p.userData) { return false; }
2017-01-24 11:56:50 -08:00
/* Reject if modifications made to Model properties */
if (p.modelURL || p.compoundShapeURL || p.shape || p.shapeType || p.url || p.fps || p.currentFrame || p.running || p.loop || p.firstFrame || p.lastFrame || p.hold || p.textures || p.xTextureURL || p.yTextureURL || p.zTextureURL) { return false; }
2017-01-24 12:11:33 -08:00
/* Clamp velocity to 5 units/second. Zeroing each component of acceleration keeps us from slamming.*/
2017-01-24 11:56:50 -08:00
if (p.velocity) {
2017-01-24 12:11:33 -08:00
if (p.velocity.x > 5) {
p.velocity.x = 5;
2017-01-24 11:56:50 -08:00
p.acceleration.x = 0;
}
2017-01-24 12:11:33 -08:00
if (p.velocity.y > 5) {
p.velocity.y = 5;
2017-01-24 11:56:50 -08:00
p.acceleration.y = 0;
}
2017-01-24 12:11:33 -08:00
if (p.velocity.z > 5) {
p.velocity.z = 5;
2017-01-24 11:56:50 -08:00
p.acceleration.z = 0;
}
}
2017-01-23 13:08:33 -08:00
/* If we make it this far, return the (possibly modified) properties. */
return p;
}