Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

# TranslationRigidMesh.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * 変換剛体メッシュ実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "System/stdafx.h"
    00026 #include "Translator/Mesh/TranslationRigidMesh.h"
    00027 #include "Graphics/Scene/Scene.h"
    00028 #include "Graphics/Mesh/MeshManager.h"
    00029 #include "Graphics/MeshData/MeshDataManager.h"
    00030 #include "Graphics/Material/MaterialManager.h"
    00031
    00032 namespace LampForMaya{
    00033
    00034 //------------------------------------------------------------------------------
    00035 // コンストラクタ
    00036 TranslationRigidMesh::TranslationRigidMesh(const String& initializeName) :
    00037     TranslationMesh(initializeName){
    00038 }
    00039 //------------------------------------------------------------------------------
    00040 // デストラクタ
    00041 TranslationRigidMesh::~TranslationRigidMesh(){
    00042 }
    00043 //------------------------------------------------------------------------------
    00044 // 論理チェック
    00045 bool TranslationRigidMesh::logicalCheck(){
    00046     if(!vertexLogicalCheck()){ return false; }
    00047     return true;
    00048 }
    00049 //------------------------------------------------------------------------------
    00050 // ピボットのコンパイル
    00051 void TranslationRigidMesh::compilePivot(const Vector3& pivot){
    00052     int vertexCount = positions_.getCount();
    00053     for(int i = 0; i < vertexCount; i++){
    00054         Vector3 position = positions_.get(i);
    00055         position -= pivot;
    00056         positions_.set(i, position);
    00057     }
    00058 }
    00059 //------------------------------------------------------------------------------
    00060 // Lampへの変換
    00061 bool TranslationRigidMesh::convertToLamp(Scene* scene){
    00062     MeshManager* meshManager = scene->getMeshManager();
    00063     RigidMesh* mesh = meshManager->createRigidMesh(name_);
    00064     // メッシュデータ
    00065     MeshDataManager* meshDataManager = scene->getMeshDataManager();
    00066     String meshDataName(name_);
    00067     meshDataName.append("d");
    00068     MeshData* meshData = meshDataManager->createMeshData(meshDataName);
    00069     mesh->setMeshData(meshData);
    00070     // 情報設定
    00071     mesh->setPrimitiveType(Mesh::triangleList);
    00072     int vertexCount = positions_.getCount();
    00073     mesh->setVertexCount(vertexCount);
    00074     mesh->enableNormal(true);
    00075     for(int i = 0; i < vertexCount; i++){
    00076         mesh->setPosition(i, positions_[i]);
    00077         mesh->setNormal(i, normals_[i]);
    00078     }
    00079     if(colors_.getCount() != 0){
    00080         mesh->enableColor(true);
    00081         for(int i = 0; i < vertexCount; i++){
    00082             Color4c color(colors_[i]);
    00083             mesh->setColor(i, color);
    00084         }
    00085     }
    00086     if(uvs_.getCount() != 0){
    00087         mesh->setTexCoordSetCount(uvSetCount_);
    00088         for(int i = 0; i < uvSetCount_; i++){
    00089             mesh->setTexCoordType(i, TexCoord::type2);
    00090         }
    00091         int uvIndex = 0;
    00092         int polygonCount = vertexCount / 3;
    00093         for(int i = 0; i < polygonCount; i++){
    00094             int vertexOffset = i * 3;
    00095             for(int j = 0; j < uvSetCount_; j++){
    00096                 mesh->setTexCoord2(vertexOffset + 0, j, uvs_[uvIndex]);
    00097                 uvIndex++;
    00098                 mesh->setTexCoord2(vertexOffset + 1, j, uvs_[uvIndex]);
    00099                 uvIndex++;
    00100                 mesh->setTexCoord2(vertexOffset + 2, j, uvs_[uvIndex]);
    00101                 uvIndex++;
    00102             }
    00103         }
    00104     }
    00105     // マテリアルとのリンク
    00106     MaterialManager* materialManager = scene->getMaterialManager();
    00107     Material* material = materialManager->search(materialName_);
    00108     if(material == NULL){
    00109         MayaErrorOut(String("TranslationRigidMesh::convertToLamp() ") + name_ +
    00110             "に接続されているマテリアル" + materialName_ + "が見つかりません ");
    00111         return false;
    00112     }
    00113     mesh->setMaterial(material);
    00114     return true;
    00115 }
    00116 //------------------------------------------------------------------------------
    00117 } // End of namespace LampForMaya
    00118 //------------------------------------------------------------------------------