|
| 1 | +var ArrowHelperAutogen = require('./ArrowHelper.autogen').ArrowHelperModel; |
| 2 | + |
| 3 | +var THREE = require('three'); |
| 4 | + |
| 5 | +var ArrowHelperModel = ArrowHelperAutogen.extend({ |
| 6 | + |
| 7 | + constructThreeObject: function() { |
| 8 | + |
| 9 | + var headLength = this.get('headLength'); |
| 10 | + var headWidth = this.get('headWidth'); |
| 11 | + |
| 12 | + if (headLength === null) { |
| 13 | + headLength = undefined; |
| 14 | + } |
| 15 | + if (headWidth === null) { |
| 16 | + headWidth = undefined; |
| 17 | + } |
| 18 | + |
| 19 | + var result = new THREE.ArrowHelper( |
| 20 | + this.convertVectorModelToThree(this.get('dir'), 'dir'), |
| 21 | + this.convertVectorModelToThree(this.get('origin'), 'origin'), |
| 22 | + this.convertFloatModelToThree(this.get('length'), 'length'), |
| 23 | + this.convertColorModelToThree(this.get('color'), 'color'), |
| 24 | + this.convertFloatModelToThree(headLength, 'headLength'), |
| 25 | + this.convertFloatModelToThree(headWidth, 'headWidth') |
| 26 | + ); |
| 27 | + return Promise.resolve(result); |
| 28 | + |
| 29 | + }, |
| 30 | + |
| 31 | + |
| 32 | + createPropertiesArrays: function() { |
| 33 | + ArrowHelperAutogen.prototype.createPropertiesArrays.call(this); |
| 34 | + |
| 35 | + // Prevent from syncing these to object |
| 36 | + delete this.property_converters['origin']; |
| 37 | + |
| 38 | + // Map with setDirection |
| 39 | + delete this.property_converters['dir']; |
| 40 | + |
| 41 | + // Map with setColor |
| 42 | + delete this.property_converters['color']; |
| 43 | + |
| 44 | + // Map these to setLength instead |
| 45 | + delete this.property_converters['length']; |
| 46 | + delete this.property_converters['headLength']; |
| 47 | + delete this.property_converters['headWidth']; |
| 48 | + |
| 49 | + this.property_mappers['mapArrowHelper'] = 'mapArrowHelper'; |
| 50 | + }, |
| 51 | + |
| 52 | + mapArrowHelperModelToThree: function() { |
| 53 | + var headLength = this.get('headLength'); |
| 54 | + var headWidth = this.get('headWidth'); |
| 55 | + |
| 56 | + if (headLength === null) { |
| 57 | + headLength = undefined; |
| 58 | + } |
| 59 | + if (headWidth === null) { |
| 60 | + headWidth = undefined; |
| 61 | + } |
| 62 | + |
| 63 | + this.obj.setDirection(this.convertVectorModelToThree(this.get('dir'), 'dir')); |
| 64 | + this.obj.setColor(this.convertColorModelToThree(this.get('color'), 'color')); |
| 65 | + this.obj.position.copy(this.convertVectorModelToThree(this.get('origin'), 'origin')); |
| 66 | + |
| 67 | + this.obj.setLength( |
| 68 | + this.convertFloatModelToThree(this.get('length'), 'length'), |
| 69 | + this.convertFloatModelToThree(headLength, 'headLength'), |
| 70 | + this.convertFloatModelToThree(headWidth, 'headWidth') |
| 71 | + ); |
| 72 | + }, |
| 73 | + |
| 74 | + mapArrowHelperThreeToModel: function() { |
| 75 | + this.set({ |
| 76 | + headLength: this.convertFloatThreeToModel(this.obj.cone.scale.y, 'headLength'), |
| 77 | + headWidth: this.convertFloatThreeToModel(this.obj.cone.scale.x, 'headWidth'), |
| 78 | + origin: this.convertVectorThreeToModel(this.obj.position, 'origin'), |
| 79 | + }); |
| 80 | + } |
| 81 | + |
| 82 | +}); |
| 83 | + |
| 84 | +module.exports = { |
| 85 | + ArrowHelperModel: ArrowHelperModel, |
| 86 | +}; |
0 commit comments