26

(9 replies, posted in General)

I found that loading meshes from xml .mesh files take a very long time in my project.
Is there any possibility in maratis to store meshes in binary format and load them with SDK from that format?

27

(12 replies, posted in General)

Hello!
I exported simple scene (box with texture) with 3d s max exporter  ( http://forum.maratis3d.com/viewtopic.php?id=134&p=5 ). Export was successful.
When  trying to open it in Maratis.app (Mac , 3.1 beta) , I see black box without texture. I tried to change path to texture in Box.mesh file, and to change parameters of texture.
I also tried to load this scene in iPhonePunlishing example. I saw the same result.
Can you look at this scene, what is wrong with it?   Scene

Thanks a lot!

I think its ok with  MVector3 newPosition = parent->getPosition() + dpos;   ,
dpos - distance that object moved from last update.

Code works now, but movement is not smooth. its very jerky.
App works very slow.
How can I get current fps from engine? I want to experiment with different effects on/off and different meshes

I will try to use
engine->getSystemContext()->getSystemTick()
also

I've found and fix  the error ,code works now.

In my maratis project I have invisible Target object, and Camera, which has Follow Target behavior and Looks At target behavior.
I want to move target from my C++ code, thus force Camera follows this object.
I  want to achieve effect of smooth moving the camera.
I create custom MoveTo behavior. Objects are initialized with new position , and the time during which they have to move. (If you familiar with cocos2d actions - I want to realize analogue of CCMoveTo for maratis).
I add behavior to my target object:

 target = scene->getObjectByName("Target");
 float animationDuration = 1.5;
 MoveToBehaviour *moveToBeh = new MoveToBehaviour(target, categoryTargetPosition, animationDuration);
 target->addBehavior( moveToBeh );
// delete behavior after delay
 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, animationDuration*1.1 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
     target->deleteBehavior(0);
 });

When this code executed, the camera instantly move to new position, without smooth movement.
What I'm doing wrong?
How to do this correctly?
Does MBehavior::update() is called periodically by engine , or should I manually call MBehavior::update() on every frame?

Code of MoveTo behavior class:

#ifndef _MB_MOVETO_H
#define _MB_MOVETO_H

#include <sys/time.h>

class MoveToBehaviour : public MBehavior
{
public:
    // constructors / destructors
    MoveToBehaviour(MObject3d * parentObject, MVector3 _pos, float _tm);
    MoveToBehaviour(MoveToBehaviour & behavior, MObject3d * parentObject);
    ~MoveToBehaviour(void);
private:

    float tm, elapsedTime;
    MVector3 pos;
    MVector3 initialPos;
    struct timeval lastCallTime;
//    M
public:

    // destroy
    void destroy(void);

    // get new
    static MBehavior * getNew(MObject3d * parentObject);

    // get copy
    MBehavior * getCopy(MObject3d * parentObject);

    // name
    static const char * getStaticName(void){ return "MoveTo"; }
    const char * getName(void){ return getStaticName(); }

    // events
    void update(void);
    void runEvent(int param){}

    // variables
    unsigned int getVariablesNumber(void);
    MVariable getVariable(unsigned int id);
};

#endif

.cpp:

#include <MEngine.h>
#include "MoveToBehaviour.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init
/////////////////////////////////////////////////////////////////////////////////////////////////////////

MoveToBehaviour::MoveToBehaviour(MObject3d * parentObject, MVector3 _pos, float _tm) :
MBehavior(parentObject),
tm (_tm),
pos (_pos),
elapsedTime (0.0)
{
    gettimeofday(&lastCallTime, NULL);
    initialPos = MVector3();
    if (parentObject) {
        initialPos = parentObject->getPosition();
    }
}

MoveToBehaviour::MoveToBehaviour(MoveToBehaviour & behavior, MObject3d * parentObject) :
MBehavior(parentObject),
tm (behavior.tm),
pos (behavior.pos),
elapsedTime (behavior.elapsedTime),
lastCallTime(behavior.lastCallTime),
initialPos (behavior.initialPos)
{}

MoveToBehaviour::~MoveToBehaviour(void) {}

void MoveToBehaviour::destroy(void)
{
    delete this;
}

MBehavior * MoveToBehaviour::getNew(MObject3d * parentObject)
{
    return new MoveToBehaviour(parentObject, MVector3() , 0.0 );
}

MBehavior * MoveToBehaviour::getCopy(MObject3d * parentObject)
{
    return new MoveToBehaviour(*this, parentObject);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables
/////////////////////////////////////////////////////////////////////////////////////////////////////////

unsigned int MoveToBehaviour::getVariablesNumber(void){
    return 2;
}

MVariable MoveToBehaviour::getVariable(unsigned int id)
{
    switch(id)
    {
    default:
        return MVariable("NULL", NULL, M_VARIABLE_NULL);
    case 0:
        return MVariable("time", &tm, M_VARIABLE_FLOAT);
    case 1:
        return MVariable("moveToPosition", &pos, M_VARIABLE_VEC3);
    }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Events
/////////////////////////////////////////////////////////////////////////////////////////////////////////

void MoveToBehaviour::update(void)
{
    if (elapsedTime >= tm*1000.0) {
        return;
    }
    
    MEngine * engine = MEngine::getInstance();
    MGame * game = engine->getGame();
    MLevel * level = engine->getLevel();
    MScene * scene = level->getCurrentScene();

    MObject3d * parent = getParentObject();

    long lastMillis = lastCallTime.tv_sec * 1000 + lastCallTime.tv_usec / 1000;
    
    struct timeval tv ;
    gettimeofday(&tv, NULL);
    long millis = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
    long dt = millis - lastMillis;
    lastCallTime = tv;
    
    MVector3 dpos = (pos - initialPos) * ( ((float)dt) / (tm*1000.0) );
    MVector3 newPosition = parent->getPosition() + dpos;
    parent->setPosition( newPosition );
    parent->updateMatrix();
    
    elapsedTime += dt;
    if (elapsedTime >= tm*1000.0) {
        parent->setPosition( pos );
        parent->updateMatrix();
    }
}

I cannot find method for hit testing in lua maratis3d docs. I found method RayHit, but I cannot understand fhow can I use it to determine on which mesh touch occurs.
SDK has functionality for this?

33

(48 replies, posted in General)

Thanks!
From which object should I obtain the current FPS?

About post-processing:
Since I used  SCREEN_WIDTH * SCREEN_HEIGHT  (768 * 1204 on iPad , 640*960 on  Retina iPhone )  as texture dimensions, I added

render->setTextureUWrapMode(M_WRAP_CLAMP);
render->setTextureVWrapMode(M_WRAP_CLAMP);

in

render->createTexture(&m_depthTextureId);
render->bindTexture(m_depthTextureId);
render->setTextureFilterMode(M_TEX_FILTER_NEAREST, M_TEX_FILTER_NEAREST);
render->texImage(0, SCREEN_WIDTH, SCREEN_HEIGHT, M_UINT, M_DEPTH, 0);

after render->bindTexture(m_depthTextureId);

34

(48 replies, posted in General)

DoF screenshot

About performance - what is the best way to display FPS on screen?
I want to see it during development of my app.
Other statistics are also useful.

Ok, thank you.

I make a 3D gallery app.
In that app I have three meshes on the  first "screen".
Each mesh represents category of 3D models to view.
When user tap on one of these meshes, camera should translate to next screen with several meshes.
Can I use lua for mesh hit testing (ie determine to what the mesh user touched)?

Can I send (trigger) events from lua to my Objective C iOS code?
For example, when user select one of the categories and  camera translates to it, I need to change UI (buttons, labels) in app.

37

(48 replies, posted in General)

I added post-process DoF to iOS example.

38

(48 replies, posted in General)

Ok
For retina support I added   
self.contentScaleFactor  = [UIScreen mainScreen].scale;
  in  initRenderingContext in EAGLView,

#define SCREEN_WIDTH ( [UIScreen mainScreen].bounds.size.width * [UIScreen mainScreen].scale)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale)
to MyGame , and change all occurrences of screenWidth/ screenHeight and RESOL macro with these macroses.
Its now works on Retina.

I've also found a bug on iPad 1 with iOS 4.3.3, where short after launches program crashes with EXC_BAD_ACCESS.
I will deploy my app on 5.* and newer firmwares, so I leave this bug for now.

39

(48 replies, posted in General)

I change M_UBYTE  to M_UINT
render->texImage(0, RESOL, RESOL, M_UBYTE, M_DEPTH, 0); , and program began to work.
Now project works on 4.3.3 and 5.1 devices, and on simulator.
On Retina display, image takes only quarter of screen.
I will fix this now, and then I'll start to add Depth of Field to this app

40

(48 replies, posted in General)

I add       glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);    at start of the resizeFromLayer:  , and buffers are created  on 5.*
Now I have to deal with  0x500 in        render->texImage(0, RESOL, RESOL, M_UBYTE, M_DEPTH, 0); in MyGame.

41

(48 replies, posted in General)

I've found that
glCheckFramebufferStatus(GL_FRAMEBUFFER)  returns error after

glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];


in resizeFromLayer: in ES2Renderer.

42

(48 replies, posted in General)

I not found the error for now.
I tried to compare initialization code in maratis ios project with initialization code in Cocos2D v 2.0.
In Cocos2d 2.0 init and creation of ramebuffer (with depth attachment) is ok both on 4.* and on 5.*.
Code in both projects looks equally, but in maratis I still have " Failed to make complete framebuffer object 8cdd" in glCheckFramebufferStatus(GL_FRAMEBUFFER).
I think that reason may be in maratis 3d code, which executed between calls to [ES2Renderer init] and [ES2Renderer resizeFromLayer:]
I will try to find it now.

43

(48 replies, posted in General)

On iOS 5.* I also get 0x8cdd (GL_FRAMEBUFFER_UNSUPPORTED) in glCheckFramebufferStatus(GL_FRAMEBUFFER)  in

- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer;

in ES2Renderer.mm.

44

(48 replies, posted in General)

On 4.3 devices all is ok.
On iPhone 4 (with retina display) image occupies a quarter of the screen (I think I must set contentScalFactor somewhere)

45

(48 replies, posted in General)

anael wrote:

I used simulator 4.3.

The errors looks like opengl is not initialized properly, something different to do with the more recent os ?

Looks like so.

I will try to run program on 4.* devices, and on Simulator 5.0 (when I download it).
I will try to google that.

46

(48 replies, posted in General)

I installed Simulator 4.3, and program runs ok on it, without gl errors.
Before that, I ran the program on simulator 5.1

47

(48 replies, posted in General)

last two errors occurs on each frame

I think there is some errors in creation of depth attachment texture in my project.
I will try to research this now.

48

(48 replies, posted in General)

I've got OpenGL error 0x500 in MyGame::MyGame() in

render->texImage(0, RESOL, RESOL, M_UBYTE, M_DEPTH, 0);

Also I've got OpenGL error  0x506  in MyGame::draw() in

render->clear(M_BUFFER_COLOR | M_BUFFER_DEPTH);

in if(camera) ..    block.
   
Also I've got 0x506 in  MyGame::draw()          scene->draw(camera);  in

glDrawElements(returnPrimitiveType(type), size, returnGLType(indicesType), indices);

49

(48 replies, posted in General)

I made checkout from svn and add last MyGame.h/.cpp,
and move

 game = new MyGame();       
 engine->setGame(game);

after

[self loadMaratisProject:filename];

What version of Simulator/Device you use?

50

(48 replies, posted in General)

I got gray and black image (like stones or wall texture) both on Simulator and on the device.
I will try now to look whats wrong and debug opengl.