├── bin
├── unpack.json
├── res
│ └── atlas
│ │ ├── comp.png
│ │ ├── .rec
│ │ └── comp.atlas
├── index.html
└── libs
│ ├── min
│ ├── laya.d3Plugin.min.js
│ ├── laya.filter.min.js
│ ├── laya.html.min.js
│ ├── laya.device.min.js
│ ├── laya.wxmini.min.js
│ ├── laya.pathfinding.min.js
│ ├── laya.particle.min.js
│ └── laya.tiledmap.min.js
│ ├── laya.d3Plugin.js
│ ├── matter-RenderLaya.js
│ ├── laya.filter.js
│ ├── LayaRender.js
│ └── worker.js
├── typings
└── index.d.ts
├── config
├── prod.env.js
├── dev.env.js
└── index.js
├── laya-webpack-typescript.laya
├── laya
├── assets
│ └── comp
│ │ ├── bg.png
│ │ ├── html.png
│ │ ├── tab.png
│ │ ├── blank.png
│ │ ├── button.png
│ │ ├── hscroll.png
│ │ ├── hslider.png
│ │ ├── image.png
│ │ ├── label.png
│ │ ├── radio.png
│ │ ├── vscroll.png
│ │ ├── vslider.png
│ │ ├── btn_close.png
│ │ ├── checkbox.png
│ │ ├── clip_num.png
│ │ ├── combobox.png
│ │ ├── progress.png
│ │ ├── textarea.png
│ │ ├── textinput.png
│ │ ├── hscroll$bar.png
│ │ ├── hscroll$down.png
│ │ ├── hscroll$up.png
│ │ ├── hslider$bar.png
│ │ ├── linkbutton.png
│ │ ├── progress$bar.png
│ │ ├── radiogroup.png
│ │ ├── vscroll$bar.png
│ │ ├── vscroll$down.png
│ │ ├── vscroll$up.png
│ │ ├── vslider$bar.png
│ │ ├── clip_selectBox.png
│ │ ├── clip_tree_arrow.png
│ │ └── clip_tree_folder.png
├── pages
│ └── DemoPage.ui
└── .laya
├── .editorconfig
├── .gitignore
├── README.md
├── .babelrc
├── tsconfig.json
├── src
├── main.ts
└── ui
│ └── layaUI.max.all.ts
└── package.json
/bin/unpack.json:
--------------------------------------------------------------------------------
1 | []
--------------------------------------------------------------------------------
/typings/index.d.ts:
--------------------------------------------------------------------------------
1 | ///
PathFinding 类用于创建寻路。
9 | */
10 | //class laya.d3.component.PathFind extends laya.d3.component.Component3D
11 | var PathFind=(function(_super){
12 | function PathFind(){
13 | /**@private */
14 | this._meshTerrainSprite3D=null;
15 | /**@private */
16 | this._finder=null;
17 | /**@private */
18 | this._setting=null;
19 | /**寻路网格。*/
20 | this.grid=null;
21 | PathFind.__super.call(this);
22 | }
23 |
24 | __class(PathFind,'laya.d3.component.PathFind',_super);
25 | var __proto=PathFind.prototype;
26 | /**
27 | *@private
28 | *初始化载入蒙皮动画组件。
29 | *@param owner 所属精灵对象。
30 | */
31 | __proto._load=function(owner){
32 | if (! (owner instanceof laya.d3.core.MeshTerrainSprite3D ))
33 | throw new Error("PathFinding: The owner must MeshTerrainSprite3D!");
34 | _super.prototype._load.call(this,owner);
35 | this._meshTerrainSprite3D=owner;
36 | }
37 |
38 | /**
39 | *寻找路径。
40 | *@param startX 开始X。
41 | *@param startZ 开始Z。
42 | *@param endX 结束X。
43 | *@param endZ 结束Z。
44 | *@return 路径。
45 | */
46 | __proto.findPath=function(startX,startZ,endX,endZ){
47 | var minX=this._meshTerrainSprite3D.minX;
48 | var minZ=this._meshTerrainSprite3D.minZ;
49 | var cellX=this._meshTerrainSprite3D.width / this.grid.width;
50 | var cellZ=this._meshTerrainSprite3D.depth / this.grid.height;
51 | var halfCellX=cellX / 2;
52 | var halfCellZ=cellZ / 2;
53 | var gridStartX=Math.floor((startX-minX)/ cellX);
54 | var gridStartZ=Math.floor((startZ-minZ)/ cellZ);
55 | var gridEndX=Math.floor((endX-minX)/ cellX);
56 | var gridEndZ=Math.floor((endZ-minZ)/ cellZ);
57 | var boundWidth=this.grid.width-1;
58 | var boundHeight=this.grid.height-1;
59 | (gridStartX > boundWidth)&& (gridStartX=boundWidth);
60 | (gridStartZ > boundHeight)&& (gridStartZ=boundHeight);
61 | (gridStartX < 0)&& (gridStartX=0);
62 | (gridStartZ < 0)&& (gridStartZ=0);
63 | (gridEndX > boundWidth)&& (gridEndX=boundWidth);
64 | (gridEndZ > boundHeight)&& (gridEndZ=boundHeight);
65 | (gridEndX < 0)&& (gridEndX=0);
66 | (gridEndZ < 0)&& (gridEndZ=0);
67 | var path=this._finder.findPath(gridStartX,gridStartZ,gridEndX,gridEndZ,this.grid);
68 | this.grid.reset();
69 | for (var i=1;i < path.length-1;i++){
70 | var gridPos=path[i];
71 | gridPos[0]=gridPos[0] *cellX+halfCellX+minX;
72 | gridPos[1]=gridPos[1] *cellZ+halfCellZ+minZ;
73 | }
74 | if (path.length==1){
75 | path[0][0]=endX;
76 | path[0][1]=endX;
77 | }else if (path.length > 1){
78 | path[0][0]=startX;
79 | path[0][1]=startZ;
80 | path[path.length-1][0]=endX;
81 | path[path.length-1][1]=endZ;
82 | }
83 | return path;
84 | }
85 |
86 | /**
87 | *设置寻路设置。
88 | *@param value 寻路设置。
89 | */
90 | /**
91 | *获取寻路设置。
92 | *@return 寻路设置。
93 | */
94 | __getset(0,__proto,'setting',function(){
95 | return this._setting;
96 | },function(value){
97 | (value)&& (this._finder=new PathFinding.finders.AStarFinder(value));
98 | this._setting=value;
99 | });
100 |
101 | return PathFind;
102 | })(Component3D)
103 |
104 |
105 |
106 | })(window,document,Laya);
107 |
108 | if (typeof define === 'function' && define.amd){
109 | define('laya.core', ['require', "exports"], function(require, exports) {
110 | 'use strict';
111 | Object.defineProperty(exports, '__esModule', { value: true });
112 | for (var i in Laya) {
113 | var o = Laya[i];
114 | o && o.__isclass && (exports[i] = o);
115 | }
116 | });
117 | }
--------------------------------------------------------------------------------
/bin/res/atlas/comp.atlas:
--------------------------------------------------------------------------------
1 | {"frames":{"bg.png":{"frame":{"h":79,"idx":0,"w":100,"x":151,"y":0},"sourceSize":{"h":79,"w":100},"spriteSourceSize":{"x":0,"y":0}},"blank.png":{"frame":{"h":10,"idx":0,"w":10,"x":344,"y":138},"sourceSize":{"h":10,"w":10},"spriteSourceSize":{"x":0,"y":0}},"btn_close.png":{"frame":{"h":60,"idx":0,"w":28,"x":328,"y":0},"sourceSize":{"h":60,"w":28},"spriteSourceSize":{"x":0,"y":0}},"button.png":{"frame":{"h":69,"idx":0,"w":75,"x":252,"y":0},"sourceSize":{"h":69,"w":75},"spriteSourceSize":{"x":0,"y":0}},"checkbox.png":{"frame":{"h":42,"idx":0,"w":14,"x":364,"y":138},"sourceSize":{"h":42,"w":14},"spriteSourceSize":{"x":0,"y":0}},"clip_num.png":{"frame":{"h":27,"idx":0,"w":240,"x":151,"y":80},"sourceSize":{"h":27,"w":240},"spriteSourceSize":{"x":0,"y":0}},"clip_selectBox.png":{"frame":{"h":40,"idx":0,"w":100,"x":243,"y":108},"sourceSize":{"h":40,"w":100},"spriteSourceSize":{"x":0,"y":0}},"clip_tree_arrow.png":{"frame":{"h":28,"idx":0,"w":14,"x":379,"y":224},"sourceSize":{"h":28,"w":14},"spriteSourceSize":{"x":0,"y":0}},"clip_tree_folder.png":{"frame":{"h":48,"idx":0,"w":16,"x":314,"y":206},"sourceSize":{"h":48,"w":16},"spriteSourceSize":{"x":0,"y":0}},"combobox.png":{"frame":{"h":69,"idx":0,"w":91,"x":151,"y":108},"sourceSize":{"h":69,"w":91},"spriteSourceSize":{"x":0,"y":0}},"hscroll$bar.png":{"frame":{"h":51,"idx":0,"w":21,"x":375,"y":0},"sourceSize":{"h":51,"w":21},"spriteSourceSize":{"x":0,"y":0}},"hscroll$down.png":{"frame":{"h":51,"idx":0,"w":17,"x":343,"y":187},"sourceSize":{"h":51,"w":17},"spriteSourceSize":{"x":0,"y":0}},"hscroll$up.png":{"frame":{"h":51,"idx":0,"w":17,"x":392,"y":52},"sourceSize":{"h":51,"w":17},"spriteSourceSize":{"x":0,"y":0}},"hscroll.png":{"frame":{"h":17,"idx":0,"w":33,"x":331,"y":239},"sourceSize":{"h":17,"w":33},"spriteSourceSize":{"x":0,"y":0}},"hslider$bar.png":{"frame":{"h":42,"idx":0,"w":14,"x":395,"y":104},"sourceSize":{"h":42,"w":14},"spriteSourceSize":{"x":0,"y":0}},"hslider.png":{"frame":{"h":6,"idx":0,"w":100,"x":252,"y":70},"sourceSize":{"h":6,"w":100},"spriteSourceSize":{"x":0,"y":0}},"html.png":{"frame":{"h":18,"idx":0,"w":120,"x":243,"y":149},"sourceSize":{"h":18,"w":120},"spriteSourceSize":{"x":0,"y":0}},"image.png":{"frame":{"h":250,"idx":0,"w":150,"x":0,"y":0},"sourceSize":{"h":250,"w":150},"spriteSourceSize":{"x":0,"y":0}},"label.png":{"frame":{"h":18,"idx":0,"w":120,"x":222,"y":187},"sourceSize":{"h":18,"w":120},"spriteSourceSize":{"x":0,"y":0}},"linkbutton.png":{"frame":{"h":18,"idx":0,"w":120,"x":243,"y":168},"sourceSize":{"h":18,"w":120},"spriteSourceSize":{"x":0,"y":0}},"progress$bar.png":{"frame":{"h":14,"idx":0,"w":50,"x":344,"y":108},"sourceSize":{"h":14,"w":50},"spriteSourceSize":{"x":0,"y":0}},"progress.png":{"frame":{"h":14,"idx":0,"w":50,"x":344,"y":123},"sourceSize":{"h":14,"w":50},"spriteSourceSize":{"x":0,"y":0}},"radio.png":{"frame":{"h":42,"idx":0,"w":14,"x":379,"y":181},"sourceSize":{"h":42,"w":14},"spriteSourceSize":{"x":0,"y":0}},"radiogroup.png":{"frame":{"h":42,"idx":0,"w":14,"x":379,"y":138},"sourceSize":{"h":42,"w":14},"spriteSourceSize":{"x":0,"y":0}},"tab.png":{"frame":{"h":78,"idx":0,"w":70,"x":151,"y":178},"sourceSize":{"h":78,"w":70},"spriteSourceSize":{"x":0,"y":0}},"textarea.png":{"frame":{"h":23,"idx":0,"w":91,"x":222,"y":206},"sourceSize":{"h":23,"w":91},"spriteSourceSize":{"x":0,"y":0}},"textinput.png":{"frame":{"h":23,"idx":0,"w":91,"x":222,"y":230},"sourceSize":{"h":23,"w":91},"spriteSourceSize":{"x":0,"y":0}},"vscroll$bar.png":{"frame":{"h":63,"idx":0,"w":17,"x":357,"y":0},"sourceSize":{"h":63,"w":17},"spriteSourceSize":{"x":0,"y":0}},"vscroll$down.png":{"frame":{"h":51,"idx":0,"w":17,"x":397,"y":0},"sourceSize":{"h":51,"w":17},"spriteSourceSize":{"x":0,"y":0}},"vscroll$up.png":{"frame":{"h":51,"idx":0,"w":17,"x":361,"y":187},"sourceSize":{"h":51,"w":17},"spriteSourceSize":{"x":0,"y":0}},"vscroll.png":{"frame":{"h":33,"idx":0,"w":17,"x":394,"y":190},"sourceSize":{"h":33,"w":17},"spriteSourceSize":{"x":0,"y":0}},"vslider$bar.png":{"frame":{"h":42,"idx":0,"w":14,"x":394,"y":147},"sourceSize":{"h":42,"w":14},"spriteSourceSize":{"x":0,"y":0}},"vslider.png":{"frame":{"h":100,"idx":0,"w":6,"x":410,"y":52},"sourceSize":{"h":100,"w":6},"spriteSourceSize":{"x":0,"y":0}}},"meta":{"image":"comp.png","prefix":"comp/"}}
--------------------------------------------------------------------------------
/bin/libs/min/laya.filter.min.js:
--------------------------------------------------------------------------------
1 | !function(t,e,i){i.un,i.uns,i.static;var a=i.class,r=i.getset,n=(i.__newvec,laya.utils.Browser,laya.utils.Color),s=laya.filters.ColorFilterAction,l=laya.filters.webgl.ColorFilterActionGL,o=laya.filters.Filter,u=laya.filters.webgl.FilterActionGL,c=laya.maths.Matrix,h=(laya.maths.Rectangle,laya.renders.Render),f=(laya.renders.RenderContext,laya.webgl.resource.RenderTarget2D),_=laya.utils.RunDriver,d=(laya.webgl.shader.d2.ShaderDefines2D,laya.display.Sprite,laya.resource.Texture,laya.webgl.shader.d2.value.Value2D),g=function(){function t(){this.data=null}a(t,"laya.filters.FilterAction");var e=t.prototype;return i.imps(e,{"laya.filters.IFilterAction":!0}),e.apply=function(t){return null},t}(),y=function(){function t(){}return a(t,"laya.filters.WebGLFilter"),t.enable=function(){t.isInit||(t.isInit=!0,h.isWebGL&&(_.createFilterAction=function(t){var e;switch(t){case 32:e=new l;break;case 16:e=new p;break;case 8:e=new w}return e}))},t.isInit=!1,t.__init$=function(){_.createFilterAction=function(t){var e;switch(t){case 16:case 8:e=new g;break;case 32:e=new s}return e}},t}(),p=(function(t){function e(t){this.strength=NaN,this.strength_sig2_2sig2_gauss1=[],e.__super.call(this),void 0===t&&(t=4),h.isWebGL&&y.enable(),this.strength=t,this._action=_.createFilterAction(16),this._action.data=this}a(e,"laya.filters.BlurFilter",o);var i=e.prototype;i.callNative=function(t){t.conchModel&&t.conchModel.blurFilter&&t.conchModel.blurFilter(this.strength)},r(0,i,"action",function(){return this._action}),r(0,i,"type",function(){return 16})}(),function(t){function e(t,i,a,r){this._color=null,e.__super.call(this),this._elements=new Float32Array(9),void 0===i&&(i=4),void 0===a&&(a=6),void 0===r&&(r=6),h.isWebGL&&y.enable(),this._color=new n(t),this.blur=Math.min(i,20),this.offX=a,this.offY=r,this._action=_.createFilterAction(8),this._action.data=this}a(e,"laya.filters.GlowFilter",o);var i=e.prototype;i.getColor=function(){return this._color._color},i.callNative=function(t){t.conchModel&&t.conchModel.glowFilter&&t.conchModel.glowFilter(this._color.strColor,this._elements[4],this._elements[5],this._elements[6])},r(0,i,"type",function(){return 8}),r(0,i,"action",function(){return this._action}),r(0,i,"offY",function(){return this._elements[6]},function(t){this._elements[6]=t}),r(0,i,"offX",function(){return this._elements[5]},function(t){this._elements[5]=t}),r(0,i,"blur",function(){return this._elements[4]},function(t){this._elements[4]=t})}(),function(t){function e(){this.data=null,e.__super.call(this)}a(e,"laya.filters.webgl.BlurFilterActionGL",u);var i=e.prototype;return i.setValueMix=function(t){t.defines.add(this.data.type)},i.apply3d=function(t,e,i,a,r){var n=t.getValue("bounds"),s=d.create(1,0);s.setFilters([this.data]);c.EMPTY.identity(),i.ctx.drawTarget(t,0,0,n.width,n.height,c.EMPTY,"src",s),s.setFilters(null)},i.setValue=function(t){t.strength=this.data.strength;var e=this.data.strength/3,i=e*e;this.data.strength_sig2_2sig2_gauss1[0]=this.data.strength,this.data.strength_sig2_2sig2_gauss1[1]=i,this.data.strength_sig2_2sig2_gauss1[2]=2*i,this.data.strength_sig2_2sig2_gauss1[3]=1/(2*Math.PI*i),t.strength_sig2_2sig2_gauss1=this.data.strength_sig2_2sig2_gauss1},r(0,i,"typeMix",function(){return 16}),e}()),w=function(t){function e(){this.data=null,this._initKey=!1,this._textureWidth=0,this._textureHeight=0,e.__super.call(this)}a(e,"laya.filters.webgl.GlowFilterActionGL",u);var n=e.prototype;return i.imps(n,{"laya.filters.IFilterActionGL":!0}),n.setValueMix=function(t){},n.apply3d=function(t,e,i,a,r){var n=t.getValue("bounds");t.addValue("color",this.data.getColor());var s=n.width,l=n.height;this._textureWidth=s,this._textureHeight=l;var o,u=c.TEMP;return u.identity(),(o=d.create(1,0)).setFilters([this.data]),i.ctx.drawTarget(t,0,0,this._textureWidth,this._textureHeight,u,"src",o,null),o=d.create(1,0),i.ctx.drawTarget(t,0,0,this._textureWidth,this._textureHeight,u,"src",o),null},n.setSpriteWH=function(t){this._textureWidth=t.width,this._textureHeight=t.height},n.setValue=function(t){t.u_offsetX=this.data.offX,t.u_offsetY=-this.data.offY,t.u_strength=1,t.u_blurX=this.data.blur,t.u_blurY=this.data.blur,t.u_textW=this._textureWidth,t.u_textH=this._textureHeight,t.u_color=this.data.getColor()},r(0,n,"typeMix",function(){return 8}),e.tmpTarget=function(t,e,i,a,r){var n=t.getValue("bounds");t.getValue("out").end();var s=f.create(n.width,n.height);s.start();var l=t.getValue("color");l&&s.clear(l[0],l[1],l[2],0),t.addValue("tmpTarget",s)},e.startOut=function(t,e,i,a,r){t.getValue("tmpTarget").end();var n=t.getValue("out");n.start();var s=t.getValue("color");s&&n.clear(s[0],s[1],s[2],0)},e.recycleTarget=function(t,e,i,a,r){t.getValue("src");t.getValue("tmpTarget").recycle()},e}();i.__init([y])}(window,document,Laya),"function"==typeof define&&define.amd&&define("laya.core",["require","exports"],function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});for(var i in Laya){var a=Laya[i];a&&a.__isclass&&(e[i]=a)}});
--------------------------------------------------------------------------------
/bin/libs/matter-RenderLaya.js:
--------------------------------------------------------------------------------
1 | var Browser = laya.utils.Browser;
2 |
3 | var Composite = Matter.Composite;
4 | var Events = Matter.Events;
5 | var Bounds = Matter.Bounds;
6 | var Common = Matter.Common;
7 | var Vertices = Matter.Vertices;
8 | var Vector = Matter.Vector;
9 | var Sleeping = Matter.Sleeping;
10 | var Axes = Matter.Axes;
11 | var Body = Matter.Body;
12 | var SAT = Matter.SAT;
13 | var Contact = Matter.Contact;
14 | var Pair = Matter.Pair;
15 | var Detector = Matter.Detector;
16 | var Grid = Matter.Grid;
17 |
18 | var LayaRender = {};
19 |
20 | (function()
21 | {
22 | var graphics,
23 | spriteCon,
24 | graphicsCon;
25 |
26 | LayaRender.create = function(options)
27 | {
28 | var defaults = {
29 | controller: LayaRender,
30 | element: null,
31 | canvas: null,
32 | mouse: null,
33 | options:
34 | {
35 | width: 800,
36 | height: 600,
37 | pixelRatio: 1,
38 | background: '#fafafa',
39 | wireframeBackground: '#222',
40 | hasBounds: !!options.bounds,
41 | enabled: true,
42 | wireframes: true,
43 | showSleeping: true,
44 | showDebug: false,
45 | showBroadphase: false,
46 | showBounds: false,
47 | showVelocity: false,
48 | showCollisions: false,
49 | showSeparations: false,
50 | showAxes: false,
51 | showPositions: false,
52 | showAngleIndicator: false,
53 | showIds: false,
54 | showShadows: false,
55 | showVertexNumbers: false,
56 | showConvexHulls: false,
57 | showInternalEdges: false,
58 | showMousePosition: false
59 | }
60 | };
61 |
62 | var render = Common.extend(defaults, options);
63 |
64 | render.canvas = laya.renders.Render.canvas;
65 | render.context = laya.renders.Render.context.ctx;
66 |
67 | render.textures = {};
68 |
69 | render.bounds = render.bounds ||
70 | {
71 | min:
72 | {
73 | x: 0,
74 | y: 0
75 | },
76 | max:
77 | {
78 | x: Laya.stage.width,
79 | y: Laya.stage.height
80 | }
81 | };
82 |
83 | createContainer(render);
84 | setBackground(render);
85 | setPixelRatio();
86 |
87 | return render;
88 | };
89 |
90 | function createContainer(render)
91 | {
92 | var con = render.container;
93 |
94 | spriteCon = new Laya.Sprite();
95 | graphicsCon = new Laya.Sprite();
96 |
97 | render.spriteContainer = spriteCon;
98 | render.graphicsContainer = graphicsCon;
99 |
100 | con.addChild(spriteCon);
101 | con.addChild(graphicsCon);
102 |
103 | graphics = graphicsCon.graphics;
104 | }
105 |
106 | // 设置背景
107 | function setBackground(render)
108 | {
109 | var bg = render.options.background;
110 | // 纯色背景
111 | if (bg.length == 7 && bg[0] == '#')
112 | {
113 | spriteCon.graphics.drawRect(
114 | 0, 0,
115 | render.options.width, render.options.height,
116 | bg);
117 | }
118 | // 图片背景
119 | else
120 | {
121 | spriteCon.loadImage(bg);
122 | }
123 | }
124 |
125 | function setPixelRatio()
126 | {
127 | var pixelRatio;
128 | pixelRatio = 1;
129 | Laya.Render.canvas.setAttribute('data-pixel-ratio', pixelRatio);
130 | }
131 |
132 | /**
133 | * Renders the given `engine`'s `Matter.World` object.
134 | * This is the entry point for all rendering and should be called every time the scene changes.
135 | * @method world
136 | * @param {engine} engine
137 | */
138 | LayaRender.world = function(engine)
139 | {
140 | var render = engine.render,
141 | world = engine.world,
142 | options = render.options,
143 | allConstraints = Composite.allConstraints(world),
144 | bodies = Composite.allBodies(world),
145 | constraints = [],
146 | i;
147 |
148 | // handle bounds
149 | if (options.hasBounds)
150 | {
151 | var boundsWidth = render.bounds.max.x - render.bounds.min.x,
152 | boundsHeight = render.bounds.max.y - render.bounds.min.y,
153 | boundsScaleX = boundsWidth / options.width,
154 | boundsScaleY = boundsHeight / options.height;
155 |
156 | // filter out bodies that are not in view
157 | for (i = 0; i < bodies.length; i++)
158 | {
159 | var body = bodies[i];
160 | body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds);
161 | }
162 |
163 | // filter out constraints that are not in view
164 | for (i = 0; i < allConstraints.length; i++)
165 | {
166 | var constraint = allConstraints[i],
167 | bodyA = constraint.bodyA,
168 | bodyB = constraint.bodyB,
169 | pointAWorld = constraint.pointA,
170 | pointBWorld = constraint.pointB;
171 |
172 | if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA);
173 | if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB);
174 |
175 | if (!pointAWorld || !pointBWorld)
176 | continue;
177 |
178 | if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld))
179 | constraints.push(constraint);
180 | }
181 |
182 | // transform the view
183 | // context.scale(1 / boundsScaleX, 1 / boundsScaleY);
184 | // context.translate(-render.bounds.min.x, -render.bounds.min.y);
185 | }
186 | else
187 | {
188 | constraints = allConstraints;
189 | }
190 |
191 | graphics.clear();
192 | for (i = 0; i < bodies.length; i++)
193 | LayaRender.body(engine, bodies[i]);
194 |
195 | for (i = 0; i < constraints.length; i++)
196 | LayaRender.constraint(engine, constraints[i]);
197 | };
198 | LayaRender.body = function(engine, body)
199 | {
200 | var render = engine.render,
201 | bodyRender = body.render;
202 |
203 | if (!bodyRender.visible)
204 | {
205 | return;
206 | }
207 |
208 | var spInfo = bodyRender.sprite;
209 | var sp = body.sprite;
210 | if (bodyRender.sprite && bodyRender.sprite.texture)
211 | {
212 | // initialize body sprite if not existing
213 | if (!sp)
214 | {
215 | sp = body.sprite = createBodySprite(spInfo.xOffset, spInfo.yOffset);
216 | sp.loadImage(spInfo.texture);
217 | }
218 |
219 | sp.scale(spInfo.xScale, spInfo.yScale);
220 | sp.pos(body.position.x, body.position.y);
221 | sp.rotation = body.angle * 180 / Math.PI;
222 | }
223 | else
224 | {
225 | var options = render.options;
226 | // handle compound parts
227 | for (k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++)
228 | {
229 | part = body.parts[k];
230 |
231 | if (!part.render.visible)
232 | continue;
233 |
234 | var fillStyle = options.wireframes ? null : part.render.fillStyle;
235 | var lineWidth = part.render.lineWidth;
236 | var strokeStyle = part.render.strokeStyle;
237 | // part polygon
238 | if (part.circleRadius)
239 | {
240 | graphics.drawCircle(part.position.x, part.position.y, part.circleRadius, fillStyle, strokeStyle, lineWidth);
241 | }
242 | else
243 | {
244 | var path = [];
245 | path.push(part.vertices[0].x, part.vertices[0].y);
246 |
247 | for (var j = 1; j < part.vertices.length; j++)
248 | {
249 | if (!part.vertices[j - 1].isInternal || showInternalEdges)
250 | {
251 | path.push(part.vertices[j].x, part.vertices[j].y);
252 | }
253 | else
254 | {
255 | path.push(part.vertices[j].x, part.vertices[j].y);
256 | }
257 |
258 | if (part.vertices[j].isInternal && !showInternalEdges)
259 | {
260 | path.push(part.vertices[(j + 1) % part.vertices.length].x, part.vertices[(j + 1) % part.vertices.length].y);
261 | }
262 | }
263 |
264 | graphics.drawPoly(0, 0, path, fillStyle, strokeStyle, lineWidth);
265 | }
266 | }
267 | }
268 | };
269 |
270 | LayaRender.constraint = function(engine, constraint)
271 | {
272 | var sx, sy, ex, ey;
273 | if (!constraint.render.visible || !constraint.pointA || !constraint.pointB)
274 | {
275 | return;
276 | }
277 |
278 | var bodyA = constraint.bodyA,
279 | bodyB = constraint.bodyB;
280 |
281 | if (bodyA)
282 | {
283 | sx = bodyA.position.x + constraint.pointA.x;
284 | sy = bodyA.position.y + constraint.pointA.y;
285 | }
286 | else
287 | {
288 | sx = constraint.pointA.x;
289 | sy = constraint.pointA.y;
290 | }
291 |
292 | if (bodyB)
293 | {
294 | ex = bodyB.position.x + constraint.pointB.x;
295 | ey = bodyB.position.y + constraint.pointB.y;
296 | }
297 | else
298 | {
299 | ex = constraint.pointB.x;
300 | ey = constraint.pointB.y;
301 | }
302 |
303 | graphics.drawLine(
304 | sx, sy, ex, ey,
305 | constraint.render.strokeStyle,
306 | constraint.render.lineWidth);
307 | };
308 |
309 | function createBodySprite(xOffset, yOffset)
310 | {
311 | var sp = new Laya.Sprite();
312 |
313 | sp.pivot(xOffset, yOffset);
314 | sp.pos(-9999, -9999);
315 | spriteCon.addChild(sp);
316 |
317 | return sp;
318 | }
319 | })();
--------------------------------------------------------------------------------
/bin/libs/laya.filter.js:
--------------------------------------------------------------------------------
1 |
2 | (function(window,document,Laya){
3 | var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
4 |
5 | var Browser=laya.utils.Browser,Color=laya.utils.Color,ColorFilterAction=laya.filters.ColorFilterAction;
6 | var ColorFilterActionGL=laya.filters.webgl.ColorFilterActionGL,Filter=laya.filters.Filter,FilterActionGL=laya.filters.webgl.FilterActionGL;
7 | var Matrix=laya.maths.Matrix,Rectangle=laya.maths.Rectangle,Render=laya.renders.Render,RenderContext=laya.renders.RenderContext;
8 | var RenderTarget2D=laya.webgl.resource.RenderTarget2D,RunDriver=laya.utils.RunDriver,ShaderDefines2D=laya.webgl.shader.d2.ShaderDefines2D;
9 | var Sprite=laya.display.Sprite,Texture=laya.resource.Texture,Value2D=laya.webgl.shader.d2.value.Value2D;
10 | /**
11 | *默认的FILTER,什么都不做
12 | *@private
13 | */
14 | //class laya.filters.FilterAction
15 | var FilterAction=(function(){
16 | function FilterAction(){
17 | this.data=null;
18 | }
19 |
20 | __class(FilterAction,'laya.filters.FilterAction');
21 | var __proto=FilterAction.prototype;
22 | Laya.imps(__proto,{"laya.filters.IFilterAction":true})
23 | __proto.apply=function(data){
24 | return null;
25 | }
26 |
27 | return FilterAction;
28 | })()
29 |
30 |
31 | /**
32 | *@private
33 | */
34 | //class laya.filters.WebGLFilter
35 | var WebGLFilter=(function(){
36 | function WebGLFilter(){}
37 | __class(WebGLFilter,'laya.filters.WebGLFilter');
38 | WebGLFilter.enable=function(){
39 | if (WebGLFilter.isInit)return;
40 | WebGLFilter.isInit=true;
41 | if (!Render.isWebGL)return;
42 | RunDriver.createFilterAction=function (type){
43 | var action;
44 | switch (type){
45 | case /*laya.filters.Filter.COLOR*/0x20:
46 | action=new ColorFilterActionGL();
47 | break ;
48 | case /*laya.filters.Filter.BLUR*/0x10:
49 | action=new BlurFilterActionGL();
50 | break ;
51 | case /*laya.filters.Filter.GLOW*/0x08:
52 | action=new GlowFilterActionGL();
53 | break ;
54 | }
55 | return action;
56 | }
57 | }
58 |
59 | WebGLFilter.isInit=false;
60 | WebGLFilter.__init$=function(){
61 | BlurFilterActionGL;
62 | ColorFilterActionGL;
63 | GlowFilterActionGL;
64 | Render;
65 | RunDriver;{
66 | RunDriver.createFilterAction=function (type){
67 | var action;
68 | switch (type){
69 | case /*laya.filters.Filter.BLUR*/0x10:
70 | action=new FilterAction();
71 | break ;
72 | case /*laya.filters.Filter.GLOW*/0x08:
73 | action=new FilterAction();
74 | break ;
75 | case /*laya.filters.Filter.COLOR*/0x20:
76 | action=new ColorFilterAction();
77 | break ;
78 | }
79 | return action;
80 | }
81 | }
82 | }
83 |
84 | return WebGLFilter;
85 | })()
86 |
87 |
88 | /**
89 | *模糊滤镜
90 | */
91 | //class laya.filters.BlurFilter extends laya.filters.Filter
92 | var BlurFilter=(function(_super){
93 | function BlurFilter(strength){
94 | /**模糊滤镜的强度(值越大,越不清晰 */
95 | this.strength=NaN;
96 | this.strength_sig2_2sig2_gauss1=[];
97 | BlurFilter.__super.call(this);
98 | (strength===void 0)&& (strength=4);
99 | if (Render.isWebGL)WebGLFilter.enable();
100 | this.strength=strength;
101 | this._action=RunDriver.createFilterAction(0x10);
102 | this._action.data=this;
103 | }
104 |
105 | __class(BlurFilter,'laya.filters.BlurFilter',_super);
106 | var __proto=BlurFilter.prototype;
107 | /**
108 | *@private 通知微端
109 | */
110 | __proto.callNative=function(sp){
111 | sp.conchModel &&sp.conchModel.blurFilter&&sp.conchModel.blurFilter(this.strength);
112 | }
113 |
114 | /**
115 | *@private
116 | *当前滤镜对应的操作器
117 | */
118 | __getset(0,__proto,'action',function(){
119 | return this._action;
120 | });
121 |
122 | /**
123 | *@private
124 | *当前滤镜的类型
125 | */
126 | __getset(0,__proto,'type',function(){
127 | return 0x10;
128 | });
129 |
130 | return BlurFilter;
131 | })(Filter)
132 |
133 |
134 | /**
135 | *发光滤镜(也可以当成阴影滤使用)
136 | */
137 | //class laya.filters.GlowFilter extends laya.filters.Filter
138 | var GlowFilter=(function(_super){
139 | function GlowFilter(color,blur,offX,offY){
140 | /**滤镜的颜色*/
141 | this._color=null;
142 | GlowFilter.__super.call(this);
143 | this._elements=new Float32Array(9);
144 | (blur===void 0)&& (blur=4);
145 | (offX===void 0)&& (offX=6);
146 | (offY===void 0)&& (offY=6);
147 | if (Render.isWebGL){
148 | WebGLFilter.enable();
149 | }
150 | this._color=new Color(color);
151 | this.blur=Math.min(blur,20);
152 | this.offX=offX;
153 | this.offY=offY;
154 | this._action=RunDriver.createFilterAction(0x08);
155 | this._action.data=this;
156 | }
157 |
158 | __class(GlowFilter,'laya.filters.GlowFilter',_super);
159 | var __proto=GlowFilter.prototype;
160 | /**@private */
161 | __proto.getColor=function(){
162 | return this._color._color;
163 | }
164 |
165 | /**
166 | *@private 通知微端
167 | */
168 | __proto.callNative=function(sp){
169 | sp.conchModel &&sp.conchModel.glowFilter&&sp.conchModel.glowFilter(this._color.strColor,this._elements[4],this._elements[5],this._elements[6]);
170 | }
171 |
172 | /**
173 | *@private
174 | *滤镜类型
175 | */
176 | __getset(0,__proto,'type',function(){
177 | return 0x08;
178 | });
179 |
180 | /**@private */
181 | __getset(0,__proto,'action',function(){
182 | return this._action;
183 | });
184 |
185 | /**@private */
186 | /**@private */
187 | __getset(0,__proto,'offY',function(){
188 | return this._elements[6];
189 | },function(value){
190 | this._elements[6]=value;
191 | });
192 |
193 | /**@private */
194 | /**@private */
195 | __getset(0,__proto,'offX',function(){
196 | return this._elements[5];
197 | },function(value){
198 | this._elements[5]=value;
199 | });
200 |
201 | /**@private */
202 | /**@private */
203 | __getset(0,__proto,'blur',function(){
204 | return this._elements[4];
205 | },function(value){
206 | this._elements[4]=value;
207 | });
208 |
209 | return GlowFilter;
210 | })(Filter)
211 |
212 |
213 | /**
214 | *@private
215 | */
216 | //class laya.filters.webgl.BlurFilterActionGL extends laya.filters.webgl.FilterActionGL
217 | var BlurFilterActionGL=(function(_super){
218 | function BlurFilterActionGL(){
219 | this.data=null;
220 | BlurFilterActionGL.__super.call(this);
221 | }
222 |
223 | __class(BlurFilterActionGL,'laya.filters.webgl.BlurFilterActionGL',_super);
224 | var __proto=BlurFilterActionGL.prototype;
225 | __proto.setValueMix=function(shader){
226 | shader.defines.add(this.data.type);
227 | var o=shader;
228 | }
229 |
230 | __proto.apply3d=function(scope,sprite,context,x,y){
231 | var b=scope.getValue("bounds");
232 | var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
233 | shaderValue.setFilters([this.data]);
234 | var tMatrix=Matrix.EMPTY;
235 | tMatrix.identity();
236 | context.ctx.drawTarget(scope,0,0,b.width,b.height,Matrix.EMPTY,"src",shaderValue);
237 | shaderValue.setFilters(null);
238 | }
239 |
240 | __proto.setValue=function(shader){
241 | shader.strength=this.data.strength;
242 | var sigma=this.data.strength/3.0;
243 | var sigma2=sigma*sigma;
244 | this.data.strength_sig2_2sig2_gauss1[0]=this.data.strength;
245 | this.data.strength_sig2_2sig2_gauss1[1]=sigma2;
246 | this.data.strength_sig2_2sig2_gauss1[2]=2.0*sigma2;
247 | this.data.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2);
248 | shader.strength_sig2_2sig2_gauss1=this.data.strength_sig2_2sig2_gauss1;
249 | }
250 |
251 | __getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.BLUR*/0x10;});
252 | return BlurFilterActionGL;
253 | })(FilterActionGL)
254 |
255 |
256 | /**
257 | *@private
258 | */
259 | //class laya.filters.webgl.GlowFilterActionGL extends laya.filters.webgl.FilterActionGL
260 | var GlowFilterActionGL=(function(_super){
261 | function GlowFilterActionGL(){
262 | this.data=null;
263 | this._initKey=false;
264 | this._textureWidth=0;
265 | this._textureHeight=0;
266 | GlowFilterActionGL.__super.call(this);
267 | }
268 |
269 | __class(GlowFilterActionGL,'laya.filters.webgl.GlowFilterActionGL',_super);
270 | var __proto=GlowFilterActionGL.prototype;
271 | Laya.imps(__proto,{"laya.filters.IFilterActionGL":true})
272 | __proto.setValueMix=function(shader){}
273 | __proto.apply3d=function(scope,sprite,context,x,y){
274 | var b=scope.getValue("bounds");
275 | scope.addValue("color",this.data.getColor());
276 | var w=b.width,h=b.height;
277 | this._textureWidth=w;
278 | this._textureHeight=h;
279 | var shaderValue;
280 | var mat=Matrix.TEMP;
281 | mat.identity();
282 | shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
283 | shaderValue.setFilters([this.data]);
284 | context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue,null);
285 | shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0);
286 | context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue);
287 | return null;
288 | }
289 |
290 | __proto.setSpriteWH=function(sprite){
291 | this._textureWidth=sprite.width;
292 | this._textureHeight=sprite.height;
293 | }
294 |
295 | __proto.setValue=function(shader){
296 | shader.u_offsetX=this.data.offX;
297 | shader.u_offsetY=-this.data.offY;
298 | shader.u_strength=1.0;
299 | shader.u_blurX=this.data.blur;
300 | shader.u_blurY=this.data.blur;
301 | shader.u_textW=this._textureWidth;
302 | shader.u_textH=this._textureHeight;
303 | shader.u_color=this.data.getColor();
304 | }
305 |
306 | __getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.GLOW*/0x08;});
307 | GlowFilterActionGL.tmpTarget=function(scope,sprite,context,x,y){
308 | var b=scope.getValue("bounds");
309 | var out=scope.getValue("out");
310 | out.end();
311 | var tmpTarget=RenderTarget2D.create(b.width,b.height);
312 | tmpTarget.start();
313 | var color=scope.getValue("color");
314 | if (color){
315 | tmpTarget.clear(color[0],color[1],color[2],0);
316 | }
317 | scope.addValue("tmpTarget",tmpTarget);
318 | }
319 |
320 | GlowFilterActionGL.startOut=function(scope,sprite,context,x,y){
321 | var tmpTarget=scope.getValue("tmpTarget");
322 | tmpTarget.end();
323 | var out=scope.getValue("out");
324 | out.start();
325 | var color=scope.getValue("color");
326 | if (color){
327 | out.clear(color[0],color[1],color[2],0);
328 | }
329 | }
330 |
331 | GlowFilterActionGL.recycleTarget=function(scope,sprite,context,x,y){
332 | var src=scope.getValue("src");
333 | var tmpTarget=scope.getValue("tmpTarget");
334 | tmpTarget.recycle();
335 | }
336 |
337 | return GlowFilterActionGL;
338 | })(FilterActionGL)
339 |
340 |
341 | Laya.__init([WebGLFilter]);
342 | })(window,document,Laya);
343 |
344 | if (typeof define === 'function' && define.amd){
345 | define('laya.core', ['require', "exports"], function(require, exports) {
346 | 'use strict';
347 | Object.defineProperty(exports, '__esModule', { value: true });
348 | for (var i in Laya) {
349 | var o = Laya[i];
350 | o && o.__isclass && (exports[i] = o);
351 | }
352 | });
353 | }
--------------------------------------------------------------------------------
/bin/libs/LayaRender.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Matter.js 渲染器在 LayaAir 的实现。
3 | */
4 | (function()
5 | {
6 | var LayaRender = {};
7 |
8 | var Common = Matter.Common;
9 | var Composite = Matter.Composite;
10 | var Bounds = Matter.Bounds;
11 | var Events = Matter.Events;
12 | var Grid = Matter.Grid;
13 | var Vector = Matter.Vector;
14 |
15 | /**
16 | * 创建新的渲染器。
17 | * @param {object} options 所有属性都有默认值,options中的属性会覆盖默认属性。
18 | * @return {render} 返回创建的旋绕器
19 | */
20 | LayaRender.create = function(options)
21 | {
22 | var defaults = {
23 | controller: LayaRender,
24 | engine: null,
25 | element: null,
26 | canvas: null,
27 | mouse: null,
28 | frameRequestId: null,
29 | options:
30 | {
31 | width: 800,
32 | height: 600,
33 | pixelRatio: 1,
34 | background: '#fafafa',
35 | wireframeBackground: '#222222',
36 | hasBounds: !!options.bounds,
37 | enabled: true,
38 | wireframes: true,
39 | showSleeping: true,
40 | showDebug: false,
41 | showBroadphase: false,
42 | showBounds: false,
43 | showVelocity: false,
44 | showCollisions: false,
45 | showSeparations: false,
46 | showAxes: false,
47 | showPositions: false,
48 | showAngleIndicator: false,
49 | showIds: false,
50 | showShadows: false,
51 | showVertexNumbers: false,
52 | showConvexHulls: false,
53 | showInternalEdges: false,
54 | showMousePosition: false
55 | }
56 | };
57 | var render = Common.extend(defaults, options);
58 | render.mouse = options.mouse;
59 | render.engine = options.engine;
60 | // 如果用户没有指定contaienr,默认使用stage
61 | render.container = render.container || Laya.stage;
62 | render.bounds = render.bounds ||
63 | {
64 | min:
65 | {
66 | x: 0,
67 | y: 0
68 | },
69 | max:
70 | {
71 | x: render.width,
72 | y: render.height
73 | }
74 | };
75 |
76 | return render;
77 | }
78 |
79 | /**
80 | * 运行渲染器。
81 | * @param {render} render 渲染的目标是LayaRender.create()返回的对象
82 | * @return {void}
83 | */
84 | LayaRender.run = function(render)
85 | {
86 | Laya.timer.frameLoop(1, this, LayaRender.world, [render]);
87 | Events.on(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite);
88 | };
89 |
90 | /**
91 | * 停止渲染器。
92 | * @param {render} LayaRender.create()返回的对象
93 | * @return {void}
94 | */
95 | LayaRender.stop = function(render)
96 | {
97 | Laya.timer.clear(this, LayaRender.world);
98 | Events.off(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite);
99 | }
100 |
101 | LayaRender.onRemoveSprite = function(args)
102 | {
103 | var sprite = args.object.layaSprite;
104 | if (sprite && sprite.parent)
105 | sprite.parent.removeChild(sprite);
106 | }
107 |
108 | /**
109 | * 渲染给定的 engine 的 Matter.World 对象。
110 | * 这是渲染的入口,每次场景改变时都应该被调用。
111 | * @param {render} render
112 | * @return {void}
113 | */
114 | LayaRender.world = function(render)
115 | {
116 | var engine = render.engine,
117 | world = engine.world,
118 | renderer = render.renderer,
119 | container = render.container,
120 | options = render.options,
121 | bodies = Composite.allBodies(world),
122 | allConstraints = Composite.allConstraints(world),
123 | constraints = [],
124 | i;
125 |
126 | if (options.wireframes)
127 | {
128 | LayaRender.setBackground(render, options.wireframeBackground);
129 | }
130 | else
131 | {
132 | LayaRender.setBackground(render, options.background);
133 | }
134 |
135 | // 处理 bounds
136 | var boundsWidth = render.bounds.max.x - render.bounds.min.x,
137 | boundsHeight = render.bounds.max.y - render.bounds.min.y,
138 | boundsScaleX = boundsWidth / render.options.width,
139 | boundsScaleY = boundsHeight / render.options.height;
140 |
141 | if (options.hasBounds)
142 | {
143 | // 隐藏不在视口内的bodies
144 | for (i = 0; i < bodies.length; i++)
145 | {
146 | var body = bodies[i];
147 | body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds);
148 | }
149 |
150 | // 过滤掉不在视口内的 constraints
151 | for (i = 0; i < allConstraints.length; i++)
152 | {
153 | var constraint = allConstraints[i],
154 | bodyA = constraint.bodyA,
155 | bodyB = constraint.bodyB,
156 | pointAWorld = constraint.pointA,
157 | pointBWorld = constraint.pointB;
158 |
159 | if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA);
160 | if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB);
161 |
162 | if (!pointAWorld || !pointBWorld)
163 | continue;
164 |
165 | if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld))
166 | constraints.push(constraint);
167 | }
168 |
169 | // 改变视口
170 | container.scale(1 / boundsScaleX, 1 / boundsScaleY);
171 | container.pos(-render.bounds.min.x * (1 / boundsScaleX), -render.bounds.min.y * (1 / boundsScaleY));
172 | }
173 | else
174 | {
175 | constraints = allConstraints;
176 | }
177 |
178 | for (i = 0; i < bodies.length; i++)
179 | LayaRender.body(render, bodies[i]);
180 |
181 | for (i = 0; i < constraints.length; i++)
182 | LayaRender.constraint(render, constraints[i]);
183 | };
184 |
185 | /**
186 | * 设置背景色或者背景图片。
187 | * @param {render} render
188 | * @param {string} background 16进制颜色字符串或者图片路径
189 | */
190 | LayaRender.setBackground = function(render, background)
191 | {
192 | if (render.currentBackground !== background)
193 | {
194 | var isColor = background.indexOf && background.indexOf('#') !== -1;
195 |
196 | render.container.graphics.clear();
197 |
198 | if (isColor)
199 | {
200 | // 使用纯色背景
201 | render.container.bgColor = background;
202 | }
203 | else
204 | {
205 | render.container.loadImage(background);
206 | // 使用背景图片时把背景色设置为白色
207 | render.container.bgColor = "#FFFFFF";
208 | }
209 |
210 | render.currentBackground = background;
211 | }
212 | }
213 |
214 | /**
215 | * 渲染 body
216 | * @param {render} render
217 | * @param {body} body
218 | * @return {void}
219 | */
220 | LayaRender.body = function(render, body)
221 | {
222 | var engine = render.engine,
223 | bodyRender = body.render;
224 |
225 | if (!bodyRender.visible)
226 | return;
227 |
228 | // 有纹理的body
229 | if (bodyRender.sprite && bodyRender.sprite.texture)
230 | {
231 | var spriteId = 'b-' + body.id,
232 | sprite = body.layaSprite,
233 | container = render.container;
234 |
235 | // 如果sprite不存在,则初始化一个
236 | if (!sprite)
237 | sprite = body.layaSprite = _createBodySprite(render, body);
238 |
239 | // 如果sprite未在显示列表,则添加至显示列表
240 | if (!container.contains(sprite))
241 | container.addChild(sprite);
242 |
243 | // 更新sprite位置
244 | sprite.x = body.position.x;
245 | sprite.y = body.position.y;
246 | sprite.rotation = body.angle * 180 / Math.PI;
247 | sprite.scaleX = bodyRender.sprite.xScale || 1;
248 | sprite.scaleY = bodyRender.sprite.yScale || 1;
249 | }
250 | else // 没有纹理的body
251 | {
252 | var primitiveId = 'b-' + body.id,
253 | sprite = body.layaSprite,
254 | container = render.container;
255 |
256 | // 如果sprite不存在,则初始化一个
257 | if (!sprite)
258 | {
259 | sprite = body.layaSprite = _createBodyPrimitive(render, body);
260 | sprite.initialAngle = body.angle;
261 | }
262 |
263 | // 如果sprite未在显示列表,则添加至显示列表
264 | if (!container.contains(sprite))
265 | container.addChild(sprite);
266 | // 更新sprite位置
267 | sprite.x = body.position.x;
268 | sprite.y = body.position.y;
269 | sprite.rotation = (body.angle - sprite.initialAngle) * 180 / Math.PI;
270 | }
271 | };
272 |
273 | /**
274 | * 创建使用纹理的Sprite对象。
275 | * @param {render} render
276 | * @param {body} body
277 | * @return {void}
278 | */
279 | var _createBodySprite = function(render, body)
280 | {
281 | var bodyRender = body.render,
282 | texturePath = bodyRender.sprite.texture,
283 | sprite = new Laya.Sprite();
284 |
285 | sprite.loadImage(texturePath);
286 | sprite.pivotX = body.render.sprite.xOffset;
287 | sprite.pivotY = body.render.sprite.yOffset;
288 |
289 | return sprite;
290 | };
291 |
292 | /**
293 | * 创建使用矢量绘图的Sprite对象。
294 | * @param {render} render
295 | * @param {body} body
296 | * @return {void}
297 | */
298 | var _createBodyPrimitive = function(render, body)
299 | {
300 | var bodyRender = body.render,
301 | options = render.options,
302 | sprite = new Laya.Sprite(),
303 | fillStyle, strokeStyle, lineWidth,
304 | part, points = [];
305 |
306 | var primitive = sprite.graphics;
307 | primitive.clear();
308 |
309 | // 处理 compound parts
310 | for (var k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++)
311 | {
312 | part = body.parts[k];
313 |
314 | if (!options.wireframes)
315 | {
316 | fillStyle = bodyRender.fillStyle;
317 | strokeStyle = bodyRender.strokeStyle;
318 | lineWidth = bodyRender.lineWidth;
319 | }
320 | else
321 | {
322 | fillStyle = null;
323 | strokeStyle = '#bbbbbb';
324 | lineWidth = 1;
325 | }
326 |
327 | points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y);
328 |
329 | for (var j = 1; j < part.vertices.length; j++)
330 | {
331 | points.push(part.vertices[j].x - body.position.x, part.vertices[j].y - body.position.y);
332 | }
333 |
334 | points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y);
335 |
336 | primitive.drawPoly(0, 0, points, fillStyle, strokeStyle, lineWidth);
337 |
338 | // 角度指示器
339 | if (options.showAngleIndicator || options.showAxes)
340 | {
341 | lineWidth = 1;
342 | if (options.wireframes)
343 | {
344 | strokeStyle = '#CD5C5C';
345 | }
346 | else
347 | {
348 | strokeStyle = bodyRender.strokeStyle;
349 | }
350 |
351 | primitive.drawLine(part.position.x - body.position.x, part.position.y - body.position.y,
352 | ((part.vertices[0].x + part.vertices[part.vertices.length - 1].x) / 2 - body.position.x),
353 | ((part.vertices[0].y + part.vertices[part.vertices.length - 1].y) / 2 - body.position.y));
354 | }
355 | }
356 |
357 | return sprite;
358 | };
359 |
360 | /**
361 | * 绘制 constraint。
362 | * @param {render} render
363 | * @param {constraint} constraint
364 | * @return {void}
365 | */
366 | LayaRender.constraint = function(render, constraint)
367 | {
368 | var engine = render.engine,
369 | bodyA = constraint.bodyA,
370 | bodyB = constraint.bodyB,
371 | pointA = constraint.pointA,
372 | pointB = constraint.pointB,
373 | container = render.container,
374 | constraintRender = constraint.render,
375 | primitiveId = 'c-' + constraint.id,
376 | sprite = constraint.layaSprite;
377 |
378 | // 如果sprite不存在,则初始化一个
379 | if (!sprite)
380 | sprite = constraint.layaSprite = new Laya.Sprite();
381 |
382 | var primitive = sprite.graphics;
383 |
384 | // constraint 没有两个终点时不渲染
385 | if (!constraintRender.visible || !constraint.pointA || !constraint.pointB)
386 | {
387 | primitive.clear();
388 | return;
389 | }
390 |
391 | // 如果sprite未在显示列表,则添加至显示列表
392 | if (!container.contains(sprite))
393 | container.addChild(sprite);
394 |
395 | // 渲染 constraint
396 | primitive.clear();
397 |
398 | var fromX, fromY, toX, toY;
399 | if (bodyA)
400 | {
401 | fromX = bodyA.position.x + pointA.x;
402 | fromY = bodyA.position.y + pointA.y;
403 | }
404 | else
405 | {
406 | fromX = pointA.x;
407 | fromY = pointA.y;
408 | }
409 |
410 | if (bodyB)
411 | {
412 | toX = bodyB.position.x + pointB.x;
413 | toY = bodyB.position.y + pointB.y;
414 | }
415 | else
416 | {
417 | toX = pointB.x;
418 | toY = pointB.y;
419 | }
420 |
421 | primitive.drawLine(fromX, fromY, toX, toY, constraintRender.strokeStyle, constraintRender.lineWidth);
422 | };
423 |
424 | window.LayaRender = LayaRender;
425 | })();
--------------------------------------------------------------------------------
/bin/libs/min/laya.html.min.js:
--------------------------------------------------------------------------------
1 | !function(window,document,Laya){var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec,Browser=laya.utils.Browser,CSSStyle=laya.display.css.CSSStyle,ClassUtils=laya.utils.ClassUtils,Event=laya.events.Event,HTMLChar=laya.utils.HTMLChar,Loader=laya.net.Loader,Node=laya.display.Node,Rectangle=laya.maths.Rectangle,Render=laya.renders.Render,RenderContext=laya.renders.RenderContext,RenderSprite=laya.renders.RenderSprite,Sprite=laya.display.Sprite,Stat=laya.utils.Stat,Text=laya.display.Text,Texture=laya.resource.Texture,URL=laya.net.URL,Utils=laya.utils.Utils,HTMLParse=function(){function t(){}return __class(t,"laya.html.utils.HTMLParse"),t.parse=function(e,i,n){i=(i="