Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pc.script.create('debugShape', function (app) {
- // Creates a new DebugShape instance
- var DebugShape = function (entity) {
- this.entity = entity;
- };
- DebugShape.prototype = {
- // Called once after all resources are loaded and before the first update
- initialize: function () {
- // create debug entity which will render our shape
- var debugEntity = new pc.Entity();
- this.entity.addChild(debugEntity);
- // add model component to debugEntity depending on the collision type
- if (this.entity.collision.type === 'mesh') {
- debugEntity.addComponent('model', {
- type: 'asset'
- });
- debugEntity.model.model = this.entity.collision.model.clone(); ;
- } else if (this.entity.collision.type === 'box') {
- debugEntity.addComponent('model', {
- type: 'box',
- halfExtents: new pc.Vec3().copy(this.entity.collision.halfExtents)
- });
- } else if (this.entity.collision.type === 'cylinder') {
- debugEntity.addComponent('model', {
- type: 'cylinder',
- height: this.entity.collision.height,
- radius: this.entity.collision.radius
- });
- } else if (this.entity.collision.type === 'capsule') {
- debugEntity.addComponent('model', {
- type: 'capsule',
- height: this.entity.collision.height,
- radius: this.entity.collision.radius
- });
- } else if (this.entity.collision.type === 'sphere') {
- debugEntity.addComponent('model', {
- type: 'sphere',
- radius: this.entity.collision.radius
- });
- } else {
- return;
- }
- // get model
- var model = debugEntity.model.model;
- // generate wireframe data
- model.generateWireframe();
- // create debug material
- var material = new pc.BasicMaterial();
- material.color = new pc.Color(0, 0, 1, 1);
- material.update();
- // assign material to mesh instances and change render style to wireframe
- model.meshInstances.forEach(function (instance) {
- instance.material = material;
- instance.renderStyle = pc.RENDERSTYLE_WIREFRAME;
- });
- }
- };
- return DebugShape;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement