├── .laya └── launch.json ├── README.md ├── bin ├── index.html ├── libs │ ├── LayaRender.js │ ├── bytebuffer.js │ ├── domparserinone.js │ ├── laya.ani.js │ ├── laya.bdmini.js │ ├── laya.core.js │ ├── laya.d3.js │ ├── laya.d3Plugin.js │ ├── laya.debugtool.js │ ├── laya.device.js │ ├── laya.filter.js │ ├── laya.html.js │ ├── laya.particle.js │ ├── laya.pathfinding.js │ ├── laya.tiledmap.js │ ├── laya.ui.js │ ├── laya.webgl.js │ ├── laya.wxmini.js │ ├── matter-RenderLaya.js │ ├── matter.js │ ├── min │ │ ├── laya.ani.min.js │ │ ├── laya.bdmini.min.js │ │ ├── laya.core.min.js │ │ ├── laya.d3.min.js │ │ ├── laya.d3Plugin.min.js │ │ ├── laya.debugtool.min.js │ │ ├── laya.device.min.js │ │ ├── laya.filter.min.js │ │ ├── laya.html.min.js │ │ ├── laya.particle.min.js │ │ ├── laya.pathfinding.min.js │ │ ├── laya.tiledmap.min.js │ │ ├── laya.ui.min.js │ │ ├── laya.webgl.min.js │ │ └── laya.wxmini.min.js │ ├── protobuf.js │ └── worker.js ├── res │ └── atlas │ │ ├── .rec │ │ ├── comp.atlas │ │ └── comp.png └── unpack.json ├── colony.laya ├── jsconfig.json ├── laya ├── .laya ├── assets │ └── comp │ │ ├── bg.png │ │ ├── blank.png │ │ ├── btn_close.png │ │ ├── button.png │ │ ├── checkbox.png │ │ ├── clip_num.png │ │ ├── clip_selectBox.png │ │ ├── clip_tree_arrow.png │ │ ├── clip_tree_folder.png │ │ ├── combobox.png │ │ ├── hscroll$bar.png │ │ ├── hscroll$down.png │ │ ├── hscroll$up.png │ │ ├── hscroll.png │ │ ├── hslider$bar.png │ │ ├── hslider.png │ │ ├── html.png │ │ ├── image.png │ │ ├── label.png │ │ ├── linkbutton.png │ │ ├── progress$bar.png │ │ ├── progress.png │ │ ├── radio.png │ │ ├── radiogroup.png │ │ ├── tab.png │ │ ├── textarea.png │ │ ├── textinput.png │ │ ├── vscroll$bar.png │ │ ├── vscroll$down.png │ │ ├── vscroll$up.png │ │ ├── vscroll.png │ │ ├── vslider$bar.png │ │ └── vslider.png └── pages │ └── MainView.ui ├── libs └── LayaAir.d.ts └── src ├── CRC.js ├── Circle.js ├── GameMain.js ├── MainView.js ├── SteeredVehicle.js ├── Vector2D.js ├── Vehicle.js └── ui └── layaUI.max.all.js /.laya/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "layaAir", 6 | "type": "chrome", 7 | "request": "launch", 8 | "file": "${workspaceRoot}/bin/index.html", 9 | "runtimeExecutable": "${execPath}", 10 | "useBuildInServer": true, 11 | "sourceMaps": true, 12 | "webRoot": "${workspaceRoot}", 13 | "port": 9222, 14 | "fixedPort":false 15 | }, 16 | { 17 | "name": "chrome调试", 18 | "type": "chrome", 19 | "request": "launch", 20 | "file": "${workspaceRoot}/bin/index.html", 21 | // "换成自己的谷歌安装路径,": 比如 22 | //window 默认安装路径为: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" 23 | //mac 系统上的默认安装路径为 "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; 24 | // "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", 25 | "runtimeArgs": [ 26 | "--allow-file-access-from-files", 27 | "--allow-file-access-frome-files", 28 | " --disable-web-security" 29 | ], 30 | "sourceMaps": true, 31 | "webRoot": "${workspaceRoot}", 32 | //假如谷歌调试报userDataDir不可用,请把谷歌安装路径取得管理员权限,或者更换${tmpdir}为其他可以读写的文件夹,也可以删除。 33 | "userDataDir": "${workspaceRoot}/.laya/chrome", 34 | "fixedPort":false 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # layaai 2 | 基于LayaboxJS版的ai跟踪,集群跟随以及散漫移动 3 | -------------------------------------------------------------------------------- /bin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 |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/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/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/min/laya.bdmini.min.js:
--------------------------------------------------------------------------------
1 | !function(t,i,a){a.un,a.uns;var e=a.static,r=a.class,o=a.getset,c=(a.__newvec,laya.utils.Browser),n=(laya.events.Event,laya.events.EventDispatcher),d=laya.resource.HTMLImage,f=laya.utils.Handler,l=laya.display.Input,h=laya.net.Loader,s=laya.net.LocalStorage,p=(laya.maths.Matrix,laya.wx.mini.MiniAdpter),u=laya.renders.Render,v=laya.utils.RunDriver,m=laya.media.SoundChannel,g=laya.media.SoundManager,_=laya.net.URL,y=laya.utils.Utils,w=function(){function u(){}return r(u,"laya.bd.mini.BMiniAdapter"),u.getJson=function(i){return JSON.parse(i)},u.init=function(i,e){if(void 0===i&&(i=!1),void 0===e&&(e=!1),!(u._inited||(u._inited=!0,(u.window=t).navigator.userAgent.indexOf("SwanGame")<0))){u.isZiYu=e,u.isPosMsgYu=i,u.EnvConfig={};try{laya.webgl.resource.WebGLCanvas.premulAlpha=!0}catch(i){}u.isZiYu||(C.setNativeFileDir("/layaairGame"),C.existDir(C.fileNativeDir,f.create(u,u.onMkdirCallBack))),u.systemInfo=swan.getSystemInfoSync(),u.window.focus=function(){},a._getUrlPath=function(){},u.window.logtime=function(i){},u.window.alertTimeLog=function(i){},u.window.resetShareInfo=function(){},u.window.CanvasRenderingContext2D=function(){},u.window.CanvasRenderingContext2D.prototype=u.window.swan.createCanvas().getContext("2d").__proto__,u.window.document.body.appendChild=function(){},u.EnvConfig.pixelRatioInt=0,v.getPixelRatio=u.pixelRatio,u._preCreateElement=c.createElement,c.createElement=u.createElement,v.createShaderCondition=u.createShaderCondition,y.parseXMLFromString=u.parseXMLFromString,l._createInputElement=x._createInputElement,u.EnvConfig.load=h.prototype.load,h.prototype.load=S.prototype.load,h.prototype._loadImage=F.prototype._loadImage,L.__init__(),s._baseClass=L}},u.getUrlEncode=function(i,e){return-1!=i.indexOf(".fnt")?"utf8":"arraybuffer"==e?"":"ascii"},u.downLoadFile=function(i,e,n,t){void 0===e&&(e=""),void 0===t&&(t="ascii"),C.getFileInfo(i)?null!=n&&n.runWith([0]):C.downLoadFile(i,e,n,t)},u.remove=function(i,e){C.deleteFile("",i,e,"",0)},u.removeAll=function(){C.deleteAll()},u.hasNativeFile=function(i){return C.isLocalNativeFile(i)},u.getFileInfo=function(i){return C.getFileInfo(i)},u.getFileList=function(){return C.filesListObj},u.exitMiniProgram=function(){u.window.wx.exitMiniProgram()},u.onMkdirCallBack=function(i,e){i||(C.filesListObj=JSON.parse(e.data))},u.pixelRatio=function(){if(!u.EnvConfig.pixelRatioInt)try{return u.EnvConfig.pixelRatioInt=u.systemInfo.pixelRatio,u.systemInfo.pixelRatio}catch(i){}return u.EnvConfig.pixelRatioInt},u.createElement=function(i){var e;if("canvas"==i)return 1==u.idx?u.isZiYu?(e=sharedCanvas).style={}:(e=t.canvas).style={}:(e=t.swan.createCanvas()).style={},u.idx++,e;if("textarea"==i||"input"==i)return u.onCreateInput(i);if("div"!=i)return u._preCreateElement(i);var n=u._preCreateElement(i);return n.contains=function(i){return null},n.removeChild=function(i){},n},u.onCreateInput=function(i){var e=u._preCreateElement(i);return e.focus=x.wxinputFocus,e.blur=x.wxinputblur,e.style={},e.value=0,e.parentElement={},e.placeholder={},e.type={},e.setColor=function(i){},e.setType=function(i){},e.setFontFace=function(i){},e.addEventListener=function(i){},e.contains=function(i){return null},e.removeChild=function(i){},e},u.createShaderCondition=function(i){var e=this;return function(){return e[i.replace("this.","")]}},u.sendAtlasToOpenDataContext=function(i){if(!p.isZiYu){var e=h.getRes(_.formatURL(i));if(!e)throw"传递的url没有获取到对应的图集数据信息,请确保图集已经过!";e.meta.image.split(",");if(e.meta&&e.meta.image)for(var n=e.meta.image.split(","),t=0<=i.indexOf("/")?"/":"\\",o=i.lastIndexOf(t),a=0<=o?i.substr(0,o+1):"",r=0,l=n.length;r