忘れない。

これまで経験した二度と同じ過ちを繰り返さない為の戒めの書。随時更新。。

dyld: library not loaded: @rpath/xxx.dylib ダイナミックリンクがないって言われる。。

dyld: library not loaded: @rpath/xxx.dylib
みたいな感じでダイナミックリンクねーよって怒られる時はこちら。忘れない。
https://github.com/2bbb/ofxNDI/blob/48616bf6a51dd1abfe2a30608390b95dc97e5132/readme.md

そして上記方法で別のframeworkなどが既にCopyFilesにある場合
Destinationの違いなのか左上から新たに+でCopyFilesPhaseを新規作成してから
DestinationをExecutablesに指定して追加してやらないとダメだった。。

ofVideoPlayer(ofAVFoundationVideoPlayer)でのofAVFoundationPlayerのsetFrameがバグってる問題 2017.12.4

以前書いてた以下の対応でも全くバグったままだったので見てみるとsetFrameだけやたら遅い。。nextFrame()とかは普通の挙動してる。
ということで差分FrameStepできる関数を勝手に追加して解決する。

# /libs/openframeworks/video/ofAVFoundationPlayer.h
void ofAVFoundationPlayer::addFrame(int frame) {
    if(videoPlayer == nullptr) {
        return;
    }
    
    [videoPlayer stepByCount: frame ];
}

    ofAVFoundationPlayer fingerMovie;
# setup
    fingerMovie.load("movies/fingers.mov");
    fingerMovie.play();

# update
    if(fingerMovie.isLoaded())
    {
        fingerMovie.setSpeed(0);
        int current = fingerMovie.getCurrentFrame();
        if(current==INT_MIN){
            fingerMovie.update();
            return;
        }
        float pct = ofClamp((float)ofGetMouseX() / (float)ofGetWidth(), 0,1);
        int addframe = (fingerMovie.getTotalNumFrames() * pct) - current;
        if( addframe!=0 )
        {
            if( fingerMovie.isFrameNew() )
                fingerMovie.addFrame( addframe );
            fingerMovie.update();
        }
    }

一応これでFullHDのh264とかでも60fpsでseekできた。

ofVideoPlayer(ofAVFoundationVideoPlayer)でのsetPosition,setFrame時にはrateを0にする

void skipFrame(int frames)
{
    player.setSpeed(0.);
    player.setFrame(frames);
    player.setSpeed(1.);
}

OSX 10.11, 10.12 etcでofVideoPlayer使用時(== ofAVFoundationVideoPlayer)のsetPositionなどのseek操作時にはupdate rateを0にするためsetSpeed(0.)を使う。忘れない。。

後からlocal_addonsに手動で突っ込むときに消すものリスト(よく使うaddons)

ofxOpenCv (OtherLinkerFlagsに/libs/opencv/lib/osx/opencv.a 入れて /libs/opencv/include 以外全消し)
ofxAssimpModelLoader (OtherLinkerFlagsに/libs/assimp/lib/osx/assimp.a 入れて /libs/assimp/include 以外全消し)
ofxMessagePack (/libs/msgpack-c/src,include 以外全消し)
ofxAlembic (/libs/alembic/lib 全消し)
ofxTurboJpeg (/libs/turbo-jpeg/lib/osx/libturbojpeg.dylib を OtherLinkerFlagsとCopyFilesにも突っ込む LinkBinary With Libraries から外す)
ofxCv ( ofxOpenCv/libs/opencv/include, ofxCv/src, ofxCv/libs/ofxCv/include, ofxCv/libs/CLD/include/CLD を HeaderSearchPathに突っ込む )
ofxDLib ( ofxDLib/libs/dlib/all ディレクトリ以外全消し opt/X11/include を HeaderSearchPathに突っ込む )

addons突っ込んでコンパイル通らなかったら書き足してく。。忘れない。。

3次元での座標回転(Node, Matrix4x4 or Quaternion 使用)

ofMatrix4x4 mat4;
ofNode node;
ofVec3f p;
ofQuaternion quat;

p = ofVec3f(100,300,0);
node.setPosition( p );
node.lookAt( ofVec3f::zero() );
mat4.makeRotationMatrix( 90., node.getUpDir() );
p = mat4.postMult( p );  // 原点を中心にNodeの垂直方向軸を90度回転させた値

// Quaternionの場合も同じ
// quat.makeRotate( 90., node.getUpDir() );
// p = quat*p;

scale,translateなどを入れる時は新たなMatrix4x4をmakeしてmatrixの乗算したものを使う。忘れない。。

Shaderに渡すgetDepthTexture用のFboSettingsにはdepthStencilAsTextureを忘れない。

ofEnableArbTex();
{
      ofFbo::Settings s;
      s.width = WIDTH;
      s.height = HEIGHT;
      s.internalformat = GL_RGBA;
      s.useDepth = true;
      s.depthStencilAsTexture = true;
      s.depthStencilInternalFormat = GL_DEPTH_COMPONENT16;
      // s.numSamples = 4; // depthStencilAsTextureとmultiSamplingは一緒に使えない!!
      shadowViewDepth.allocate(s);
}
ofDisableArbTex();

どこか別のところで間違って一緒にmultiSampling設定とかしてるだけで全部死ぬ。忘れない。。

AlphaBlending + DepthTest を同時に使う時、印面消去にglColorMaskを忘れない。

ofEnableAlphaBlending();
ofEnableDepthTest();
ofSetColor(255);

glColorMask(false, false, false, false); // 全色描画しないけどDepthBufferにだけ書く
{
    ofPushMatrix();
    ofScale(0.999,0.999,0.999); // 描画するオブジェクトより少しだけ小さく書く。
    sphere_mesh.draw();
    ofPopMatrix();
}
glColorMask(true, true, true, true);

sphere_tex.bind();
sphere_mesh.draw();
sphere_tex.unbind();

半透明のテクスチャとか色で描画する時にDepthTestがおかしくなるので、
一旦glColorMaskで描画色を全部切ったオブジェクトでDepthTestを上書き(マスク)すること。忘れない。

ofxCvを使う時にopencv.aへのリンクを忘れない。

/addons/ofxOpenCv/libs/opencv/lib/osx/opencv.a

へのLink Binary With Librariesを忘れない。

ofMeshとかにsyphon textureとかをbindする時にtexcordのサイズ編集を忘れない。

ofVec2f s(WIDTH, HEIGHT);
vector<ofVec2f> &TC = mesh.getTexCoords();
for (int i = 0; i < TC.size(); i++) {
//    TC[i].x *= -1; TC[i].x += 1;  // 左右反転
//    TC[i].y *= -1; TC[i].y += 1;  // 上下
    TC[i] *= s;
}

C4DとかでTextureとしてBakeした時も一緒。マテリアルを反転もしくは上記の上下反転でUV座標変更して
bindすること。忘れない。

ShaderにsetUniformTextureでFBO渡す時にFBO.allocate時のofEnableArbTexを忘れない。

ofDisableArbTex();
uv.loadImage("assets/texture/uv.png");
ofEnableArbTex();
mskFbo.allocate(WIDTH,HEIGHT);

逆にuv.getTextureReference().bind()とかしてやる時にはofDisableArbTexを忘れない。

you