00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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 }
00118