扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 101|回复: 0

[转载发布] mv如何使用three.js?

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    2024-11-27 10:08
  • 签到天数: 108 天

    连续签到: 4 天

    [LV.6]常住居民II

    2219

    主题

    376

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    9661
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    12284

    灌水之王

    发表于 2024-2-16 15:02:51 | 显示全部楼层 |阅读模式
    如题,

    参考 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 = [0, 0, 0, 0];
        this._colorTone = [0, 0, 0, 0];
        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在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2025-1-16 15:02 , Processed in 0.066947 second(s), 57 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表