0

私はphysicaljsとnode.jsを使って簡単なウェブオンラインゲームを作ろうとしています.

ここから関連ソースを見つけました ( https://github.com/jjoe64/nodejs-physijs )

以下は、使用したい基本的なサーバー側コードです。

'use strict';

var THREE = require('./libs/three.js');
var Ammo = require('./libs/ammo.js');
var Physijs = require('./libs/physi.js')(THREE, Ammo);



/////////////////
// game

var initScene, render, renderer, scene, camera, box_falling;

initScene = function() {

    scene = new Physijs.Scene;

    // Box
    box_falling = new Physijs.BoxMesh(
        new THREE.CubeGeometry( 5, 5, 5 ),
        new THREE.MeshBasicMaterial({ color: 0x888888 })
    );
    scene.add( box_falling );

    // Box
    var box = new Physijs.BoxMesh(
        new THREE.CubeGeometry( 5, 5, 5 ),
        new THREE.MeshBasicMaterial({ color: 0x880088 }),
        0
    );
    box.position.y = -20;
    scene.add( box );

    setTimeout( render, 200 );
};

render = function() {
    scene.simulate(); // run physics
    setTimeout( render, 200 );
};


//////////////////
// web socket

var io = require('socket.io').listen(8088);

(function() {
    io.sockets.on('connection', function (socket) {
        console.log('client conneted');
    });

    // start physijs scene
    initScene();
})();

問題は、私は node.js と socket.io の初心者なので、このサーバー側コードからクライアントのビューポートにシーンをインポートする方法がわからないことです。これのクライアント側のサンプルコードはありますか? または、ソケットを使用してサーバーからクライアントにシーン情報を送信するにはどうすればよいですか? どうすればそれらを表示できますか?

4

1 に答える 1