starling-framework
Version:
A fast, productive library for 2D cross-platform development.
225 lines (210 loc) • 8.54 kB
JavaScript
// Class: starling.display.Mesh
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $hxEnums = require("./../../hxEnums_stub").default;
var $import = require("./../../import_stub").default;
var $extend = require("./../../extend_stub").default;
function starling_display_DisplayObject() {return require("./../../starling/display/DisplayObject");}
function starling_utils_MeshUtil() {return require("./../../starling/utils/MeshUtil");}
function starling_utils_MatrixUtil() {return require("./../../starling/utils/MatrixUtil");}
function starling_styles_MeshStyle() {return require("./../../starling/styles/MeshStyle");}
function Type() {return require("./../../Type");}
function starling_rendering_VertexData() {return require("./../../starling/rendering/VertexData");}
function starling_rendering_IndexData() {return require("./../../starling/rendering/IndexData");}
function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");}
function openfl_errors_ArgumentError() {return $import(require("openfl/errors/ArgumentError"));}
// Constructor
var Mesh = function(vertexData,indexData,style) {
(starling_display_DisplayObject().default).call(this);
if(vertexData == null) {
throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("VertexData must not be null"));
}
if(indexData == null) {
throw new (js__$Boot_HaxeError().default)(new (openfl_errors_ArgumentError().default)("IndexData must not be null"));
}
this.__vertexData = vertexData;
this.__indexData = indexData;
this.setStyle(style,false);
}
// Meta
Mesh.__name__ = "starling.display.Mesh";
Mesh.__isInterface__ = false;
Mesh.__super__ = (starling_display_DisplayObject().default);
Mesh.prototype = $extend((starling_display_DisplayObject().default).prototype, {
dispose: function() {
this.__vertexData.clear();
this.__indexData.clear();
(starling_display_DisplayObject().default).prototype.dispose.call(this);
},
hitTest: function(localPoint) {
if(!this.get_visible() || !this.get_touchable() || !this.hitTestMask(localPoint)) {
return null;
} else if((starling_utils_MeshUtil().default).containsPoint(this.__vertexData,this.__indexData,localPoint)) {
return this;
} else {
return null;
}
},
getBounds: function(targetSpace,out) {
return (starling_utils_MeshUtil().default).calculateBounds(this.__vertexData,this,targetSpace,out);
},
render: function(painter) {
if(this.__pixelSnapping) {
(starling_utils_MatrixUtil().default).snapToPixels(painter.get_state().get_modelviewMatrix(),painter.get_pixelSize());
}
painter.batchMesh(this);
},
setStyle: function(meshStyle,mergeWithPredecessor) {
if(mergeWithPredecessor == null) {
mergeWithPredecessor = true;
}
if(meshStyle == null) {
meshStyle = Mesh.createDefaultStyle(this);
} else if(meshStyle == this.__style) {
return;
} else if(meshStyle.get_target() != null) {
meshStyle.get_target().setStyle();
}
if(this.__style != null) {
if(mergeWithPredecessor) {
meshStyle.copyFrom(this.__style);
}
this.__style.setTarget();
}
this.__style = meshStyle;
this.__style.setTarget(this,this.__vertexData,this.__indexData);
this.setRequiresRedraw();
},
setVertexDataChanged: function() {
this.setRequiresRedraw();
},
setIndexDataChanged: function() {
this.setRequiresRedraw();
},
getVertexPosition: function(vertexID,out) {
return this.__style.getVertexPosition(vertexID,out);
},
setVertexPosition: function(vertexID,x,y) {
this.__style.setVertexPosition(vertexID,x,y);
},
getVertexAlpha: function(vertexID) {
return this.__style.getVertexAlpha(vertexID);
},
setVertexAlpha: function(vertexID,alpha) {
this.__style.setVertexAlpha(vertexID,alpha);
},
getVertexColor: function(vertexID) {
return this.__style.getVertexColor(vertexID);
},
setVertexColor: function(vertexID,color) {
this.__style.setVertexColor(vertexID,color);
},
getTexCoords: function(vertexID,out) {
return this.__style.getTexCoords(vertexID,out);
},
setTexCoords: function(vertexID,u,v) {
this.__style.setTexCoords(vertexID,u,v);
},
get_vertexData: function() {
return this.__vertexData;
},
get_indexData: function() {
return this.__indexData;
},
get_style: function() {
return this.__style;
},
set_style: function(value) {
this.setStyle(value);
return value;
},
get_texture: function() {
return this.__style.get_texture();
},
set_texture: function(value) {
return this.__style.set_texture(value);
},
get_color: function() {
return this.__style.get_color();
},
set_color: function(value) {
return this.__style.set_color(value);
},
get_textureSmoothing: function() {
return this.__style.get_textureSmoothing();
},
set_textureSmoothing: function(value) {
return this.__style.set_textureSmoothing(value);
},
get_textureRepeat: function() {
return this.__style.get_textureRepeat();
},
set_textureRepeat: function(value) {
return this.__style.set_textureRepeat(value);
},
get_pixelSnapping: function() {
return this.__pixelSnapping;
},
set_pixelSnapping: function(value) {
return this.__pixelSnapping = value;
},
get_numVertices: function() {
return this.__vertexData.get_numVertices();
},
get_numIndices: function() {
return this.__indexData.get_numIndices();
},
get_numTriangles: function() {
return this.__indexData.get_numTriangles();
},
get_vertexFormat: function() {
return this.__style.get_vertexFormat();
}
});
Mesh.prototype.__class__ = Mesh.prototype.constructor = $hxClasses["starling.display.Mesh"] = Mesh;
// Init
{
Object.defineProperties(Mesh.prototype,{ vertexData : { get : function () { return this.get_vertexData (); }}, indexData : { get : function () { return this.get_indexData (); }}, style : { get : function () { return this.get_style (); }, set : function (v) { return this.set_style (v); }}, texture : { get : function () { return this.get_texture (); }, set : function (v) { return this.set_texture (v); }}, color : { get : function () { return this.get_color (); }, set : function (v) { return this.set_color (v); }}, textureSmoothing : { get : function () { return this.get_textureSmoothing (); }, set : function (v) { return this.set_textureSmoothing (v); }}, textureRepeat : { get : function () { return this.get_textureRepeat (); }, set : function (v) { return this.set_textureRepeat (v); }}, pixelSnapping : { get : function () { return this.get_pixelSnapping (); }, set : function (v) { return this.set_pixelSnapping (v); }}, numVertices : { get : function () { return this.get_numVertices (); }}, numIndices : { get : function () { return this.get_numIndices (); }}, numTriangles : { get : function () { return this.get_numTriangles (); }}, vertexFormat : { get : function () { return this.get_vertexFormat (); }}});
Object.defineProperties(Mesh,{ defaultStyle : { get : function () { return Mesh.get_defaultStyle (); }, set : function (v) { return Mesh.set_defaultStyle (v); }}, defaultStyleFactory : { get : function () { return Mesh.get_defaultStyleFactory (); }, set : function (v) { return Mesh.set_defaultStyleFactory (v); }}});
};
// Statics
Mesh.createDefaultStyle = function(instance) {
var meshStyle = null;
if(Mesh.sDefaultStyleFactory != null) {
if(instance == null) {
meshStyle = Mesh.sDefaultStyleFactory();
} else {
meshStyle = Mesh.sDefaultStyleFactory(instance);
}
}
if(meshStyle == null) {
meshStyle = (Type().default).createInstance(Mesh.sDefaultStyle,[]);
}
return meshStyle;
}
Mesh.get_defaultStyle = function() {
return Mesh.sDefaultStyle;
}
Mesh.set_defaultStyle = function(value) {
return Mesh.sDefaultStyle = value;
}
Mesh.get_defaultStyleFactory = function() {
return Mesh.sDefaultStyleFactory;
}
Mesh.set_defaultStyleFactory = function(value) {
return Mesh.sDefaultStyleFactory = value;
}
Mesh.fromPolygon = function(polygon,style) {
var vertexData = new (starling_rendering_VertexData().default)(null,polygon.get_numVertices());
var indexData = new (starling_rendering_IndexData().default)(polygon.get_numTriangles());
polygon.copyToVertexData(vertexData);
polygon.triangulate(indexData);
return new Mesh(vertexData,indexData,style);
}
Mesh.sDefaultStyle = (starling_styles_MeshStyle().default)
Mesh.sDefaultStyleFactory = null
// Export
exports.default = Mesh;