Cocos2d-js in 3D

  • little77
    Likes 0

    Problem Description

    Hi,

    I have some difficulties to load a 3D scene made with cocos studio in javascript. When I try to load my scene, I get errors for each object in my scene.

    Can't find the parser : %s UserCameraObjectData
    Can't find the parser : %s Light3DObjectData
    Can't find the parser : %s Light3DObjectData

    I have 1 camera and 2 lights.

    I made some research and found that it was not possible to make 3D in javascript with cocos2d, is it now possible?

    Another question, is it possible to include Three.js library in cocos2d to make 3D ?


    Thanks for your time,

  • Sonar Systems admin
    Likes 0

    What code are you using to load the scene.

     

    Three.js for web games or mobile/desktop games?

  • little77
    Likes 0

    Three.js for webGame.

    Here is my code to load 3DScene :

    app.js

    
    var INITIALISED = false;
    
    var HelloWorldLayer = cc.Layer.extend({
        _mainscene:null,
        _size:null,
        ctor:function () {
    
            this._super();
    
    
            this._size = cc.winSize;
    
            this._mainscene = ccs.load(res.MenuScene_json);
            this.addChild(this._mainscene.node);
    
           /* var camera = cc.Camera.createPerspective(60,size.width/size.height,1,1000);
            camera.setPosition3D(Vec3(0,100,100));
            camera.lookAt(Vec3(0,0,0),Vec3(0,1,0));
            this.addChild(camera);*/
    
            var btn = this._mainscene.node.getChildByName("btn_Start");
            btn.addTouchEventListener(this.touchEvent,this);
    
    
            return true;
        },
        touchEvent: function(sender, type)
        {
            var scene = new Scene3D();
            switch(type)
            {
                case ccui.Widget.TOUCH_ENDED:
                    cc.director.pushScene(scene);
            }
        }
    });
    
    var HelloWorldScene = cc.Scene.extend({
        onEnter:function () {
            this._super();
            if(INITIALISED == false)
            {
                INITIALISED = true;
                var layer = new HelloWorldLayer();
                this.addChild(layer);
            }
        }
    });
    

    3dScene.js

    
    var INITIALISED_3D = false;
    
    var Scene3DLayer = cc.Node.extend({
        _scene:null,
        _size:null,
        ctor:function () {
    
            this._super();
    
    
            this._size = cc.winSize;
    
            this._scene = ccs.load(res.Scene3D_json);
            this.addChild(this._scene.node);
    
            console.log(this);
    
            /* var camera = cc.Camera.createPerspective(60,size.width/size.height,1,1000);
             camera.setPosition3D(Vec3(0,100,100));
             camera.lookAt(Vec3(0,0,0),Vec3(0,1,0));
             this.addChild(camera);*/
    
            return true;
        }
    
    });
    
    var Scene3D = cc.Scene.extend({
        onEnter:function () {
            this._super();
            if(INITIALISED_3D == false)
            {
                INITIALISED_3D = true;
                var layer = new Scene3DLayer();
                this.addChild(layer);
            }
        }
    });
    

     

  • Sonar Systems admin
    Likes 0

    Have you looked at the examples in the Cocos2d-x folder?

  • little77
    Likes 0

    Yes but there is no example for launching a 3d scene in javascript

  • Sonar Systems admin
    Likes 0

    Are there any examples for launching a scene in C++?

  • little77
    Likes 0

    There : http://cocos2d-x.org/documentation/programmers-guide/9/index.html

    but some function does not exist when i try but convert the code in javascript.

    I did not find any other example.

  • Sonar Systems admin
    Likes 0

    What function does not exist?

  • little77
    Likes 0

    The functions that does not exist are for creating a camera in javascript.

    But,

    That is not what I asked, can you answer me something instead of answering me another question please? It’s not usefull right now. I juste want to launch a 3d scene in javascript, did you already done that ? I sent you my code, what is wrong with it? and for Three.js, is there any way to use it in the same canvas than cocos?

  • Sonar Systems admin
    Likes 0

    Does a model load correctly.

     

    Three.js can be potentially used with Cocos but no point, just use Three.js if you want Three.js.

  • little77
    Likes 0

    No I can’t load any model, when I have a model in my scene, I get this error : 

    loader for [.c3t] not exists!

     

  • Sonar Systems admin
    Likes 0

    What version of cocos are you using?

  • little77
    Likes 0

    I am using cocos2d-x-3.10

  • Sonar Systems admin
    Likes 0

    What 3D model was you trying to load?

  • little77
    Likes 0

    A simple cube...

  • Sonar Systems admin
    Likes 0

    Have you tried one of the included models from the Cocos Examples?

  • little77
    Likes 0

    Yes, I got the same issue

  • Sonar Systems admin
    Likes 0

    That is weird, try it in a fresh project using the code from our Cocos API Guide http://cocos.sonarlearning.co.uk/ 

Login to reply