查看: 9314|回复: 34

[随意闲聊] 牛了比,看见歪果仁用mv做的真3d了

[复制链接]
梦石
0
星屑
50
在线时间
139 小时
注册时间
2014-6-12
回帖
110
发表于 2016-1-22 12:50:07 来自手机 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
牛了比,看见歪果仁用mv做的真3d了视频了,没想到js3d性能这么强,虽然建模全是方框类似我的世界那种,但是贴图貌似比我的世界清晰,反正以前rpg都是平面方框,现在只是立体方框已经挺牛逼了,跟那些侠盗和巫师什么的没法比,但是我已经很满足了,坐着有国内大神插件汉化
梦石
0
星屑
50
在线时间
35 小时
注册时间
2015-5-2
回帖
19
发表于 2016-1-22 12:54:05 | 显示全部楼层
好歹吧视频地址一起发了呀= =
回复

使用道具 举报

梦石
0
星屑
90
在线时间
387 小时
注册时间
2007-7-27
回帖
4075

开拓者

发表于 2016-1-22 19:23:49 | 显示全部楼层
minecraft贴图那么糊又不是因为性能的关系……
要看js的3d搜一下three.js,和mv本身倒是没什么关系,主要是html5的canvas可以用opengl
https://stemkoski.github.io/Three.js/Metabubbles.html
随便贴一个
吸吸
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2016-1-22 19:50:48 | 显示全部楼层
threejs必要
飛空艇搭乗時 3D 化 α 版
  1. //=============================================================================
  2. // KMS_3DVehicle.js
  3. //   Last update : 2016/01/19
  4. //=============================================================================

  5. /*
  6. * This plugin is licensed under the MIT License.
  7. * [url]http://www.opensource.org/licenses/mit-license.php[/url]
  8. *
  9. * This plugin requires "three.js".
  10. * [url]http://threejs.org/[/url]
  11. *
  12. * This plugin can be used in the environment which supports WebGL.
  13. */

  14. /*:
  15. * @plugindesc
  16. * [v0.1.0α] Display 3D map when getting on the airplane.
  17. *
  18. * @author TOMY (Kamesoft)
  19. *
  20. * @param 3D mode switch
  21. * @default 0
  22. * @desc 3D モード時に ON にするスイッチの番号です。0 にするとスイッチ操作をしなくなります。
  23. *
  24. * @param Plane speed
  25. * @default 6
  26. * @desc Move speed of the airplane.
  27. *
  28. * @param Plane whirl speed
  29. * @default 0.0349
  30. * @desc Whirl speed of the airplane. Specified by the rad unit per frame.
  31. *
  32. * @param Plane tilt angle
  33. * @default 0.314
  34. * @desc The tilt angle of the whirling airplane.
  35. *
  36. * @param Accel touch area
  37. * @default 0.7
  38. * @desc The touch area judged to be go forward. 1.0 indicates the whole screen.
  39. *
  40. * @param Whirl touch area
  41. * @default 0.7
  42. * @desc The touch area judged to be whirl. 1.0 indicates harl of screen left and right.
  43. *
  44. * @param Map quality
  45. * @default 0.5
  46. * @desc Map quality in 3D mode. Processing load also becomes so heavy that it is increased.
  47. *
  48. * @param Use CDN
  49. * @default 0
  50. * @desc
  51. * Specify the source of "three.min.js" to load from CDN or local.
  52. * 0: From local (js/libs/three.min.js), 1: From CDN
  53. *
  54. * @help This plugin does not provide plugin commands.
  55. */

  56. /*:ja
  57. * @plugindesc
  58. * [v0.1.0α] 飛空艇搭乗時のマップを 3D 化します。
  59. *
  60. * @author TOMY (Kamesoft)
  61. *
  62. * @param 3D mode switch
  63. * @default 0
  64. * @desc 3D モード時に ON にするスイッチの番号です。0 にするとスイッチ操作をしなくなります。
  65. *
  66. * @param Plane speed
  67. * @default 6
  68. * @desc 飛空艇の移動速度です。
  69. *
  70. * @param Plane whirl speed
  71. * @default 0.0349
  72. * @desc 飛空艇の旋回速度です。1 フレームあたりの回転角度をラジアンです。
  73. *
  74. * @param Plane tilt angle
  75. * @default 0.314
  76. * @desc 飛空艇旋回時の画面の傾き具合です。
  77. *
  78. * @param Accel touch area
  79. * @default 0.7
  80. * @desc タッチ操作を前進と判定する範囲です。画面中央からの割合で指定し、1.0 で画面全体になります。
  81. *
  82. * @param Whirl touch area
  83. * @default 0.7
  84. * @desc タッチ操作を旋回と判定する範囲です。画面左右からの割合で指定し、1.0 で画面半分ずつになります。
  85. *
  86. * @param Map quality
  87. * @default 0.5
  88. * @desc 3D モード時のマップ画質です。値を大きくするほど高画質になりますが、処理負荷も増大します。
  89. *
  90. * @param Use CDN
  91. * @default 0
  92. * @desc
  93. * どの "three.min.js" を使用するか指定します。
  94. * 0: ローカル (js/libs/three.min.js), 1: CDN
  95. *
  96. * @help このプラグインには、プラグインコマンドはありません。
  97. */

  98. var KMS = KMS || {};

  99. (function(undefined)
  100. {

  101. if (!Graphics.hasWebGL())
  102. {
  103.     console.error("WebGL をサポートしていないため、three.js を使用できません。");
  104.     return;
  105. }

  106. KMS.imported = KMS.imported || {};
  107. KMS.imported['3DVehicle'] = true;

  108. var PluginName = 'KMS_3DVehicle';

  109. var pluginParams = PluginManager.parameters(PluginName);
  110. var Params = {};
  111. Params.in3DModeSwitchId = Number(pluginParams['3D mode switch'] || 0);
  112. Params.speed = {
  113.     plane: Number(pluginParams['Plane speed'] || 6),
  114.     planeWhirl: Number(pluginParams['Plane whirl speed'] || (Math.PI / 90))
  115. };
  116. Params.whirlTiltAngle = Number(pluginParams['Plane tilt angle'] || (Math.PI / 12));
  117. Params.touchArea = {
  118.     accel: Number(pluginParams['Accel touch area'] || 0.7),
  119.     whirl: Number(pluginParams['Whirl touch area'] || 0.7)
  120. };
  121. Params.mapQuality = Number(pluginParams['Map quality'] || 0.5);
  122. Params.useCdn = Number(pluginParams['Use CDN'] || 0);

  123. //Params._debugMode = true;

  124. // three.js のロード
  125. (function()
  126. {
  127.     var threeJsId = 'three-js-script';
  128.     if (document.getElementById(threeJsId) || typeof THREE !== 'undefined')
  129.     {
  130.         return;
  131.     }

  132.     var url = Params.useCdn ?
  133.         'https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.min.js' :
  134.         'js/libs/three.min.js';

  135.     console.info('[' + PluginName + '] Load "three.min.js" from ' + (Params.useCdn ? 'CDN' : 'local'));

  136.     var script = document.createElement('script');
  137.     script.type = 'text/javascript';
  138.     script.src = url
  139.     script.async = false;
  140.     script.onerror = PluginManager.onError.bind(PluginManager);
  141.     script._url = url;
  142.     script.id = threeJsId;
  143.     document.body.appendChild(script);
  144. })();


  145. //-----------------------------------------------------------------------------
  146. // Tilemap

  147. var _KMS_3DVehicle_Tilemap_createLayers = Tilemap.prototype._createLayers;
  148. Tilemap.prototype._createLayers = function()
  149. {
  150.     // レイヤーが重複して追加される不具合への対処
  151.     if (this._lowerLayer)
  152.     {
  153.         this.removeChild(this._lowerLayer);
  154.         this._lowerLayer = null;
  155.     }
  156.     if (this._upperLayer)
  157.     {
  158.         this.removeChild(this._upperLayer);
  159.         this._upperLayer = null;
  160.     }

  161.     _KMS_3DVehicle_Tilemap_createLayers.call(this);
  162. };


  163. //-----------------------------------------------------------------------------
  164. // Game_Temp

  165. var _KMS_3DVehicle_Game_Temp_initialize = Game_Temp.prototype.initialize;
  166. Game_Temp.prototype.initialize = function()
  167. {
  168.     _KMS_3DVehicle_Game_Temp_initialize.call(this);

  169.     this._gameScene3DObjects = {};
  170.     this._gameMap3DObjects = {};
  171. };

  172. Object.defineProperties(Game_Temp.prototype, {
  173.     // Game_Scene 用の 3D オブジェクト
  174.     gameScene3DObjects: {
  175.         get: function() { return this._gameScene3DObjects; },
  176.         set: function(value) { this._gameScene3DObjects = value; },
  177.         configurable: true
  178.     },

  179.     // Game_Map 用の 3D オブジェクト
  180.     gameMap3DObjects: {
  181.         get: function() { return this._gameMap3DObjects; },
  182.         set: function(value) { this._gameMap3DObjects = value; },
  183.         configurable: true
  184.     }
  185. });


  186. //-----------------------------------------------------------------------------
  187. // Game_Screen

  188. var _KMS_3DVehicle_Game_Screen_initialize = Game_Screen.prototype.initialize;
  189. Game_Screen.prototype.initialize = function()
  190. {
  191.     _KMS_3DVehicle_Game_Screen_initialize.call(this);
  192.     this._change3DModeDuration = 0;
  193.     this._isNext3DMode = false;
  194. };

  195. /**
  196. * 3D モードへ移行
  197. */
  198. Game_Screen.prototype.change3DMode = function(enable, caller, callback)
  199. {
  200.     var fadeSpeed = Game_Interpreter.prototype.fadeSpeed.call(null);

  201.     var obj3d = $gameTemp.gameScene3DObjects;
  202.     obj3d.change3DCaller = caller;
  203.     obj3d.change3DCallback = callback;

  204.     this._change3DModeDuration = fadeSpeed * 2 + (enable ? 20 : 0);
  205.     this._isNext3DMode = !!enable;
  206. };

  207. /**
  208. * 3D モードへ移行中
  209. */
  210. Game_Screen.prototype.isChanging3DMode = function()
  211. {
  212.     return this._change3DModeDuration > 0;
  213. };

  214. var _KMS_3DVehicle_Game_Screen_update = Game_Screen.prototype.update;
  215. Game_Screen.prototype.update = function()
  216. {
  217.     _KMS_3DVehicle_Game_Screen_update.call(this);
  218.     this.updateChange3D();
  219. };

  220. /**
  221. * 3D モード遷移処理の更新
  222. */
  223. Game_Screen.prototype.updateChange3D = function()
  224. {
  225.     if (this._change3DModeDuration <= 0)
  226.     {
  227.         return;
  228.     }

  229.     var fadeSpeed = Game_Interpreter.prototype.fadeSpeed.call(null);
  230.     switch (this._change3DModeDuration)
  231.     {
  232.         case fadeSpeed * 2:
  233.             this.startFadeOut(fadeSpeed);
  234.             break;
  235.         case fadeSpeed:
  236.             {
  237.                 $gameSwitches.setValue(
  238.                     Params.in3DModeSwitchId,
  239.                     this._isNext3DMode);

  240.                 var obj3d = $gameTemp.gameScene3DObjects;
  241.                 obj3d.change3DCallback.call(
  242.                     obj3d.change3DCaller,
  243.                     this._isNext3DMode);
  244.                 this.startFadeIn(fadeSpeed);
  245.             }
  246.             break;
  247.     };
  248.     this._change3DModeDuration--;
  249. };


  250. //-----------------------------------------------------------------------------
  251. // Game_Map

  252. var _KMS_3DVehicle_Game_Map_initialize = Game_Map.prototype.initialize;
  253. Game_Map.prototype.initialize = function()
  254. {
  255.     _KMS_3DVehicle_Game_Map_initialize.call(this);
  256.     this._3DMode = false;

  257.     var obj3d = $gameTemp.gameMap3DObjects;
  258.     obj3d.mapObject = null;
  259.     obj3d.setModeCaller = null;
  260.     obj3d.setModeCallback = null;
  261. };

  262. Game_Map.prototype.set3DMode = function(value)
  263. {
  264.     this._3DMode = !!value;

  265.     var obj3d = $gameTemp.gameMap3DObjects;
  266.     if (obj3d.setModeCaller && obj3d.setModeCallback)
  267.     {
  268.         obj3d.setModeCallback.call(obj3d.setModeCaller, this.is3DMode());
  269.     }
  270. };

  271. Game_Map.prototype.is3DMode = function()
  272. {
  273.     return this._3DMode;
  274. };

  275. Game_Map.prototype.is3DReady = function()
  276. {
  277.     return this.is3DMode();
  278. };

  279. Game_Map.prototype.create3DMap = function()
  280. {
  281.     var obj3d = $gameTemp.gameMap3DObjects;
  282.     if (obj3d.mapObject)
  283.     {
  284.         this.dispose3DMap();
  285.     }
  286.     obj3d.mapObject = new Game_3DMap();
  287. };

  288. Game_Map.prototype.dispose3DMap = function()
  289. {
  290.     var obj3d = $gameTemp.gameMap3DObjects;
  291.     obj3d.mapObject.dispose();
  292.     obj3d.mapObject = null;
  293. };

  294. Game_Map.prototype.get3DMap = function()
  295. {
  296.     return $gameTemp.gameMap3DObjects.mapObject;
  297. };

  298. Game_Map.prototype.set3DModeCallback = function(caller, callback)
  299. {
  300.     var obj3d = $gameTemp.gameMap3DObjects;
  301.     obj3d.setModeCaller = caller;
  302.     obj3d.setModeCallback = callback;
  303. };

  304. Game_Map.prototype.get3DPlayerAngle = function()
  305. {
  306.     return this.get3DMap().getPlayerAngle();
  307. };

  308. Game_Map.prototype.save3DMapInfo = function()
  309. {
  310.     var obj3d = $gameTemp.gameMap3DObjects;
  311.     obj3d.savedPosition = {};
  312.     obj3d.savedPosition.angle = this.get3DPlayerAngle();
  313. };

  314. Game_Map.prototype.restore3DMapInfo = function()
  315. {
  316.     var map3d = this.get3DMap();
  317.     var obj3d = $gameTemp.gameMap3DObjects;
  318.     if (map3d && obj3d.savedPosition)
  319.     {
  320.         map3d.setPlayerAngle(obj3d.savedPosition.angle);
  321.         obj3d.savedPosition = null;
  322.     }
  323. };


  324. //-----------------------------------------------------------------------------
  325. // Game_CharacterBase

  326. /**
  327. * スクロールを無視した画面 X 座標
  328. */
  329. Game_CharacterBase.prototype.notScrolledScreenX = function()
  330. {
  331.     var tw = $gameMap.tileWidth();
  332.     return Math.round(this._realX * tw + tw / 2);
  333. };

  334. /**
  335. * スクロールを無視した画面 Y 座標
  336. */
  337. Game_CharacterBase.prototype.notScrolledScreenY = function()
  338. {
  339.     var th = $gameMap.tileHeight();
  340.     return Math.round(this._realY * th + th - this.shiftY() - this.jumpHeight());
  341. };


  342. //-----------------------------------------------------------------------------
  343. // Game_Player

  344. var _KMS_3DVehicle_Game_Player_isMoving = Game_Player.prototype.isMoving;
  345. Game_Player.prototype.isMoving = function()
  346. {
  347.     if ($gameMap.is3DMode())
  348.     {
  349.         // 3D モード中は realX/Y が自動更新されないようにする
  350.         return false;
  351.     }

  352.     return _KMS_3DVehicle_Game_Player_isMoving.call(this);
  353. };

  354. var _KMS_3DVehicle_Game_Player_moveByInput = Game_Player.prototype.moveByInput;
  355. Game_Player.prototype.moveByInput = function()
  356. {
  357.     if ($gameMap.is3DMode())
  358.     {
  359.         $gameMap.get3DMap().updateMove();
  360.     }
  361.     else
  362.     {
  363.         _KMS_3DVehicle_Game_Player_moveByInput.call(this);
  364.     }
  365. };

  366. var _KMS_3DVehicle_Game_Player_update = Game_Player.prototype.update;
  367. Game_Player.prototype.update = function(sceneActive)
  368. {
  369.     _KMS_3DVehicle_Game_Player_update.call(this, sceneActive);

  370.     if ($gameMap.is3DMode() && this.canMove())
  371.     {
  372.         if (!this.triggerButtonActionFor3DVehicle())
  373.         {
  374.             this.triggerTouchActionFor3DVehicle();
  375.         }
  376.     }
  377. };

  378. Game_Player.prototype.triggerButtonActionFor3DVehicle = function()
  379. {
  380.     if (Input.isTriggered('ok'))
  381.     {
  382.         // OK ボタンでは降りない
  383.         if (!this.isInVehicle() && this.getOnVehicle())
  384.         {
  385.             return true;
  386.         }
  387.         this.checkEventTriggerHere([0]);
  388.         if ($gameMap.setupStartingEvent())
  389.         {
  390.             return true;
  391.         }
  392.         this.checkEventTriggerThere([0, 1, 2]);
  393.         if ($gameMap.setupStartingEvent())
  394.         {
  395.             return true;
  396.         }
  397.     }
  398.     else if (Input.isTriggered('cancel'))
  399.     {
  400.         if (this.isInVehicle() && this.getOffVehicle())
  401.         {
  402.             return true;
  403.         }
  404.     }

  405.     return false;
  406. };

  407. Game_Player.prototype.triggerTouchActionFor3DVehicle = function()
  408. {
  409.     if (TouchInput.isTriggered())
  410.     {
  411.         // シングルタッチでは降りない
  412.         if (!this.isInVehicle() && this.getOnVehicle())
  413.         {
  414.             return true;
  415.         }

  416.         // TODO: イベント起動ができるならやる
  417.     }
  418.     else if (TouchInput.isCancelled())
  419.     {
  420.         if (this.isInVehicle() && this.getOffVehicle())
  421.         {
  422.             return true;
  423.         }
  424.     }

  425.     return false;
  426. };

  427. var _KMS_3DVehicle_Game_Player_triggerButtonAction = Game_Player.prototype.triggerButtonAction;
  428. Game_Player.prototype.triggerButtonAction = function()
  429. {
  430.     if (!$gameMap.is3DMode())
  431.     {
  432.         return _KMS_3DVehicle_Game_Player_triggerButtonAction.call(this);
  433.     }

  434.     return false;
  435. };

  436. var _KMS_3DVehicle_Game_Player_triggerTouchAction = Game_Player.prototype.triggerTouchAction;
  437. Game_Player.prototype.triggerTouchAction = function()
  438. {
  439.     if (!$gameMap.is3DMode())
  440.     {
  441.         return _KMS_3DVehicle_Game_Player_triggerTouchAction.call(this);
  442.     }

  443.     return false;
  444. };


  445. //-----------------------------------------------------------------------------
  446. // Game_Vehicle

  447. Game_Vehicle.prototype.getOn = function() {
  448.     this._driving = true;
  449.     this.setWalkAnime(true);
  450.     this.setStepAnime(true);
  451.     $gameSystem.saveWalkingBgm();
  452.     this.playBgm();

  453.     if (this.isAirship())
  454.     {
  455.         $gameScreen.change3DMode(true, this, this.set3DMode);
  456.     }
  457. };

  458. Game_Vehicle.prototype.getOff = function() {
  459.     this._driving = false;
  460.     this.setWalkAnime(false);
  461.     this.setStepAnime(false);
  462.     this.resetDirection();
  463.     $gameSystem.replayWalkingBgm();

  464.     if (this.isAirship())
  465.     {
  466.         $gameScreen.change3DMode(false, this, this.set3DMode);
  467.     }
  468. };

  469. Game_Vehicle.prototype.set3DMode = function(enabled)
  470. {
  471.     $gameMap.set3DMode(enabled);
  472. };

  473. var _KMS_3DVehicle_Game_Vehicle_direction = Game_Vehicle.prototype.direction;
  474. Game_Vehicle.prototype.direction = function()
  475. {
  476.     if ($gameMap.is3DMode())
  477.     {
  478.         return 8;
  479.     }
  480.     else
  481.     {
  482.         return _KMS_3DVehicle_Game_Vehicle_direction.call(this);
  483.     }
  484. };

  485. var _KMS_3DVehicle_Game_Vehicle_screenX = Game_Vehicle.prototype.screenX;
  486. Game_Vehicle.prototype.screenX = function()
  487. {
  488.     if ($gameMap.is3DMode())
  489.     {
  490.         return Graphics.width / 2;
  491.     }
  492.     else
  493.     {
  494.         return _KMS_3DVehicle_Game_Vehicle_screenX.call(this);
  495.     }
  496. };

  497. var _KMS_3DVehicle_Game_Vehicle_screenY = Game_Vehicle.prototype.screenY;
  498. Game_Vehicle.prototype.screenY = function()
  499. {
  500.     if ($gameMap.is3DMode())
  501.     {
  502.         return Graphics.height / 2 - this._altitude;
  503.     }
  504.     else
  505.     {
  506.         var baseY = _KMS_3DVehicle_Game_Vehicle_screenY.call(this);
  507.         return baseY - this._altitude * Math.sqrt(this._altitude / 2);
  508.     }
  509. };

  510. var _KMS_3DVehicle_Game_Vehicle_shadowY = Game_Vehicle.prototype.shadowY;
  511. Game_Vehicle.prototype.shadowY = function()
  512. {
  513.     if ($gameMap.is3DMode())
  514.     {
  515.         return 0;
  516.     }
  517.     else
  518.     {
  519.         var baseY = _KMS_3DVehicle_Game_Vehicle_screenY.call(this);
  520.         return baseY + this._altitude;
  521.     }
  522. };

  523. Game_Vehicle.prototype.canMove = function()
  524. {
  525.     if (this.isAirship())
  526.     {
  527.         return this.isHighest() && $gameMap.is3DReady() && !$gameScreen.isChanging3DMode();
  528.     }
  529.     else
  530.     {
  531.         return true;
  532.     }
  533. };

  534. var _KMS_3DVehicle_Game_Vehicle_isTransparent = Game_Vehicle.prototype.isTransparent;
  535. Game_Vehicle.prototype.isTransparent = function()
  536. {
  537.     var isTransparent = _KMS_3DVehicle_Game_Vehicle_isTransparent.call(this);

  538.     if (!isTransparent && $gameMap.is3DMode())
  539.     {
  540.         isTransparent = this._type !== $gamePlayer._vehicleType;
  541.     }

  542.     return isTransparent;
  543. };


  544. //-----------------------------------------------------------------------------
  545. // Game_3DMap

  546. Game_3DMap = function()
  547. {
  548.     this.initialize.apply(this, arguments);
  549. };

  550. Game_3DMap.prototype = Object.create(Sprite.prototype);
  551. Game_3DMap.prototype.constructor = Game_3DMap;

  552. //! 最大回転角
  553. Game_3DMap.prototype.MaxRot = {
  554.     x: Math.PI / 12,
  555.     y: 0,
  556.     z: Params.whirlTiltAngle
  557. };

  558. //! 1 フレームあたりの回転角の変化量
  559. Game_3DMap.prototype.StepRot = {
  560.     x: Game_3DMap.prototype.MaxRot.x / 8,
  561.     y: Params.speed.planeWhirl,
  562.     z: Game_3DMap.prototype.MaxRot.z / 16
  563. };

  564. //! 座標の変化量
  565. Game_3DMap.prototype.StepPos = { y: 4 };

  566. //! 座標の最大値
  567. Game_3DMap.prototype.MaxPos = { y: 192 };

  568. //! 座標の最小値
  569. Game_3DMap.prototype.MinPos = { y: 96 };

  570. /**
  571. * オブジェクトの初期化
  572. */
  573. Game_3DMap.prototype.initialize = function()
  574. {
  575.     Sprite.prototype.initialize.call(this);

  576.     this.create3dScene();
  577.     this.createPlayerMesh();
  578.     this.createShadowMesh();
  579.     this.createCamera();
  580.     this.create3dRenderer();

  581.     this._stage2d = new Stage();

  582.     this._moveSpeed = 0;
  583.     this._parallaxX = 0;
  584. };

  585. /**
  586. * 3D シーンの作成
  587. */
  588. Game_3DMap.prototype.create3dScene = function()
  589. {
  590.     this._scene3d = new THREE.Scene();
  591.     this._scene3d.fog = new THREE.Fog("white", 200, 2000);
  592. };

  593. /**
  594. * プレイヤーを作成
  595. */
  596. Game_3DMap.prototype.createPlayerMesh = function()
  597. {
  598.     var material = new THREE.MeshBasicMaterial({ color: 0 });
  599.     material.transparent = true;
  600.     material.opacity = 0.5;

  601.     // 形は何でも良いので三角形
  602.     var shape = new THREE.Shape();
  603.     shape.moveTo(0, 4);
  604.     shape.lineTo(4, -2);
  605.     shape.lineTo(-4, -2);
  606.     shape.lineTo(0, 4);

  607.     var geometry = new THREE.ShapeGeometry(shape);
  608.     var player= new THREE.Mesh(geometry, material);
  609.     player.position.y = 96;
  610.     player.visible = false;


  611.     this._player = player;
  612.     this._scene3d.add(this._player);
  613. };

  614. /**
  615. * 影を作成
  616. */
  617. Game_3DMap.prototype.createShadowMesh = function()
  618. {
  619.     var shadow = new THREE.Mesh(
  620.         new THREE.CircleGeometry(10, 16),
  621.         new THREE.MeshBasicMaterial({ color: 0x101010, transparent: true, opacity: 0.35 }));
  622.     shadow.position.y = 10;
  623.     shadow.rotation.x = -Math.PI / 2;
  624.     shadow.transparent = true;
  625.     shadow.renderOrder = 1;

  626.     this._shadow = shadow;
  627.     this._scene3d.add(this._shadow);
  628. };

  629. /**
  630. * カメラを作成
  631. */
  632. Game_3DMap.prototype.createCamera = function()
  633. {
  634.     this._camera = new THREE.PerspectiveCamera(75, Graphics.width / Graphics.height, 1, 2000);
  635.     this._camera.position.set(0, this.MinPos.y, 0);
  636.     this._camera.updateProjectionMatrix();
  637. };

  638. /**
  639. * 3D レンダラの作成
  640. */
  641. Game_3DMap.prototype.create3dRenderer = function()
  642. {
  643.     this._canvas3d = new THREE.WebGLRenderer({ antialias: true, alpha: true });
  644.     this._canvas3d.setSize(Graphics.width, Graphics.height);
  645.     this._canvas3d.setClearColor(0, 0);

  646.     // 3D 描画結果を 2D 上に表示するためのスプライト
  647.     this._texture3d = PIXI.Texture.fromCanvas(this._canvas3d.domElement);
  648.     this._sprite3d = new PIXI.Sprite(this._texture3d);
  649.     this.addChild(this._sprite3d);
  650. };

  651. /**
  652. * オブジェクトの破棄
  653. */
  654. Game_3DMap.prototype.dispose = function()
  655. {
  656.     this.clear();

  657.     if (this._player)
  658.     {
  659.         this._player.material.dispose();
  660.         this._player = null;
  661.     }
  662.     this.removeChild(this._sprite3d);
  663.     this._canvas3d.dispose();
  664.     //this._stage2d.destroy();
  665. };

  666. Game_3DMap.prototype.parallaxOx = function()
  667. {
  668.     return this._parallaxX;
  669. };

  670. Game_3DMap.prototype.parallaxOy = function()
  671. {
  672.     return 0;
  673. };

  674. /**
  675. * 遠景の回転量を取得
  676. */
  677. Game_3DMap.prototype.parallaxRotation = function()
  678. {
  679.     return this._player.rotation.z;
  680. };

  681. /*
  682. * 処理時間をコンソールに表示 (デバッグ用)
  683. */
  684. var consoleTimeBegin;
  685. var consoleTimeEnd;
  686. if (Params._debugMode)
  687. {
  688.     consoleTimeBegin = function(key) { console.time(key); };
  689.     consoleTimeEnd = function(key) { console.timeEnd(key); };
  690. }
  691. else
  692. {
  693.     consoleTimeBegin = function() { };
  694.     consoleTimeEnd = function() { };
  695. }

  696. /**
  697. * 指定した軸を中心とした回転用のクォータニオンを作成
  698. */
  699. var calcQuaternion = function(axis, angleRad)
  700. {
  701.     var quat = new THREE.Quaternion();
  702.     quat.setFromAxisAngle(axis.normalize(), angleRad);

  703.     return quat;
  704. };

  705. /**
  706. * 2のべき乗に切り上げる
  707. */
  708. var roundUpSquareSize = function(n)
  709. {
  710.     var square = 1;
  711.     while (n > square)
  712.     {
  713.         square *= 2;
  714.     }

  715.     return square;
  716. };

  717. var snapForTileTexture = function(stage, width, height)
  718. {
  719.     var bitmap = new Bitmap(width, height);
  720.     var context = bitmap._context;
  721.     var renderTexture = new PIXI.RenderTexture(width, height);

  722.     if (stage)
  723.     {
  724.         consoleTimeBegin('render@snap');
  725.         renderTexture.render(stage);
  726.         stage.worldTransform.identity();
  727.         consoleTimeEnd('render@snap');
  728.     }

  729.     if (Graphics.isWebGL())
  730.     {
  731.         var gl = renderTexture.renderer.gl;
  732.         var webGLPixels = new Uint8Array(4 * width * height);

  733.         consoleTimeBegin('read@snap');
  734.         gl.bindFramebuffer(gl.FRAMEBUFFER, renderTexture.textureBuffer.frameBuffer);
  735.         gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels);
  736.         gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  737.         consoleTimeEnd('read@snap');

  738.         consoleTimeBegin('copy@snap');
  739.         var canvasData = context.getImageData(0, 0, width, height);
  740.         canvasData.data.set(webGLPixels);
  741.         context.putImageData(canvasData, 0, 0);
  742.         consoleTimeEnd('copy@snap');
  743.     }
  744.     else
  745.     {
  746.         context.drawImage(renderTexture.textureBuffer.canvas, 0, 0);
  747.     }

  748.     bitmap._setDirty();
  749.     return bitmap;
  750. };

  751. var updateLayerPos = function()
  752. {
  753.     var ox = Math.floor(this.origin.x);
  754.     var oy = Math.floor(this.origin.y);
  755.     var startX = Math.floor((ox - this._margin) / this._tileWidth);
  756.     var startY = Math.floor((oy - this._margin) / this._tileHeight);
  757.     this._updateLayerPositions(startX, startY);

  758.     this._frameUpdated = this._lastAnimationFrame !== this.animationFrame;
  759.     this._lastAnimationFrame = this.animationFrame;
  760.     this._lastStartX = startX;
  761.     this._lastStartY = startY;
  762.     this._paintAllTiles(startX, startY);
  763.     this._needsRepaint = false;
  764.     this._sortChildren();
  765. };

  766. /**
  767. * タイルマップのキャプチャを実行
  768. */
  769. Game_3DMap.prototype.captureTilemap = function(originalHolder, tilemap, characters)
  770. {
  771.     this._originalTilemapHolder = originalHolder;
  772.     this._tilemap = tilemap;
  773.     this._characters = characters;
  774.     this._baseScale = Params.mapQuality;

  775.     tilemap.origin.x = tilemap.origin.y = tilemap._margin;

  776.     // マップ画像作成のために、イベントをスクロールを無視した位置に配置
  777.     // (次のスプライト更新で元に戻るので、位置は記憶しなくて良い)
  778.     tilemap.children.forEach(function(child, index)
  779.     {
  780.         if (!(child instanceof Sprite_Character) || !child._character)
  781.         {
  782.             return;
  783.         }

  784.         var character = child._character;
  785.         child.x = character.notScrolledScreenX() - tilemap._margin;
  786.         child.y = character.notScrolledScreenY() - tilemap._margin;
  787.     });

  788.     tilemap.width = tilemap._mapWidth * tilemap.tileWidth;
  789.     tilemap.height = tilemap._mapHeight * tilemap.tileHeight;
  790.     //updateLayerPos.call(tilemap);
  791.     tilemap.scale.x = tilemap.scale.y = this._baseScale;
  792.     tilemap.refresh();

  793.     this._stage2d.addChild(this._tilemap);

  794.     consoleTimeBegin('3D snap');
  795.     var bitmap = snapForTileTexture(
  796.         this._stage2d,
  797.         Math.floor(this._tilemap.width * this._baseScale),
  798.         Math.floor(this._tilemap.height * this._baseScale));
  799.     consoleTimeEnd('3D snap');
  800.     var texSize = roundUpSquareSize(Math.max(bitmap.width, bitmap.height));

  801.     this._texRate = { x: texSize / bitmap.width, y: texSize / bitmap.height };
  802.     var loopNum = 2 * Math.min(2, Math.ceil(
  803.         2500 * Math.max(this._texRate.x, this._texRate.y) * this._baseScale / texSize));

  804.     consoleTimeBegin('3D blt');
  805.     this._tileBitmap = new Bitmap(texSize, texSize);
  806.     this._tileBitmap.blt(bitmap, 0, 0, bitmap.width, bitmap.height, 0, 0, texSize, texSize);
  807.     consoleTimeEnd('3D blt');

  808.     // ループ仕様でテクスチャを作成
  809.     consoleTimeBegin('3D texture');
  810.     this._planeTexture = new THREE.Texture(this._tileBitmap.canvas);
  811.     this._planeTexture.needsUpdate = true;
  812.     this._planeTexture.wrapS = this._planeTexture.wrapT = THREE.RepeatWrapping;
  813.     this._planeTexture.repeat.set(loopNum, loopNum);
  814.     consoleTimeEnd('3D texture');

  815.     consoleTimeBegin('3D material');
  816.     this._planeMaterial = new THREE.MeshBasicMaterial({ map: this._planeTexture });
  817.     this._planeMaterial.transparent = true;
  818.     consoleTimeEnd('3D material');

  819.     consoleTimeBegin('3D geometry');
  820.     this._planeGeometry = new THREE.PlaneGeometry(
  821.         texSize * loopNum / this._texRate.x / this._baseScale,
  822.         texSize * loopNum / this._texRate.y / this._baseScale,
  823.         8, 8);
  824.     consoleTimeEnd('3D geometry');

  825.     // 地面オブジェクト
  826.     consoleTimeBegin('3D mesh');
  827.     this._planeMesh = new THREE.Mesh(this._planeGeometry, this._planeMaterial);
  828.     this._planeMesh.position.set(0, 0, 0);
  829.     this._planeMesh.rotation.x = -Math.PI / 2;
  830.     consoleTimeEnd('3D mesh');

  831.     this._scene3d.add(this._planeMesh);

  832.     this.setPlayerMapPosition($gamePlayer.x, $gamePlayer.y);
  833. };

  834. /**
  835. * タイルマップのキャプチャを終了
  836. */
  837. Game_3DMap.prototype.unCaptureTilemap = function()
  838. {
  839.     //tilemap.origin.x = tilemap.origin.y = tilemap._margin;
  840.     this._tilemap.width = Graphics.width + this._tilemap._margin * 2;
  841.     this._tilemap.height = Graphics.height + this._tilemap._margin * 2;
  842.     updateLayerPos.call(this._tilemap);
  843.     this._tilemap.scale.x = this._tilemap.scale.y = 1;
  844.     this._tilemap.refresh();

  845.     this.clear();
  846. };

  847. /**
  848. * メンバーのクリア
  849. */
  850. Game_3DMap.prototype.clear = function()
  851. {
  852.     if (this._originalTilemapHolder)
  853.     {
  854.         this._stage2d.removeChild(this._tilemap);
  855.         this._originalTilemapHolder.addChild(this._tilemap);
  856.         this._originalTilemapHolder = null;
  857.         this._tilemap = null;
  858.     }

  859.     this._scene3d.remove(this._planeMesh);
  860.     this._planeMesh = null;

  861.     if (this._planeGeo)
  862.     {
  863.         this._planeGeo.dispose();
  864.         this._planeGeo = null;
  865.     }

  866.     if (this._planeMaterial)
  867.     {
  868.         this._planeMaterial.dispose();
  869.         this._planeMaterial = null;
  870.     }

  871.     if (this._planeTexture)
  872.     {
  873.         this._planeTexture.dispose();
  874.         this._planeTexture = null;
  875.     }

  876.     this._player.position.y = this.MinPos.y;
  877.     this._player.rotation.set(0, 0, 0);
  878. };

  879. /**
  880. * 3D レンダリング実行
  881. */
  882. Game_3DMap.prototype.render3d = function()
  883. {
  884.     this._texture3d.baseTexture.dirty();
  885.     this._canvas3d.render(this._scene3d, this._camera);
  886. };

  887. /**
  888. * プレイヤーのマップ座標を設定
  889. */
  890. Game_3DMap.prototype.setPlayerMapPosition = function(x, y)
  891. {
  892.     var nx = x * this._tilemap.tileWidth;
  893.     var nz = y * this._tilemap.tileHeight;

  894.     this._player.position.x = nx;
  895.     this._player.position.z = nz;
  896.     this._parallaxX = 0;
  897.     this.updateCamera();
  898.     this.updateShadow();
  899.     this.updateParallax();
  900. };

  901. /**
  902. * プレイヤーのマップ座標を取得
  903. */
  904. Game_3DMap.prototype.getPlayerMapPosition = function()
  905. {
  906.     if (this._tilemap)
  907.     {
  908.         var x = this._player.position.x / this._tilemap.tileWidth;
  909.         var y = this._player.position.z / this._tilemap.tileHeight;
  910.         //x -= Math.sin(this._player.rotation.y) * 3;
  911.         //y -= Math.cos(this._player.rotation.y) * 3;
  912.         return { x: x, y: y };
  913.     }
  914.     else
  915.     {
  916.         return { x: 0, y: 0 };
  917.     }
  918. };

  919. Game_3DMap.prototype.setPlayerAngle = function(angle)
  920. {
  921.     this._player.rotation.y = angle;
  922. };

  923. Game_3DMap.prototype.getPlayerAngle = function()
  924. {
  925.     return this._player.rotation.y;
  926. };

  927. /**
  928. * 実際のプレイヤー位置を 3D マップ上の位置に合わせる
  929. */
  930. Game_3DMap.prototype.updatePlayerPosition = function()
  931. {
  932.     var pos = this.getPlayerMapPosition();
  933.     $gamePlayer._x = Math.round(pos.x);
  934.     $gamePlayer._y = Math.round(pos.y);
  935.     $gamePlayer._realX = pos.x;
  936.     $gamePlayer._realY = pos.y;
  937. };

  938. /**
  939. * プレイヤー位置をマップ座標内に収める
  940. */
  941. Game_3DMap.prototype.roundPlayerPosition = function()
  942. {
  943.     if (!this._tilemap)
  944.     {
  945.         return;
  946.     }

  947.     var pos = this.getPlayerMapPosition();
  948.     if (pos.x >= $gameMap.width())
  949.     {
  950.         this._player.position.x -= this._tilemap.tileWidth * $gameMap.width();
  951.     }
  952.     else if (pos.x < 0)
  953.     {
  954.         this._player.position.x += this._tilemap.tileWidth * $gameMap.width();
  955.     }

  956.     if (pos.y >= $gameMap.height())
  957.     {
  958.         this._player.position.z -= this._tilemap.tileHeight * $gameMap.height();
  959.     }
  960.     else if (pos.y < 0)
  961.     {
  962.         this._player.position.z += this._tilemap.tileHeight * $gameMap.height();
  963.     }
  964. };

  965. /**
  966. * カメラ座標とアングルの更新
  967. */
  968. Game_3DMap.prototype.updateCamera = function()
  969. {
  970.     var camera = this._camera;
  971.     var destObj = this._player;

  972.     var dist = (destObj.position.y - this.MinPos.y) * 1.45 + 128;
  973.     var dx = Math.sin(destObj.rotation.y) * dist;
  974.     var dz = Math.cos(destObj.rotation.y) * dist;

  975.     camera.position.x = destObj.position.x + dx;
  976.     camera.position.z = destObj.position.z + dz;
  977.     //camera.position.y = 24 + maxPosY - (maxPosY - destObj.position.y) * 0.25;
  978.     camera.position.y = destObj.position.y;
  979.     camera.lookAt(destObj.position);

  980.     // 旋回時の傾きを反映
  981.     var quat = calcQuaternion(new THREE.Vector3(0, 0, 1), destObj.rotation.z);
  982.     camera.quaternion.multiply(quat);
  983. };

  984. /**
  985. * 影の更新
  986. */
  987. Game_3DMap.prototype.updateShadow = function()
  988. {
  989.     this._shadow.position.x = this._player.position.x;
  990.     this._shadow.position.z = this._player.position.z;
  991. };

  992. /**
  993. * 遠景の更新
  994. */
  995. Game_3DMap.prototype.updateParallax = function(prevRotY)
  996. {
  997.     if (!$gameMap._parallaxLoopX)
  998.     {
  999.         return;
  1000.     }

  1001.     if (prevRotY)
  1002.     {
  1003.         this._parallaxX += (prevRotY - this._player.rotation.y)
  1004.             * this._tilemap.tileWidth * $gameMap.width() / Math.PI / 2;
  1005.     }
  1006. };

  1007. /**
  1008. * プレイヤーの移動処理
  1009. */
  1010. Game_3DMap.prototype.updateMove = function()
  1011. {
  1012.     if (!$gamePlayer.canMove())
  1013.     {
  1014.         return;
  1015.     }

  1016.     var isFast = this.isInputFast();
  1017.     var prevRotY = this._player.rotation.y;

  1018.     this.updateAccel(isFast);
  1019.     this.updateWhirl(isFast);
  1020.     this.updatePitch();
  1021.     this.updateCamera();
  1022.     this.updateShadow();
  1023.     this.updateParallax(prevRotY);

  1024.     /*
  1025.     if (Input.isTriggered('pageup'))
  1026.     {
  1027.         console.log(this._camera.position);
  1028.         console.log(this.getPlayerMapPosition());
  1029.         console.log({ x: $gamePlayer._x, y: $gamePlayer._y });
  1030.     }
  1031.     */
  1032. };

  1033. /**
  1034. * 前後への移動処理
  1035. */
  1036. Game_3DMap.prototype.updateAccel = function(isFast)
  1037. {
  1038.     var MaxSpeed = {
  1039.         forward: Params.speed.plane,
  1040.         backward: Params.speed.plane * 2 / 3
  1041.     };
  1042.     var StepSpeed = {
  1043.         forward: MaxSpeed.forward / 15,
  1044.         backward: MaxSpeed.backward / 15,
  1045.     };
  1046.     var BreakSpeed = $gamePlayer.moveSpeed() / 10;

  1047.     if (this.isInputForward())
  1048.     {
  1049.         // 前進
  1050.         this._moveSpeed = Math.max(
  1051.             this._moveSpeed - StepSpeed.forward,
  1052.             -MaxSpeed.forward);
  1053.     }
  1054.     else if (this.isInputBackward())
  1055.     {
  1056.         // 後退
  1057.         this._moveSpeed = Math.min(
  1058.             this._moveSpeed + StepSpeed.backward,
  1059.             MaxSpeed.backward);
  1060.     }
  1061.     else
  1062.     {
  1063.         // 操作終了後の慣性移動
  1064.         if (this._moveSpeed > 0)
  1065.         {
  1066.             this._moveSpeed = Math.max(this._moveSpeed - BreakSpeed, 0);
  1067.         }
  1068.         else
  1069.         {
  1070.             this._moveSpeed = Math.min(this._moveSpeed + BreakSpeed, 0);
  1071.         }
  1072.     }

  1073.     // 高速移動
  1074.     if (this._moveSpeed !== 0)
  1075.     {
  1076.         this._player.translateZ(this._moveSpeed * (isFast ? 2 : 1));
  1077.     }

  1078.     this.roundPlayerPosition();
  1079.     this.updatePlayerPosition();
  1080. };

  1081. /**
  1082. * 旋回処理
  1083. */
  1084. Game_3DMap.prototype.updateWhirl = function(isFast)
  1085. {
  1086.     if (this.isInputWhirlLeft())
  1087.     {
  1088.         this._player.rotation.y += this.StepRot.y * (isFast ? 1.5 : 1);
  1089.         this._player.rotation.z =
  1090.             Math.min(this._player.rotation.z + this.StepRot.z, this.MaxRot.z);
  1091.     }
  1092.     else if (this.isInputWhirlRight())
  1093.     {
  1094.         this._player.rotation.y -= this.StepRot.y * (isFast ? 1.5 : 1);
  1095.         this._player.rotation.z =
  1096.             Math.max(this._player.rotation.z - this.StepRot.z, -this.MaxRot.z);
  1097.     }
  1098.     else if (this._player.rotation.z !== 0)
  1099.     {
  1100.         // 旋回操作をやめたら徐々に水平に戻す
  1101.         if (this._player.rotation.z < 0)
  1102.         {
  1103.             this._player.rotation.z =
  1104.                 Math.min(this._player.rotation.z + this.StepRot.z, 0);
  1105.         }
  1106.         else
  1107.         {
  1108.             this._player.rotation.z =
  1109.                 Math.max(this._player.rotation.z - this.StepRot.z, 0);
  1110.         }
  1111.     }
  1112. };

  1113. /**
  1114. * ピッチアップ/ダウン処理
  1115. */
  1116. Game_3DMap.prototype.updatePitch = function()
  1117. {
  1118.     if (this.isInputPitchDown())
  1119.     {
  1120.         this._player.position.y =
  1121.             Math.max(this._player.position.y - this.StepPos.y, this.MinPos.y);
  1122.     }
  1123.     else if (this.isInputPitchUp())
  1124.     {
  1125.         this._player.position.y =
  1126.             Math.min(this._player.position.y + this.StepPos.y, this.MaxPos.y);
  1127.     }
  1128. };

  1129. /**
  1130. * 前進入力判定
  1131. */
  1132. Game_3DMap.prototype.isInputForward = function()
  1133. {
  1134.     return Input.isPressed('ok') || this.isTouchAccelArea();
  1135. };

  1136. /**
  1137. * 後退入力判定
  1138. */
  1139. Game_3DMap.prototype.isInputBackward = function()
  1140. {
  1141.     return Input.isPressed('pagedown');
  1142. };

  1143. /**
  1144. * 高速移動入力判定
  1145. */
  1146. Game_3DMap.prototype.isInputFast = function()
  1147. {
  1148.     return Input.isPressed('shift');
  1149. };

  1150. /**
  1151. * 左旋回入力判定
  1152. */
  1153. Game_3DMap.prototype.isInputWhirlLeft = function()
  1154. {
  1155.     return Input.isPressed('left') || this.isTouchWhirlArea('left');
  1156. };

  1157. /**
  1158. * 右旋回入力判定
  1159. */
  1160. Game_3DMap.prototype.isInputWhirlRight = function()
  1161. {
  1162.     return Input.isPressed('right') || this.isTouchWhirlArea('right');
  1163. };

  1164. /**
  1165. * ピッチアップ入力判定
  1166. */
  1167. Game_3DMap.prototype.isInputPitchUp = function()
  1168. {
  1169.     return Input.isPressed('down');
  1170. };

  1171. /**
  1172. * ピッチダウン入力判定
  1173. */
  1174. Game_3DMap.prototype.isInputPitchDown = function()
  1175. {
  1176.     return Input.isPressed('up');
  1177. };

  1178. /**
  1179. * 前進領域タッチ中判定
  1180. */
  1181. Game_3DMap.prototype.isTouchAccelArea = function()
  1182. {
  1183.     if (!TouchInput.isPressed())
  1184.     {
  1185.         return false;
  1186.     }

  1187.     var areaWidth = Math.floor(Graphics.width * Params.touchArea.accel);
  1188.     var areaX = Math.floor((Graphics.width - areaWidth) / 2);
  1189.     var touchX = TouchInput.x;
  1190.    
  1191.     return touchX >= areaX && touchX <= areaX + areaWidth;
  1192. };

  1193. /**
  1194. * 旋回領域タッチ中判定
  1195. */
  1196. Game_3DMap.prototype.isTouchWhirlArea = function(dir)
  1197. {
  1198.     if (!TouchInput.isPressed())
  1199.     {
  1200.         return false;
  1201.     }

  1202.     var areaWidth = Math.floor(Graphics.width * Params.touchArea.whirl / 2);
  1203.     var touchX = TouchInput.x;
  1204.     switch (dir)
  1205.     {
  1206.         case 'left': return touchX <= areaWidth;
  1207.         case 'right': return touchX >= Graphics.width - areaWidth;
  1208.         default: return false;
  1209.     }
  1210. };


  1211. //-----------------------------------------------------------------------------
  1212. // Spriteset_Map

  1213. Spriteset_Map.prototype.captureFor3D = function()
  1214. {
  1215.     // 3D モード用スイッチによる変更を反映
  1216.     $gameMap.refreshIfNeeded();
  1217.     this._characterSprites.forEach(function(sprite)
  1218.     {
  1219.         sprite.update();
  1220.     });

  1221.     this._vehicleSprites.forEach(function(sprite)
  1222.     {
  1223.         sprite.scale.x = sprite.scale.y = 1.5;

  1224.         // 乗り物スプライトを tilemap とは別の領域に表示
  1225.         this._tilemap.removeChild(sprite);
  1226.         this._pseudoTilemap.addChild(sprite);
  1227.     }, this);

  1228.     this._shadowSprite.visible = false;

  1229.     var map3d = $gameMap.get3DMap();
  1230.     var tilemapIndex = this._baseSprite.children.indexOf(this._tilemap);
  1231.     this._baseSprite.removeChild(this._tilemap);
  1232.     map3d.captureTilemap(this._baseSprite, this._tilemap, this._characterSprites);
  1233.     this._baseSprite.addChildAt(map3d, tilemapIndex);

  1234.     var rollMargin = 112;
  1235.     this._parallax.anchor.x = this._parallax.anchor.y = 0.5;
  1236.     this._parallax.move(
  1237.         Graphics.width / 2,
  1238.         Graphics.height / 2,
  1239.         Graphics.width + rollMargin * 3 / 2,
  1240.         Graphics.height + rollMargin * 2);
  1241. };

  1242. Spriteset_Map.prototype.unCaptureFor3D = function()
  1243. {
  1244.     this._parallax.anchor.x = this._parallax.anchor.y = 0;
  1245.     this._parallax.move(0, 0, Graphics.width, Graphics.height);

  1246.     var map3d = $gameMap.get3DMap();
  1247.     var tilemapIndex = this._baseSprite.children.indexOf(map3d);
  1248.     this._baseSprite.removeChild(map3d);
  1249.     map3d.unCaptureTilemap();
  1250.     this._baseSprite.addChildAt(this._tilemap, tilemapIndex);

  1251.     this._shadowSprite.visible = true;

  1252.     this._vehicleSprites.forEach(function(sprite, index)
  1253.     {
  1254.         sprite.scale.x = sprite.scale.y = 1;

  1255.         // 乗り物スプライトを tilemap 配下に戻す
  1256.         this._pseudoTilemap.removeChild(sprite);
  1257.         this._tilemap.addChildAt(sprite, this._vehicleSpriteChildIndex + index);
  1258.     }, this);

  1259.     // 3D モード用スイッチによる変更を反映
  1260.     $gameMap.refreshIfNeeded();
  1261.     this._characterSprites.forEach(function(sprite)
  1262.     {
  1263.         sprite.update();
  1264.     });
  1265. };

  1266. Spriteset_Map.prototype.createCharacters = function()
  1267. {
  1268.     this._pseudoTilemap = new Sprite();
  1269.     this._baseSprite.addChild(this._pseudoTilemap);
  1270.     this._characterSprites = [];
  1271.     this._vehicleSprites = [];
  1272.     $gameMap.events().forEach(function(event) {
  1273.         this._characterSprites.push(new Sprite_Character(event));
  1274.     }, this);

  1275.     // 3D モードからの復帰用に、乗り物スプライトの追加位置を記憶
  1276.     this._vehicleSpriteChildIndex = this._characterSprites.length - 1;

  1277.     $gameMap.vehicles().forEach(function(vehicle) {
  1278.         var sprite = new Sprite_Character(vehicle);
  1279.         this._characterSprites.push(sprite);
  1280.         this._vehicleSprites.push(sprite);
  1281.     }, this);
  1282.     $gamePlayer.followers().reverseEach(function(follower) {
  1283.         this._characterSprites.push(new Sprite_Character(follower));
  1284.     }, this);
  1285.     this._characterSprites.push(new Sprite_Character($gamePlayer));
  1286.     for (var i = 0; i < this._characterSprites.length; i++) {
  1287.         this._tilemap.addChild(this._characterSprites[i]);
  1288.     }
  1289. };

  1290. var _KMS_3DVehicle_Spriteset_Map_updateParallax = Spriteset_Map.prototype.updateParallax;
  1291. Spriteset_Map.prototype.updateParallax = function()
  1292. {
  1293.     if ($gameMap.is3DMode())
  1294.     {
  1295.         this.updateParallaxFor3D();
  1296.     }
  1297.     else
  1298.     {
  1299.         _KMS_3DVehicle_Spriteset_Map_updateParallax.call(this);
  1300.     }
  1301. }

  1302. Spriteset_Map.prototype.updateParallaxFor3D = function()
  1303. {
  1304.     if (this._parallaxName !== $gameMap.parallaxName())
  1305.     {
  1306.         this._parallaxName = $gameMap.parallaxName();
  1307.         this._parallax.bitmap = ImageManager.loadParallax(this._parallaxName);
  1308.     }
  1309.     if (this._parallax.bitmap)
  1310.     {
  1311.         var map3d = $gameMap.get3DMap();
  1312.         this._parallax.origin.x = map3d.parallaxOx();
  1313.         this._parallax.origin.y = map3d.parallaxOy();
  1314.         this._parallax.rotation = map3d.parallaxRotation();
  1315.     }
  1316. };

  1317. var _KMS_3DVehicle_Spriteset_Map_updateTilemap = Spriteset_Map.prototype.updateTilemap;
  1318. Spriteset_Map.prototype.updateTilemap = function()
  1319. {
  1320.     _KMS_3DVehicle_Spriteset_Map_updateTilemap.call(this);

  1321.     if ($gameMap.is3DMode())
  1322.     {
  1323.         $gameMap.get3DMap().render3d();
  1324.     }
  1325. };


  1326. //-----------------------------------------------------------------------------
  1327. // Scene_Map

  1328. var _KMS_3DVehicle_Scene_Map_create = Scene_Map.prototype.create;
  1329. Scene_Map.prototype.create = function()
  1330. {
  1331.     _KMS_3DVehicle_Scene_Map_create.call(this);

  1332.     this._last3DMapMode = false;
  1333.     $gameMap.create3DMap();

  1334.     // XXX: マップ移動の場合は 3D 解除 (暫定)
  1335.     if (this._transfer)
  1336.     {
  1337.         $gameMap.set3DMode(false);
  1338.     }
  1339.     else
  1340.     {
  1341.         $gameMap.restore3DMapInfo();
  1342.     }

  1343.     $gameMap.set3DModeCallback(this, this.set3DMode);
  1344. };

  1345. var _KMS_3DVehicle_Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  1346. Scene_Map.prototype.createDisplayObjects = function()
  1347. {
  1348.     _KMS_3DVehicle_Scene_Map_createDisplayObjects.call(this);

  1349.     // 前回の 3D 状態の復元
  1350.     this.set3DMode($gameMap.is3DMode());
  1351. };

  1352. var _KMS_3DVehicle_Scene_Map_stop = Scene_Map.prototype.stop;
  1353. Scene_Map.prototype.stop = function()
  1354. {
  1355.     if ($gameMap.is3DMode())
  1356.     {
  1357.         $gameMap.save3DMapInfo();
  1358.     }

  1359.     _KMS_3DVehicle_Scene_Map_stop.call(this);
  1360. };

  1361. var _KMS_3DVehicle_Scene_Map_update = Scene_Map.prototype.update;
  1362. Scene_Map.prototype.update = function()
  1363. {
  1364.     _KMS_3DVehicle_Scene_Map_update.call(this);
  1365. };

  1366. var _KMS_3DVehicle_Scene_Map_terminate = Scene_Map.prototype.terminate;
  1367. Scene_Map.prototype.terminate = function()
  1368. {
  1369.     _KMS_3DVehicle_Scene_Map_terminate.call(this);

  1370.     $gameMap.dispose3DMap();
  1371. };

  1372. Scene_Map.prototype.set3DMode = function(enabled)
  1373. {
  1374.     if (this._last3DMapMode !== enabled)
  1375.     {
  1376.         this._last3DMapMode = enabled;
  1377.         if (enabled)
  1378.         {
  1379.             this._spriteset.captureFor3D();
  1380.         }
  1381.         else
  1382.         {
  1383.             this._spriteset.unCaptureFor3D();
  1384.         }
  1385.     }
  1386. };

  1387. var _KMS_3DVehicle_Scene_Map_isMenuCalled = Scene_Map.prototype.isMenuCalled;
  1388. Scene_Map.prototype.isMenuCalled = function()
  1389. {
  1390.     if ($gamePlayer.isInVehicle())
  1391.     {
  1392.         return false;
  1393.     }

  1394.     return _KMS_3DVehicle_Scene_Map_isMenuCalled.call(this);
  1395. };

  1396. })();
复制代码


KMS_3DMenu
  1. //=============================================================================
  2. // KMS_3DMenu.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc
  6. * [v0.1]
  7. * Applies spiral encounter effect.
  8. *
  9. * @author TOMY
  10. *
  11. * @help This plugin does not provide plugin commands.
  12. */

  13. /*:ja
  14. * @plugindesc
  15. * [v0.1]
  16. * エンカウント時に画面を回転させるエフェクトを適用します。
  17. *
  18. * @author TOMY
  19. *
  20. * @help このプラグインには、プラグインコマンドはありません。
  21. */

  22. (function()
  23. {

  24. var pluginParams = PluginManager.parameters('KMS_3DMenu');
  25. var Params = {};

  26. KMS.subRenderer = PIXI.autoDetectRenderer(Graphics.width, Graphics.height, { transparent: true });

  27. var _KMS_3DMenu_Graphics_render = Graphics.render;
  28. Graphics.render = function(stage)
  29. {
  30.     _KMS_3DMenu_Graphics_render.call(this, stage);

  31.     if (!this._rendered)
  32.     {
  33.         return;
  34.     }

  35.     var skipCount3d = 0;
  36.     if (Graphics.Kms3dInfo)
  37.     {
  38.         var info = Graphics.Kms3dInfo;
  39.         var startTime = Date.now();
  40.         info.texture3d.baseTexture.dirty();
  41.         info.texture2d.needsUpdate = true;
  42.         info.canvas.render(info.stage, info.camera);
  43.         var endTime = Date.now();
  44.         var elapsed = endTime - startTime;
  45.         skipCount3d = Math.floor(elapsed / 15);
  46.     }

  47.     this._skipCount = Math.min(skipCount3d + this._skipCount, this._maxSkip);
  48. };

  49. //-----------------------------------------------------------------------------
  50. // Scene_Menu

  51. var _KMS_3DMenu_Scene_Menu_create = Scene_Menu.prototype.create;
  52. Scene_Menu.prototype.create = function()
  53. {
  54.     _KMS_3DMenu_Scene_Menu_create.call(this);
  55.     this.create3d();
  56. };

  57. Scene_Menu.prototype.create3d = function()
  58. {
  59.     var width  = Graphics.width;
  60.     var height = Graphics.height;
  61.     this._scene3d = new THREE.Scene();
  62.     this._scene3d.fog = new THREE.Fog( "#a1a1a1", 2000, 4000 );
  63.     this._camera  = new THREE.PerspectiveCamera(75, width / height, 1, 10000);
  64.     this._camera.position.set( 0, 0, 400);
  65.     this._camera.updateProjectionMatrix();

  66.     this._canvas3d = new THREE.WebGLRenderer( { antialias: true, alpha: true } );
  67.     this._canvas3d.setSize(width, height);
  68.     this._canvas3d.setClearColor(0x000000, 0);

  69.     this._texture3d = PIXI.Texture.fromCanvas(this._canvas3d.domElement);
  70.     this._sprite3d = new PIXI.Sprite(this._texture3d);
  71.     /*
  72.     var filter = new PIXI.TwistFilter();
  73.     filter.radius = 0.3;
  74.     this._sprite3d.filters = [filter];
  75.     */
  76.     this.addChild(this._sprite3d);

  77.     // 2D グラフィックスを 3D にマップ
  78.     this._subStage = new Stage();
  79.     this._texture2d = new THREE.Texture(KMS.subRenderer.view);
  80.     this._texture2d.needsUpdate = true;

  81.     this._windowMaterial = new THREE.MeshBasicMaterial(
  82.             { map: this._texture2d, transparent: true } );
  83.     this._windowMaterial.side = THREE.DoubleSide;

  84.     var geometry = new THREE.BoxGeometry( 500, 500, 500 );
  85.     this.cube = new THREE.Mesh( geometry, this._windowMaterial );
  86.     this.cube.position.z = -200;
  87.     this.cube.rotation.z = -45;
  88.     this._scene3d.add( this.cube );

  89.     paramFunc = function(u, v)
  90.     {
  91.         var x = (u - 0.5) * width;
  92.         var y = (v - 0.5) * height;
  93.         var z = Math.sin(u * Math.PI) * -50;
  94.         return new THREE.Vector3(x, y, z);
  95.     };
  96.     this._windowMesh = new THREE.Mesh(
  97.             new THREE.ParametricGeometry(paramFunc, 8, 32),
  98.             this._windowMaterial);
  99.     this._windowMesh.position.set(0, 0, 0);
  100.     //this._scene3d.add(this._windowMesh);

  101.     Graphics.Kms3dInfo = {
  102.         canvas:    this._canvas3d,
  103.         stage:     this._scene3d,
  104.         camera:    this._camera,
  105.         texture3d: this._texture3d,
  106.         texture2d: this._texture2d
  107.     };

  108.     this._waveFilter = new KMS.ShockwaveFilter();
  109. };

  110. var _KMS_3DMenu_Scene_Menu_terminate = Scene_Menu.prototype.terminate;
  111. Scene_Menu.prototype.terminate = function() {
  112.     _KMS_3DMenu_Scene_Menu_terminate.call(this);
  113.     this.terminate3d();
  114. };

  115. Scene_Menu.prototype.terminate3d = function()
  116. {
  117.     Graphics.Kms3dInfo = null;
  118.     //this._windowMesh.dispose();
  119.     this._windowMaterial.dispose();
  120.     this._texture2d.dispose();
  121.     //this._sprite3d.dispose();
  122.     //this._texture3d.dispose();
  123.     this._canvas3d.dispose();
  124.     //this._camera.dispose();
  125.     //this._scene3d.dispose();
  126. };

  127. var _KMS_3DMenu_Scene_Menu_update = Scene_Menu.prototype.update;
  128. Scene_Menu.prototype.update = function()
  129. {
  130.     _KMS_3DMenu_Scene_Menu_update.call(this);
  131.     this.cube.rotation.y += 0.01;
  132.     this.cube.rotation.x += 0.01;
  133.     this.renderWindow();
  134. };

  135. Scene_Menu.prototype.renderWindow = function()
  136. {
  137.     var targets = [this._windowLayer, this._animationCursor];

  138.     if (Input.isTriggered('pageup'))
  139.     {
  140.         if (this._sprite3d.filters)
  141.         {
  142.             this._sprite3d.filters = null;
  143.         }
  144.         else
  145.         {
  146.             this._sprite3d.filters = [this._waveFilter];
  147.             this._waveFilter.time = 0;
  148.         }
  149.     }
  150.     this._waveFilter.time += 0.015;
  151.     if (this._waveFilter.time >= 1.0)
  152.     {
  153.         this._waveFilter.time = 0;
  154.         this._waveFilter.center.x = 0.4 + Math.random() * 0.2;
  155.         this._waveFilter.center.y = 0.4 + Math.random() * 0.2;
  156.     }

  157.     targets.forEach(function(target)
  158.     {
  159.         this._subStage.addChild(target);
  160.         target.visible = true;
  161.     }, this);
  162.     KMS.subRenderer.render(this._subStage);
  163.     targets.forEach(function(target)
  164.     {
  165.         target.visible = false;
  166.         this.addChild(target);
  167.     }, this);
  168. };

  169. })();
复制代码
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2016-1-22 22:20:30 来自手机 | 显示全部楼层
好东西……学习。
回复

使用道具 举报

梦石
0
星屑
50
在线时间
139 小时
注册时间
2014-6-12
回帖
110
 楼主| 发表于 2016-8-28 23:13:36 | 显示全部楼层
回复

使用道具 举报

梦石
0
星屑
50
在线时间
139 小时
注册时间
2014-6-12
回帖
110
 楼主| 发表于 2016-8-28 23:14:24 | 显示全部楼层
tseyik 发表于 2016-1-22 19:50
threejs必要
[fold=飛空艇搭乗時 3D 化 α 版]//======================================================= ...

到今天才知道那个牛b的东西不叫mv,叫sg
https://rpg.blue/forum.php?mod=v ... page%3D1#pid2695754
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2016-8-28 23:42:02 | 显示全部楼层
situkei 发表于 2016-8-28 23:14
到今天才知道那个牛b的东西不叫mv,叫sg
https://rpg.blue/forum.php?mod=viewthread&tid=395425&pid= ...

MV有3D插件
回复

使用道具 举报

梦石
0
星屑
50
在线时间
139 小时
注册时间
2014-6-12
回帖
110
 楼主| 发表于 2016-8-28 23:45:12 | 显示全部楼层

但是这个太牛了,看我头像5分钟做的地图,实景图没有任何后期滤镜加工,只是在游戏里加了一个区域光

点评

只要有3D模組,不只MV可以做到,VA也一様可做到,http://rm.66rpg.com/forum.php?mod=viewthread&tid=347457  发表于 2016-8-29 00:09
回复

使用道具 举报

梦石
0
星屑
497
在线时间
266 小时
注册时间
2015-12-8
回帖
729
发表于 2016-8-31 21:55:18 | 显示全部楼层
situkei 发表于 2016-8-28 23:14
到今天才知道那个牛b的东西不叫mv,叫sg
https://rpg.blue/forum.php?mod=viewthread&tid=395425&pid= ...

你先隨便弄個範例遊戲來看看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部