├── README.md
├── main
├── .laya
│ ├── launch.json
│ ├── pubset.json
│ └── tasks.json
├── bin
│ ├── index.html
│ ├── libs
│ │ ├── LayaRender.js
│ │ ├── bytebuffer.js
│ │ ├── domparserinone.js
│ │ ├── laya.ani.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.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
│ ├── unpack.json
│ └── version.json
├── copy.bat
├── 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
│ │ └── rank
│ │ │ ├── first.png
│ │ │ ├── second.png
│ │ │ └── third.png
│ ├── pages
│ │ └── index.ui
│ └── styles.xml
├── libs
│ └── LayaAir.d.ts
├── rank-main.laya
├── release.bat
├── release
│ └── wxgame
│ │ ├── game.json
│ │ └── src
│ │ └── openDataContext
│ │ └── .gitkeep
├── src
│ ├── Main.ts
│ ├── ui
│ │ └── layaUI.max.all.ts
│ └── views
│ │ └── Index.ts
└── tsconfig.json
├── open-data
├── .laya
│ ├── launch.json
│ ├── pubset.json
│ └── tasks.json
├── bin
│ ├── index.html
│ ├── libs
│ │ ├── LayaRender.js
│ │ ├── bytebuffer.js
│ │ ├── domparserinone.js
│ │ ├── laya.ani.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.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
│ ├── unpack.json
│ └── version.json
├── laya
│ ├── .laya
│ ├── assets
│ │ └── rank
│ │ │ ├── first.png
│ │ │ ├── second.png
│ │ │ └── third.png
│ └── pages
│ │ └── rank.ui
├── libs
│ └── LayaAir.d.ts
├── open-data.laya
├── release_opendata.bat
├── src
│ ├── Main.ts
│ ├── ui
│ │ └── layaUI.max.all.ts
│ └── views
│ │ └── Rank.ts
└── tsconfig.json
├── view.png
└── wxgame
└── .gitkeep
/README.md:
--------------------------------------------------------------------------------
1 | # laya-wx-rank-ts
2 | Layabox(windows版本,因为没钱买苹果)开发的微信小游戏排行榜demo,使用开放数据域,开发用的Typescript语言,对应Laya类库版本 >= 1.7.19
3 |
4 | # 使用步骤(版本 <= 1.7.20)
5 | 为了同时使用版本管理和图集加载,做了一些特殊的处理,具体原理会在之后说明,这里请先照着用吧:)。
6 | 1. 下载本项目解压,可以看到三个文件夹,main为主代码,open-data为开放数据域代码,wxgame对应最后发布出来的小游戏代码(现在是空的,等这些步骤执行完,它就有东西了)。
7 | 2. 在两个Layabox窗口中分别打开main项目和open-data项目。
8 | 3. 在两个项目中都切换到编辑模式,按F12导出资源。
9 | 4. 执行main项目下的copy.bat脚本,将排行榜图集拷贝到单独的文件夹下。
10 | 5. main项目切换回代码模式,编译,然后发布项目。这里是重点,发布项目的选项,要勾选启用版本管理,后续执行脚本要选择main项目下的release.bat文件。然后就能看到与main平级的wxgame文件夹下有内容了。
11 | 6. 继续发布open-data项目,注意,发布选项,*不要*勾选版本管理,后续执行脚本选择open-data项目下的release_opendata文件。
12 | 7. 用微信web开发者工具打开wxgame文件夹,填入你自己的小游戏AppID,即可执行看到效果了。
13 |
14 | # 使用步骤(版本 >= 1.7.21)
15 | 由于laya库升级,增加了将图集直接传到子域的方法,这样就不再需要将排行榜图集独立出来了,子域也可以使用版本管理,但是官方库中还有点问题,需要改一行代码,请先照着用:)。
16 | 1. 下载本项目解压,可以看到三个文件夹,main为主代码,open-data为开放数据域代码,wxgame对应最后发布出来的小游戏代码(现在是空的,等这些步骤执行完,它就有东西了)。
17 | 2. 在两个Layabox窗口中分别打开main项目和open-data项目。
18 | 3. 在两个项目中都切换到编辑模式,按F12导出资源。
19 | 4. main项目中,打开`bin/libs/laya.wxmini.js`,找到`MiniAdpter.postInfoToContext`方法,将里面的
20 | ```
21 | fileNativeUrl=textureUrl
22 | ```
23 | 改为
24 | ```
25 | fileNativeUrl=URL.formatURL(textureUrl)
26 | ```
27 | 5. main项目切换回代码模式,编译,然后发布项目。这里是重点,发布项目的选项,要勾选启用版本管理,后续执行脚本要选择main项目下的release.bat文件。然后就能看到与main平级的wxgame文件夹下有内容了。
28 | 6. 继续发布open-data项目,注意,发布选项,*不要*勾选版本管理,后续执行脚本选择open-data项目下的release_opendata文件。
29 | 7. 用微信web开发者工具打开wxgame文件夹,填入你自己的小游戏AppID,即可执行看到效果了。
30 |
31 | 界面比较丑,请忽略
32 | 
33 |
34 | # 代码说明
35 | ### 基础实现
36 | 这个其实在社区里有不少文章说过了,但是在这里我还是重复讲一遍吧。
37 | 首先,大家都知道肯定是需要两个项目的,一个对应小游戏的主域,另一个对应小游戏的开放数据域(子域)。
38 | main文件夹,对应主域,初始化的时候用 Laya.MiniAdpter.init(true, false);
,表示是主域,并自动将加载的文本数据自动传递到子域。
39 | 而open-data对应子域,初始化时用 Laya.MiniAdpter.init(true, true);
,其实我觉得第一个参数没啥用,关键是第二个参数表示它是子域。
40 |
41 | ---
42 | 在主域中,做了以下几件事:
43 | * 设置共享画布,根据小游戏的文档,它的宽高只能在主域设置,不能在开放数据域中设置,我这里使用了如下的代码:
44 | ```
45 | let wx = Laya.Browser.window.wx;
46 | Laya.timer.once(1000, this, () => {
47 | //设置共享画布大小
48 | let sharedCanvas = wx.getOpenDataContext().canvas;
49 | sharedCanvas.width = Laya.stage.width;
50 | sharedCanvas.height = Laya.stage.height;
51 | //主域往子域透传消息
52 | wx.postMessage({type:"resizeShared",url:"",data:{width:Laya.stage.width,height:Laya.stage.height,matrix:Laya.stage._canvasTransform},isLoad:false});
53 | Laya.ResourceVersion.type = Laya.ResourceVersion.FILENAME_VERSION;
54 | Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.loadOpenDataResource));
55 | });
56 | ```
57 | * 绘制离屏画布,我在这里是把它放在了页面里,首先创建了一个Sprite组件,并设置它的var为openDataCanvas,然后,在View初始化时使用如下代码:
58 | ```
59 | let texture:Laya.Texture = new Laya.Texture(Laya.Browser.window.sharedCanvas);
60 | texture.bitmap.alwaysChange = true;//小程序使用,非常费,这个参数可以根据自己的需求适当调整,如果内容不变可以不用设置成true
61 | this.openDataCanvas.graphics.drawTexture(texture, 0, 0, texture.width, texture.height);
62 | ```
63 | * 控制离屏画布的显示和隐藏,有了上面的openDataCanvas,直接设置它的visible属性就好。然后在显示的同时,向子域发送刷新数据的命令(参考下方子域接收命令的说明),以下是部分代码:
64 | ```
65 | protected postMessage(item:Object):void
66 | {
67 | if (Laya.Browser.onMiniGame) {
68 | let wx = Laya.Browser.window.wx;
69 | let openDataContext = wx.getOpenDataContext();
70 | openDataContext.postMessage(item);
71 | }
72 | }
73 |
74 | public showRankList():void
75 | {
76 | this.rankBox.x = -480;
77 | this.openDataCanvas.x = -471;
78 | this.rankBox.visible = true;
79 | this.openDataCanvas.visible = true;
80 |
81 | Laya.Tween.to(this.rankBox, {"x": 0}, 200);
82 | Laya.Tween.to(this.openDataCanvas, {"x": 0}, 200);
83 |
84 | this.postMessage({
85 | cmd: 'showRank',
86 | });
87 | }
88 | ```
89 |
90 | ---
91 | 在子域中,主要就是一件事,接收主域的命令并处理,在这里,我把它分为系统需要的部分和自定义部分。
92 | * 系统需要部分,主要就是缓存文件数据和重设渲染canvas。
93 | * 自定义部分,主要是处理关系链数据及绘制。
94 | 示例代码如下:
95 | ```
96 | wx.onMessage(data => {
97 | let MiniFileMgr = laya.wx.mini.MiniFileMgr;
98 | //console.log(data);
99 | if (data.cmd != undefined) {
100 | if (data.cmd == 'addScore') {
101 | this.increaseWeekScore();
102 | } else if (data.cmd == 'showRank') {
103 | (this.rankView as views.Rank).showRankList();
104 | } else if (data.cmd == 'hideRank') {
105 |
106 | } else if (data.cmd == 'loadRes') {
107 | this.loadResource();
108 | }
109 | } else {
110 | if (data['isLoad'] == "filedata") {
111 | MiniFileMgr.ziyuFileData[data.url] = data.data;//文本数据
112 | } else if(data['isLoad']=="opendatacontext"){
113 | if(data.url){
114 | MiniFileMgr.ziyuFileData[data.url]=data.atlasdata;
115 | (MiniFileMgr as any).ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl;
116 | }
117 | }else if(data['isLoad']=="openJsondatacontext"){
118 | if(data.url){
119 | MiniFileMgr.ziyuFileData[data.url]=data.atlasdata;
120 | }
121 | }else if(data['isLoad']=="openJsondatacontextPic"){
122 | (MiniFileMgr as any).ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl;
123 | } else if (data['isLoad'] == "filenative") {
124 | if(data.isAdd)
125 | MiniFileMgr.filesListObj[data.url] = data.data;
126 | else
127 | delete MiniFileMgr.filesListObj[data.url];
128 | } else if (data['type'] == "resizeShared") {
129 | let tempMatrix = data.data.matrix;
130 | let matrix:Laya.Matrix = new Laya.Matrix();
131 | matrix.a = tempMatrix.a;
132 | matrix.b = tempMatrix.b;
133 | matrix.c = tempMatrix.c;
134 | matrix.d = tempMatrix.d;
135 | Laya.stage._canvasTransform = matrix;//重新设置矩阵
136 | }
137 | }
138 | });
139 | ```
140 |
141 | ### 版本管理&图集使用
142 | ##### 版本 <= 1.7.20
143 | 主域使用版本管理,子域不使用,当主域自动把atlas内容通过消息传给子域后,子域再去加载资源。
144 |
145 | 主域中,资源加载完成后,将atlas内容传给子域。因为使用了版本管理,因此系统自动的传递,子域接收到后对应的URL是不正确的,所以需要手动再传一次,如下:
146 | ```
147 | protected loadOpenDataResource():void
148 | {
149 | Laya.loader.load("rankRes/rank.atlas", Laya.Handler.create(this, this.openDataHandle), null, Laya.Loader.ATLAS);
150 | }
151 |
152 | protected openDataHandle():void
153 | {
154 | if (Laya.Browser.onMiniGame) {
155 | let wx = Laya.Browser.window.wx;
156 | let urlArr = ["rankRes/rank.atlas"];
157 | for (let i = 0; i < urlArr.length; i++) {
158 | wx.postMessage({url:urlArr[i], data:Laya.loader.getRes(urlArr[i]),isLoad:"filedata"});
159 | }
160 | wx.postMessage({cmd:"loadRes"});
161 | }
162 | this.loadResource();
163 | }
164 | ```
165 |
166 | 子域收到loadRes的消息后,才开始加载资源。
167 | 但是这里还有一个问题,在主域,加载atlas之后,再加载对应的png文件,也是带着版本号的,而在子域中,是直接加载不带版本号的png文件。
168 | 所以,我在这里多做了一个操作,将原始不带版本号的png文件拷贝了一份,放在同一个文件夹下。
169 | 我以rank.atlas和rank.png为例,将它们从res文件夹中拷贝出来,放在单独rankRes文件夹中,就是发布图集之后执行copy.bat做的事情,然后进行加载。
170 | 当然,直接将它们从bin/res/atlas文件夹拷贝到release/wxgame/res/atlas文件夹下也是可以的。
171 | 那么,我把它放在单独的文件夹中有什么好处呢?答案是,整个res文件夹,我是放在网上进行加载的,最后发布出来的微信小游戏项目中,res文件夹我是直接删除的,本地和网络加载的文件混在一起,处理起来会有些麻烦:)
172 |
173 | ##### 版本 >= 1.7.21
174 | 首先,版本管理暂时不太容易绕过,因为需要读取version.json文件的内容,而在子域里,非常不幸,没有办法使用文件系统相关的方法。
175 | 或许可以更改laya源码部分,将version.json内容传送到子域,但是这个改动可能有点大,不是一行代码的事,坐等官方更新。所以,还是先将就着不要用版本管理吧,而且实际跟使用版本管理也没有区别,因为最终加载的是带版本号的文件。
176 |
177 | 比起之前版本的进步在于,rank.atlas和rank.png,不需要放在单独的文件夹中了,从主域加载了可以直接将本地文件url传过去,需要时直接使用即可。
178 | 存在的一个问题就是,使用`MiniAdpter.sendAtlasToOpenDataContext`时,传的url还是原始的未经过版本管理解析的,这样子域会加载不到,因此需要改一行代码,变成真正存在的url。
179 |
180 | # ~~TODO~~
181 | ~~研究一下有没有什么开挂的方法,让子域需要的图集也能从网络加载,或者说,主域从网络加载了,同步到子域中。~~
182 | 从版本1.7.21开始,laya已经增加了将图集直接传到子域的方法`MiniAdpter.sendAtlasToOpenDataContext`,使用它即可,使用步骤里已经有补充,不再赘述。
183 |
--------------------------------------------------------------------------------
/main/.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 | }
--------------------------------------------------------------------------------
/main/.laya/pubset.json:
--------------------------------------------------------------------------------
1 | {"1":{"sourcePath":"E:\\laya_workspace\\laya-wx-rank-ts\\main\\bin","outPath":"E:\\laya_workspace\\laya-wx-rank-ts\\main\\release\\wxgame","pngQualityLow":"65","pngQualityHigh":"80","jpgQuality":"85","mergeJs":true,"compressPng":false,"compressJpg":false,"compressJson":false,"jsontypes":"json,atlas,ls,lh,lmat,lav","compressJs":false,"enableVersion":true,"excludeFiles":"","publishType":1,"projectType":"ts","copyOutFiles":"","copyOutPath":"","userCmd":"E:\\laya_workspace\\laya-wx-rank-ts\\main\\release.bat"},"pf":1}
--------------------------------------------------------------------------------
/main/.laya/tasks.json:
--------------------------------------------------------------------------------
1 | {"version":"0.1.0","command":"tsc","isShellCommand":true,"args":["-p",".","--outDir","bin/js"],"showOutput":"silent","problemMatcher":"$tsc"}
--------------------------------------------------------------------------------
/main/bin/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
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 | }
--------------------------------------------------------------------------------
/main/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 | }
--------------------------------------------------------------------------------
/main/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 | })();
--------------------------------------------------------------------------------
/main/bin/libs/min/laya.d3Plugin.min.js:
--------------------------------------------------------------------------------
1 | !function(t,i,e){e.un,e.uns,e.static;var n=e.class,r=e.getset,a=(e.__newvec,laya.d3.component.Component3D);laya.d3.core.ComponentNode,laya.d3.core.MeshTerrainSprite3D,laya.d3.core.Sprite3D,function(i){function t(){this._meshTerrainSprite3D=null,this._finder=null,this._setting=null,this.grid=null,t.__super.call(this)}n(t,"laya.d3.component.PathFind",i);var e=t.prototype;e._load=function(t){if(!(t instanceof laya.d3.core.MeshTerrainSprite3D))throw new Error("PathFinding: The owner must MeshTerrainSprite3D!");i.prototype._load.call(this,t),this._meshTerrainSprite3D=t},e.findPath=function(t,i,e,n){var r=this._meshTerrainSprite3D.minX,a=this._meshTerrainSprite3D.minZ,h=this._meshTerrainSprite3D.width/this.grid.width,s=this._meshTerrainSprite3D.depth/this.grid.height,o=h/2,d=s/2,l=Math.floor((t-r)/h),f=Math.floor((i-a)/s),c=Math.floor((e-r)/h),u=Math.floor((n-a)/s),p=this.grid.width-1,_=this.grid.height-1;pPathFinding
类用于创建寻路。
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 | }
--------------------------------------------------------------------------------
/open-data/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 | }
--------------------------------------------------------------------------------
/open-data/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 | })();
--------------------------------------------------------------------------------
/open-data/bin/libs/min/laya.d3Plugin.min.js:
--------------------------------------------------------------------------------
1 | !function(t,i,e){e.un,e.uns,e.static;var n=e.class,r=e.getset,a=(e.__newvec,laya.d3.component.Component3D);laya.d3.core.ComponentNode,laya.d3.core.MeshTerrainSprite3D,laya.d3.core.Sprite3D,function(i){function t(){this._meshTerrainSprite3D=null,this._finder=null,this._setting=null,this.grid=null,t.__super.call(this)}n(t,"laya.d3.component.PathFind",i);var e=t.prototype;e._load=function(t){if(!(t instanceof laya.d3.core.MeshTerrainSprite3D))throw new Error("PathFinding: The owner must MeshTerrainSprite3D!");i.prototype._load.call(this,t),this._meshTerrainSprite3D=t},e.findPath=function(t,i,e,n){var r=this._meshTerrainSprite3D.minX,a=this._meshTerrainSprite3D.minZ,h=this._meshTerrainSprite3D.width/this.grid.width,s=this._meshTerrainSprite3D.depth/this.grid.height,o=h/2,d=s/2,l=Math.floor((t-r)/h),f=Math.floor((i-a)/s),c=Math.floor((e-r)/h),u=Math.floor((n-a)/s),p=this.grid.width-1,_=this.grid.height-1;p