Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pc.script.create('debugShape', function (app) {
  2.     // Creates a new DebugShape instance
  3.     var DebugShape = function (entity) {
  4.         this.entity = entity;
  5.     };
  6.  
  7.     DebugShape.prototype = {
  8.         // Called once after all resources are loaded and before the first update
  9.         initialize: function () {
  10.             // create debug entity which will render our shape
  11.             var debugEntity = new pc.Entity();
  12.             this.entity.addChild(debugEntity);
  13.            
  14.             // add model component to debugEntity depending on the collision type
  15.             if (this.entity.collision.type === 'mesh') {
  16.                 debugEntity.addComponent('model', {
  17.                     type: 'asset'
  18.                 });
  19.                      
  20.                 debugEntity.model.model = this.entity.collision.model.clone(); ;
  21.             } else if (this.entity.collision.type === 'box') {
  22.                 debugEntity.addComponent('model', {
  23.                     type: 'box',
  24.                     halfExtents: new pc.Vec3().copy(this.entity.collision.halfExtents)
  25.                 });
  26.             } else if (this.entity.collision.type === 'cylinder') {
  27.                 debugEntity.addComponent('model', {
  28.                     type: 'cylinder',
  29.                     height: this.entity.collision.height,
  30.                     radius: this.entity.collision.radius                    
  31.                 });
  32.             } else if (this.entity.collision.type === 'capsule') {
  33.                 debugEntity.addComponent('model', {
  34.                     type: 'capsule',
  35.                     height: this.entity.collision.height,
  36.                     radius: this.entity.collision.radius  
  37.                 });  
  38.             } else if (this.entity.collision.type === 'sphere') {
  39.                 debugEntity.addComponent('model', {
  40.                     type: 'sphere',
  41.                     radius: this.entity.collision.radius  
  42.                 });  
  43.             } else {
  44.                 return;
  45.             }
  46.            
  47.             // get model
  48.             var model = debugEntity.model.model;
  49.             // generate wireframe data
  50.             model.generateWireframe();        
  51.            
  52.             // create debug material
  53.             var material = new pc.BasicMaterial();
  54.             material.color = new pc.Color(0, 0, 1, 1);
  55.             material.update();
  56.            
  57.             // assign material to mesh instances and change render style to wireframe
  58.             model.meshInstances.forEach(function (instance) {
  59.                 instance.material = material;
  60.                 instance.renderStyle = pc.RENDERSTYLE_WIREFRAME;
  61.             });
  62.         }
  63.        
  64.     };
  65.  
  66.     return DebugShape;
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement