じ☆ve冰风 发表于 2024-2-16 15:02:51

mv如何使用three.js?

如题,

参考 live2d的那个试了试,结果只能获得一个静态的图......
如何让它动起来呢?

原始的
http://www.hewebgl.com/article/getarticle/50

      var scene = new THREE.Scene();
      var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
      var renderer = new THREE.WebGLRenderer();
      renderer.setSize(window.innerWidth, window.innerHeight);
      document.body.appendChild(renderer.domElement);
      var geometry = new THREE.CubeGeometry(1,1,1);
      var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
      var cube = new THREE.Mesh(geometry, material); scene.add(cube);
      camera.position.z = 5;
      function render() {
            requestAnimationFrame(render);
            cube.rotation.x += 0.1;
            cube.rotation.y += 0.1;
            renderer.render(scene, camera);
      }
      render();
参考live2d那个.修改成的
https://rpg.blue/forum.php?mod=viewthread&tid=385505
function L2d_Sprite(){
      this.initialize.apply(this, arguments);
}

/**
* RMMV Live2D Sprite 物件
*/

L2d_Sprite.prototype = Object.create(PIXI.Sprite.prototype);
L2d_Sprite.prototype.constructor = L2d_Sprite;
L2d_Sprite.prototype.initialize = function() {

    this.scene = new THREE.Scene();
    this.camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
    this.renderer = new THREE.WebGLRenderer({ alpha:true, });
    this.renderer.setSize(300, 300);
    this.geometry = new THREE.CubeGeometry(1,1,1);
    this.material = new THREE.MeshBasicMaterial({color: 0x00ff00});
    this.cube = new THREE.Mesh(this.geometry, this.material);
    this.scene.add(this.cube);
    this.camera.position.z = 5;
      var texture=new PIXI.Texture.fromCanvas(this.renderer.domElement);
      PIXI.Sprite.call(this, texture);
}










已自己解决.....


function T3_Sprite(){
      this.initialize.apply(this, arguments);
}
(function() {

      
T3_Sprite.prototype = Object.create(Sprite.prototype);
T3_Sprite.prototype.constructor = T3_Sprite;
T3_Sprite.prototype.initialize = function() {

    this.scene = new THREE.Scene();
    this.camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
    this.renderer = new THREE.WebGLRenderer({alpha:true});
    this.renderer.setSize(300, 300);
    this.geometry = new THREE.CubeGeometry(1,1,1);
    this.material = new THREE.MeshBasicMaterial({color: 0x00ff00});
    this.cube = new THREE.Mesh(this.geometry, this.material);
    this.scene.add(this.cube);
    this.camera.position.z = 5;
    this.renderer.render(this.scene, this.camera);
   
    this._canvas = this.renderer.domElement

      var texture=new PIXI.Texture.fromCanvas(this._canvas)
      PIXI.Sprite.call(this, texture);

    this._bitmap = null;
    this._frame = new Rectangle();   

    this._frame.width = this._canvas.width;
    this._frame.height = this._canvas.height;

   
    this._realFrame = new Rectangle();
    this._offset = new Point();
    this._blendColor = ;
    this._colorTone = ;
    this._context = null;
    this._tintTexture = null;

    this.spriteId = Sprite._counter++;
    this.opaque = false;


      this.requestID
    this.updateAnimation()
}







T3_Sprite.prototype.stopAnimation =function () {
         var cancelAnimationFrame =
            window.cancelAnimationFrame ||
            window.mozCancelAnimationFrame;
      //取消动画帧
      cancelAnimationFrame(this.requestID);
      
}




T3_Sprite.prototype.updateAnimation =function () {
      this.cube.rotation.x += 100;
    this.renderer.render(this.scene, this.camera)
    this.texture.baseTexture =new PIXI.BaseTexture(this._canvas);
      
      var requestAnimationFrame =
                     window.requestAnimationFrame ||
                     window.mozRequestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.msRequestAnimationFrame;
      this.requestID = requestAnimationFrame( this.updateAnimation.bind(this))
}



Object.defineProperty(T3_Sprite.prototype, 'bitmap', {
    configurable: false
});



})();
            本帖来自P1论坛作者汪汪,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=387616若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页: [1]
查看完整版本: mv如何使用three.js?