サンプル

UV アニメーション

UV アニメーション - MascotCapsule eruption

ここでは UV アニメーションについて解説します。




※ 開発環境によってダウンロードするサンプルデータが異なります。

目次





モデルにマッピングされているテクスチャの UV 座標を変更する機能で、テクスチャ自体の張り替えの変更をすることなく、見た目を変化させることができます。


1. UV アニメーションの設定

mceAppearance_getTransform( This, ix, dst ) を使用して mceTransform を取得し、mceAppearance_setTransform( This, ix, src ) を使用して UV 座標の設定を行います。

typedef struct tagWork
{
    (中略)

    mceFigure       *Figure;    /* Figure       */
    mceTextureTable *Textbl;    /* TextureTable */
    mceAppearance   *Appe;      /* Appearance   */

/*------ UVアニメーション ------*/

    hi_coord TextureU;          /* テクスチャーU軸座標 */
    hi_coord TextureV;          /* テクスチャーV軸座標 */

} WORK;
hi_exception exception;

    (中略)

exception = mceFigure_bindTexture (work->Figure, work->Textbl);
if (exception != hi_NoException)
{
    return 1;
}

    (中略)

work->TextureU = MCE_F2C (0.0f);
work->TextureV = MCE_F2C (0.0f);

    (中略)

mceTransform matrix;

    (中略)

/*------ UVアニメーション ------*/

work->Appe = (mceAppearance *)mceObject3D_findObject3D (
                                      (mceObject3D *)work->Figure,
                                      ClassId_Appearance,
                                      0);
if (work->Appe == NULL)
{
    return 1;
}

/* mceApearanceからUV座標の変換行列を取得 */
exception = mceAppearance_getTransform (work->Appe, 0, &matrix);
if (exception != hi_NoException)
{
    return 1;
}

/* 取得した変換行列の平行移動成分を変更 */
mceTransform_setTranslate (&matrix,
                           work->TextureU, work->TextureV, MCE_F2C (0.0f));

/* mceAppearanceにUV座標の変換行列を設定 */
exception = mceAppearance_setTransform (work->Appe, 0, &matrix);
if (exception != hi_NoException)
{
    return 1;
}

対象モデルに対する UV 座標がテスクチャの範囲外になった場合は、ラッピングモードの設定により、描画結果が異なります。ラッピングモードの設定は、mceAppearance_setTextureWrapMode( This, ix, wrapS, wrapT ) を使用して行います。初期設定では MCE_TEXTURE_WRAP_REPEAT に設定されています。
ラッピングモードの設定は以下の 2 種類です。


hi_exception exception;

/* ラッピングモードをMCE_TEXTURE_WRAP_CLAMPに設定 */
exception = mceAppearance_setTextureWrapMode(work->Appe,
                                             0,
                                             MCE_TEXTURE_WRAP_CLAMP,
                                             MCE_TEXTURE_WRAP_CLAMP);
if (exception != hi_NoException)
{
    return 1;
}
描画結果 U 方向の座標 0.0 、V 方向の座標 0.0 描画結果 U 方向の座標 0.15 、V 方向の座標 0.75
U 方向の座標 0.0 、V 方向の座標 0.0 U 方向の座標 0.15 、V 方向の座標 0.75
描画結果
( テクスチャラッピングモードは全て MCE_TEXTURE_WRAP_REPEAT )



このページの先頭へ戻る