IZ_BOOL Udp::connectTo(const IPv4Endpoint& remoteEp) { VRETURN(isValidSocket(m_socket)); IZ_BOOL result = IZ_FALSE; // 通信ポート・アドレスの設定 sockaddr_in destAddr; { memset(&destAddr, 0, sizeof(destAddr)); destAddr.sin_family = AF_INET; destAddr.sin_port = htons(remoteEp.getPort()); auto address = remoteEp.getAddress(); result = !address.isAny(); VGOTO(result, __EXIT__); char ip[64]; address.toString(ip, COUNTOF(ip)); setIp(destAddr, inet_addr(ip)); } // 接続 result = (connect(m_socket, (const sockaddr*)&destAddr, sizeof(destAddr)) >= 0); if (result) { if (!m_isBindAddr) { // ホスト名取得 sockaddr_in inAddr; int32_t inAddrSize = sizeof(inAddr); result = (getsockname(m_socket, (sockaddr*)&inAddr, &inAddrSize) >= 0); VGOTO(result, __EXIT__); m_isBindAddr = IZ_TRUE; m_host.set(inAddr); } } __EXIT__: if (!result) { IZ_ASSERT(IZ_FALSE); stop(); } return result; }
// 初期化. IZ_BOOL CMonitor::Init() { IZ_BOOL ret = IZ_FALSE; ret = m_LockMutex.Open(); VGOTO(ret, __EXIT__); ret = m_WaitCond.Init(); VGOTO(ret, __EXIT__); __EXIT__: if (!ret) { Destroy(); } return ret; }
CShaderConstTableLite* CShaderConstTableLite::CreateShaderConstTableLite( IMemoryAllocator* allocator, IZ_PCSTR path) { void *buf = ALLOC(allocator, sizeof(CShaderConstTableLite)); VRETURN_NULL(buf != IZ_NULL); IZ_BOOL result = IZ_TRUE; CShaderConstTableLite* instance = new(buf) CShaderConstTableLite; { instance->AddRef(); instance->m_Allocator = allocator; izanagi::CFileInputStream input; result = input.Open(path); VGOTO(result, __EXIT__); void* program = ALLOC(allocator, (size_t)input.GetSize()); result = (program != IZ_NULL); VGOTO(result, __EXIT__); input.Read(program, 0, (size_t)input.GetSize()); // シェーダ定数テーブル取得 HRESULT hr = D3DXGetShaderConstantTable( (const DWORD*)program, &instance->m_ConstTable); result = SUCCEEDED(hr); result = (instance->m_ConstTable != IZ_NULL); IZ_ASSERT(result); FREE(allocator, program); } __EXIT__: if (!result) { SAFE_RELEASE(instance); } return instance; }
// 開始 IZ_BOOL CStateBevelShader::Enter( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::CValue& arg) { IZ_BOOL result = IZ_TRUE; // シェーダ { izanagi::CFileInputStream in; VRETURN(in.Open("data/BevelShader.shd")); m_Shader = izanagi::shader::CShaderBasic::CreateShader<izanagi::shader::CShaderBasic>( allocator, device, &in); VGOTO(result = (m_Shader != IZ_NULL), __EXIT__); } // メッシュ { IZ_UINT flag = izanagi::E_DEBUG_MESH_VTX_FORM_POS | izanagi::E_DEBUG_MESH_VTX_FORM_NORMAL; m_Mesh = BevelShaderMesh::Create( allocator, device, flag, IZ_COLOR_RGBA(0xff, 0xff, 0xff, 0xff), 5.0f, 5.0f, 5.0f); VGOTO(result = (m_Mesh != IZ_NULL), __EXIT__); } __EXIT__: if (!result) { Leave(); } return result; }
/** * インスタンス作成 */ CGraphicsDevice* CGraphicsDevice::CreateGraphicsDevice(IMemoryAllocator* allocator) { if (s_Instance != IZ_NULL) { // 作成済みなので何もしない return s_Instance; } IZ_ASSERT(allocator != IZ_NULL); IZ_BOOL result = IZ_TRUE; IZ_UINT8* buf = IZ_NULL; CGraphicsDeviceGLES2* instance = IZ_NULL; // メモリ確保 buf = (IZ_UINT8*)ALLOC_ZERO(allocator, sizeof(CGraphicsDeviceGLES2)); VGOTO(buf != IZ_NULL, __EXIT__); // インスタンス作成 instance = new(buf) CGraphicsDeviceGLES2; { instance->m_Allocator = allocator; instance->AddRef(); } if (!result) { goto __EXIT__; } s_Instance = instance; __EXIT__: if (!result) { if (instance != IZ_NULL) { SAFE_RELEASE(instance); } else if (buf != IZ_NULL) { allocator->Free(buf); } } return instance; }
IZ_BOOL LoadTextureJob::OnRun() { #if 0 if (!m_TargetItem->IsShown()) { return IZ_FALSE; } #endif // Open file. izanagi::CFileInputStream input; //VRETURN(input.Open(m_Path)); if (!input.Open(m_Path)) { return IZ_FALSE; } // Read to memory. IZ_UINT8* buf = (IZ_UINT8*)ALLOC(m_InternalAllocator, input.GetSize()); size_t size = input.GetSize(); VRETURN(buf != IZ_NULL); input.Read(buf, 0, size); input.Close(); // Read jpeg. jpeg_decompress_struct cinfo; jpeg_error_mgr jerror; cinfo.err = jpeg_std_error(&jerror); jpeg_create_decompress(&cinfo); jpeg_mem_src(&cinfo, buf, size); jpeg_read_header(&cinfo, IZ_TRUE); jpeg_start_decompress(&cinfo); // Alloc buffer to store line data. IZ_UINT pitch = cinfo.output_width * cinfo.output_components; IZ_UINT8* lineData = (IZ_UINT8*)ALLOC(m_InternalAllocator, pitch + 10); VGOTO(lineData != IZ_NULL, __EXIT__); // Convert to RGBA8 format. const IZ_UINT bpp = izanagi::graph::CGraphUtil::GetBPP(izanagi::graph::E_GRAPH_PIXEL_FMT_RGBA8); const IZ_UINT stride = bpp * cinfo.output_width; // Alloc buffer to store rgba data. IZ_UINT bytes = cinfo.output_width * cinfo.output_height * bpp; m_PixelData = (IZ_UINT8*)ALLOC(m_InternalAllocator, bytes); VGOTO(m_PixelData != IZ_NULL, __EXIT__); IZ_BOOL ret = IZ_TRUE; IZ_UINT8* dst = m_PixelData; while(cinfo.output_scanline < cinfo.output_height) { IZ_UINT8* buffer[1]; buffer[0] = (IZ_UINT8*)lineData; jpeg_read_scanlines(&cinfo, buffer, 1); // Convert to rgba. for (IZ_UINT i = 0; i < cinfo.output_width; i++) { dst[i * 4 + 0] = lineData[i * 3 + 2]; dst[i * 4 + 1] = lineData[i * 3 + 1]; dst[i * 4 + 2] = lineData[i * 3 + 0]; dst[i * 4 + 3] = 0xff; } dst += stride; } // Keep image size. m_TexWidth = cinfo.output_width; m_TexHeight = cinfo.output_height; __EXIT__: jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); FREE(m_InternalAllocator, buf); FREE(m_InternalAllocator, lineData); // If this job is canceld... if (IsCanceled()) { ret = IZ_FALSE; } return ret; }
// 初期化. IZ_BOOL CMotionBindApp::InitInternal( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::sample::CSampleCamera& camera) { IZ_BOOL result = IZ_TRUE; // Texture { izanagi::CFileInputStream in; VRETURN(in.Open("data/MikuImage.img")); m_Img = izanagi::CImage::CreateImage( allocator, device, &in); VGOTO(result = (m_Img != IZ_NULL), __EXIT__); } // Animation for (IZ_UINT i = 0; i < COUNTOF(ANM_FILE_NAME); i++) { izanagi::CFileInputStream in; VRETURN(in.Open(ANM_FILE_NAME[i])); m_Anm[i] = izanagi::CAnimation::CreateAnimation( allocator, &in); VGOTO(result = (m_Anm[i] != IZ_NULL), __EXIT__); } // Mesh { izanagi::CFileInputStream in; VRETURN(in.Open(MSH_FILE_NAME)); m_Msh = izanagi::CMesh::CreateMesh( allocator, device, &in); VGOTO(result = (m_Msh != IZ_NULL), __EXIT__); } // Skelton { izanagi::CFileInputStream in; VRETURN(in.Open(SKL_FILE_NAME)); m_Skl = izanagi::CSkeleton::CreateSkeleton( allocator, &in); VGOTO(result = (m_Skl != IZ_NULL), __EXIT__); } // 独自の補間計算を設定 izanagi::CAnimation::SetUserFuncInterpScalar(CCustomInterp::InterpScalar); izanagi::CAnimation::SetUserFuncInterpVector(CCustomInterp::InterpVector); // アニメーションバインド { m_AnmBinder = izanagi::CAnimationBinder::CreateAnimationBinder( allocator, m_Skl); IZ_ASSERT(m_AnmBinder != IZ_NULL); for (IZ_UINT i = 0; i < COUNTOF(UpperBodyIdx); i++) { m_AnmBinder->BindByIdx(UpperBodyIdx[i], m_Anm[1]); } for (IZ_UINT i = 0; i < COUNTOF(LowerBodyIdx); i++) { m_AnmBinder->BindByIdx(LowerBodyIdx[i], m_Anm[0]); } } // Timeline { m_Timeline.Init( m_AnmBinder->GetAnimationTime(), 0.0f); m_Timeline.EnableLoop(IZ_TRUE); m_Timeline.AutoReverse(IZ_FALSE); m_Timeline.Start(); m_Timeline.Reset(); } // Shader { izanagi::CFileInputStream in; VRETURN(in.Open("data/SkinShader.shd")); m_Shd = izanagi::shader::CShaderBasic::CreateShader<izanagi::shader::CShaderBasic>( allocator, device, &in); VGOTO(result = (m_Shd != IZ_NULL), __EXIT__); // ジョイントマトリクスを描画時に設定するためのハンドラ s_MdlRenderHandler = izanagi::IMshRenderHandler::CreateMshRenderHandler<izanagi::sample::CSampleMdlRenderHandler>(allocator); s_MdlRenderHandler->SetShader(m_Shd); VGOTO(result = (s_MdlRenderHandler != IZ_NULL), __EXIT__); } // Model { m_Mdl = izanagi::CModel::CreateModel( allocator, m_Msh, m_Skl, s_MdlRenderHandler); VGOTO(result = (m_Mdl != IZ_NULL), __EXIT__); } // Material { izanagi::CFileInputStream in; IZ_CHAR tmp[32]; for (IZ_UINT i = 0; i < COUNTOF(m_Mtrl); i++) { IZ_SPRINTF(tmp, sizeof(tmp), "data/miku_%d.mtrl\0", i); VRETURN(in.Open(tmp)); m_Mtrl[i] = izanagi::CMaterial::CreateMaterial(allocator, &in); VGOTO((result = m_Mtrl[i] != IZ_NULL), __EXIT__); in.Finalize(); } // シェーダ名を強制的に設定 m_Shd->SetName("DefaultShader"); for (IZ_UINT i = 0; i < COUNTOF(m_Mtrl); i++) { IZ_UINT num = m_Mtrl[i]->GetTexNum(); IZ_PCSTR name = m_Mtrl[i]->GetTexInfoByIdx(num > 1 ? 1 : 0)->name.GetString(); IZ_BOOL isToon = (::strncmp(name, "toon", 4) == 0); m_Mtrl[i]->SetTexture(name, m_Img->GetTexture(isToon ? 0 : 1)); m_Mtrl[i]->SetShader(m_Shd); m_Mdl->SetMaterial(0, m_Mtrl[i]); } } // レンダーグラフ m_RenderGraph = izanagi::CRenderGraph::CreateRenderGraph(allocator, 5); VGOTO(result = (m_RenderGraph != IZ_NULL), __EXIT__); // レンダラ m_Renderer = izanagi::CSceneRenderer::CreateSceneRenderer(allocator); VGOTO(result = (m_Renderer != IZ_NULL), __EXIT__); // カメラ camera.Init( izanagi::math::CVector4(0.0f, 5.0f, CAMERA_Z, 1.0f), izanagi::math::CVector4(0.0f, 5.0f, 0.0f, 1.0f), izanagi::math::CVector4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 500.0f, izanagi::math::CMath::Deg2Rad(60.0f), (IZ_FLOAT)device->GetBackBufferWidth() / device->GetBackBufferHeight()); camera.Update(); __EXIT__: if (!result) { ReleaseInternal(); } return IZ_TRUE; }
// 初期化. IZ_BOOL FoveatedRenderingApp::InitInternal( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::sample::CSampleCamera& camera) { IZ_BOOL result = IZ_TRUE; IZ_UINT flag = izanagi::E_DEBUG_MESH_VTX_FORM_POS; // Cube { m_Cube = izanagi::sample::CSampleEnvBox::CreateSampleEnvBox( allocator, device); VGOTO(result = (m_Cube != IZ_NULL), __EXIT__); } // テクスチャ { izanagi::CFileInputStream in; VGOTO(result = in.Open("data/EnvMap.img"), __EXIT__); m_Img = izanagi::CImage::CreateImage( allocator, device, &in); VGOTO(result = (m_Img != IZ_NULL), __EXIT__); } // FBO. { m_rt = device->CreateRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, izanagi::graph::E_GRAPH_PIXEL_FMT_RGBA8); m_depth = device->CreateRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, izanagi::graph::E_GRAPH_PIXEL_FMT_D24S8); m_mask = device->CreateRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, izanagi::graph::E_GRAPH_PIXEL_FMT_RGBA8); } m_shdDrawCube.Init( device, "shader/vs_equirect.glsl", "shader/fs_equirect.glsl"); m_shdMakeMask.Init( device, "shader/vs_2dscreen.glsl", "shader/fs_radicaldensitymask.glsl"); m_shdFilter.Init( device, "shader/vs_2dscreen.glsl", "shader/fs_filter.glsl"); IZ_FLOAT aspect = (IZ_FLOAT)SCREEN_WIDTH / SCREEN_HEIGHT; IZ_FLOAT verticalFOV = izanagi::math::CMath::Deg2Rad(60.0f); // カメラ camera.Init( izanagi::math::CVector4(0.0f, 0.0f, 0.0f, 1.0f), izanagi::math::CVector4(0.0f, 0.0f, 1.0f, 1.0f), izanagi::math::CVector4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 500.0f, verticalFOV, aspect); camera.Update(); __EXIT__: if (!result) { ReleaseInternal(); } return IZ_TRUE; }
// 初期化. IZ_BOOL StereoCameraApp::InitInternal( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::sample::CSampleCamera& camera) { IZ_BOOL result = IZ_TRUE; IZ_UINT flag = izanagi::E_DEBUG_MESH_VTX_FORM_POS; // Cube { m_Cube = izanagi::sample::CSampleEnvBox::CreateSampleEnvBox( allocator, device); VGOTO(result = (m_Cube != IZ_NULL), __EXIT__); } // テクスチャ { izanagi::CFileInputStream in; VGOTO(result = in.Open("data/EnvMap.img"), __EXIT__); m_Img = izanagi::CImage::CreateImage( allocator, device, &in); VGOTO(result = (m_Img != IZ_NULL), __EXIT__); } // シェーダ { izanagi::CFileInputStream in; VGOTO(result = in.Open("shader/vs_equirect.glsl"), __EXIT__); std::vector<uint8_t> buf(in.GetSize() + 1); in.Read(&buf[0], 0, in.GetSize()); m_vs = device->CreateVertexShader(&buf[0]); VGOTO(result = (m_vs != IZ_NULL), __EXIT__); } { izanagi::CFileInputStream in; VGOTO(result = in.Open("shader/fs_equirect.glsl"), __EXIT__); std::vector<uint8_t> buf(in.GetSize() + 1); in.Read(&buf[0], 0, in.GetSize()); m_fs = device->CreatePixelShader(&buf[0]); VGOTO(result = (m_fs != IZ_NULL), __EXIT__); } { m_shd = device->CreateShaderProgram(); m_shd->AttachVertexShader(m_vs); m_shd->AttachPixelShader(m_fs); } // カメラ camera.Init( izanagi::math::CVector4(0.0f, 0.0f, 0.0f, 1.0f), izanagi::math::CVector4(0.0f, 0.0f, 1.0f, 1.0f), izanagi::math::CVector4(0.0f, 1.0f, 0.0f, 1.0f), 0.01f, 5.0f, izanagi::math::CMath::Deg2Rad(90.0f), (IZ_FLOAT)device->GetBackBufferWidth() / device->GetBackBufferHeight()); camera.Update(); __EXIT__: if (!result) { ReleaseInternal(); } return IZ_TRUE; }
// 初期化. IZ_BOOL CMouseHit::InitInternal( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::sample::CSampleCamera& camera) { IZ_BOOL result = IZ_TRUE; static const izanagi::math::SVector4 triPoint[3] = { { -10.0f, 0.0f, 0.0f, 1.0f }, { -10.0f, 0.0f, 20.0f, 1.0f }, { 10.0f, 0.0f, 20.0f, 1.0f }, }; static const izanagi::graph::SVertexElement vtxElem[] = { {0, 0, izanagi::graph::E_GRAPH_VTX_DECL_TYPE_FLOAT4, izanagi::graph::E_GRAPH_VTX_DECL_USAGE_POSITION, 0}, // 座標 {0, 16, izanagi::graph::E_GRAPH_VTX_DECL_TYPE_COLOR, izanagi::graph::E_GRAPH_VTX_DECL_USAGE_COLOR, 0}, // 色 }; { izanagi::math::SMatrix44::SetUnit(m_Triangles.mtx); m_Triangles.tri.Set(triPoint); m_Triangles.vb = device->CreateVertexBuffer( sizeof(SVertex), 3, izanagi::graph::E_GRAPH_RSC_TYPE_STATIC); SVertex* data = IZ_NULL; m_Triangles.vb->Lock(0, 0, (void**)&data, IZ_FALSE); { for (IZ_UINT i = 0; i < 3; i++) { izanagi::math::SVector4::Copy(data[i].pos, triPoint[i]); data[i].color = 0xffffffff; } } m_Triangles.vb->Unlock(); m_VD = device->CreateVertexDeclaration(vtxElem, COUNTOF(vtxElem)); } // シェーダ { izanagi::CFileInputStream in; VGOTO(result = in.Open("data/BasicShader.shd"), __EXIT__); m_Shader = izanagi::CShaderBasic::CreateShader<izanagi::CShaderBasic>( allocator, device, &in); VGOTO(result = (m_Shader != IZ_NULL), __EXIT__); } // カメラ camera.Init( izanagi::math::CVector4(0.0f, 5.0f, -30.0f, 1.0f), izanagi::math::CVector4(0.0f, 5.0f, 0.0f, 1.0f), izanagi::math::CVector4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 500.0f, izanagi::math::CMath::Deg2Rad(60.0f), (IZ_FLOAT)SCREEN_WIDTH / SCREEN_HEIGHT); camera.Update(); __EXIT__: if (!result) { ReleaseInternal(); } return IZ_TRUE; }
// 初期化. IZ_BOOL CResourceManagerApp::InitInternal( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device, izanagi::sample::CSampleCamera& camera) { IZ_BOOL result = IZ_TRUE; m_RscMgr = izanagi::resource::CResourceManager::CreateResourceManager(allocator); IZ_ASSERT(m_RscMgr != IZ_NULL); izanagi::CMesh* msh = IZ_NULL; izanagi::CSkeleton* skl = IZ_NULL; // Texture { izanagi::CFileInputStream in; VRETURN(in.Open("data/ModelImage.img")); izanagi::CImage* img = izanagi::CImage::CreateImage( allocator, device, &in); VGOTO(result = (img != IZ_NULL), __EXIT__); m_RscMgr->Add( img, IZ_CC3('i', 'm', 'g'), izanagi::CKey("ModelImage.img")); // ResourceManagerに登録したのでもういらない SAFE_RELEASE(img); } // Mesh { izanagi::CFileInputStream in; VRETURN(in.Open("data/Seymour.msh")); msh = izanagi::CMesh::CreateMesh( allocator, device, &in); VGOTO(result = (msh != IZ_NULL), __EXIT__); } // Skelton { izanagi::CFileInputStream in; VRETURN(in.Open("data/Seymour.skl")); skl = izanagi::CSkeleton::CreateSkeleton( allocator, &in); VGOTO(result = (skl != IZ_NULL), __EXIT__); } // Shader { izanagi::CFileInputStream in; VRETURN(in.Open("data/SkinShader.shd")); izanagi::shader::CShaderBasic* shd = izanagi::shader::CShaderBasic::CreateShader<izanagi::shader::CShaderBasic>( allocator, device, &in); VGOTO(result = (shd != IZ_NULL), __EXIT__); // ジョイントマトリクスを描画時に設定するためのハンドラ s_MdlRenderHandler = izanagi::IMshRenderHandler::CreateMshRenderHandler<izanagi::sample::CSampleMdlRenderHandler>(allocator); s_MdlRenderHandler->SetShader(shd); VGOTO(result = (s_MdlRenderHandler != IZ_NULL), __EXIT__); m_RscMgr->Add( shd, IZ_CC3('s', 'h', 'd'), izanagi::CKey("SkinShader.shd")); // ResourceManagerに登録したのでもういらない SAFE_RELEASE(shd); } // Model { izanagi::CModel* mdl = izanagi::CModel::CreateModel( allocator, msh, skl, s_MdlRenderHandler); VGOTO(result = (mdl != IZ_NULL), __EXIT__); // Modelに登録したのでもういらない SAFE_RELEASE(msh); SAFE_RELEASE(skl); m_RscMgr->Add( mdl, IZ_CC3('m', 'd', 'l'), izanagi::CKey("Seymour.mdl")); // ResourceManagerに登録したのでもういらない SAFE_RELEASE(mdl); } // カメラ camera.Init( izanagi::math::CVector4(0.0f, 5.0f, 30.0f, 1.0f), izanagi::math::CVector4(0.0f, 5.0f, 0.0f, 1.0f), izanagi::math::CVector4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 500.0f, izanagi::math::CMath::Deg2Rad(60.0f), (IZ_FLOAT)device->GetBackBufferWidth() / device->GetBackBufferHeight()); camera.Update(); __EXIT__: if (!result) { ReleaseInternal(); } return IZ_TRUE; }
IZ_BOOL CMdlExporter::Export( IZ_UINT maxJointMtxNum, IZ_PCSTR lpszOutFile, IImporter* pImporter) { IZ_BOOL ret = IZ_TRUE; VRETURN(m_Out.Open(lpszOutFile)); izanagi::S_MDL_HEADER sHeader; { FILL_ZERO(&sHeader, sizeof(sHeader)); sHeader.sizeHeader = sizeof(sHeader); } // Blank for file's header. izanagi::tool::CIoStreamSeekHelper cSeekHelper(&m_Out); VGOTO(ret = cSeekHelper.Skip(sizeof(sHeader)), __EXIT__); #if 0 #if 1 // geometry chunk ret = CGeometryChunk::GetInstance().Export( &m_Out, pImporter); CGeometryChunk::GetInstance().Clear(); VGOTO(ret, __EXIT__); #endif #if 1 // joint chunk ret = CJointChunk::Export( &m_Out, pImporter); VGOTO(ret, __EXIT__); #endif // Export terminater. { izanagi::S_MDL_CHUNK_HEADER sChunkHeader; sChunkHeader.magicChunk = izanagi::MDL_CHUNK_MAGIC_TERMINATE; IZ_OUTPUT_WRITE_VRETURN(&m_Out, &sChunkHeader, 0, sizeof(sChunkHeader)); } // Export files's header. { sHeader.sizeFile = m_Out.GetCurPos(); const izanagi::math::SVector4& vMin = CGeometryChunk::GetInstance().GetMin(); const izanagi::math::SVector4& vMax = CGeometryChunk::GetInstance().GetMax(); sHeader.minVtx[0] = vMin.x; sHeader.minVtx[1] = vMin.y; sHeader.minVtx[2] = vMin.z; sHeader.maxVtx[0] = vMax.x; sHeader.maxVtx[1] = vMax.y; sHeader.maxVtx[2] = vMax.z; VRETURN(cSeekHelper.Return()); IZ_OUTPUT_WRITE_VRETURN(&m_Out, &sHeader, 0, sizeof(sHeader)); } #else // Mesh chunk. { izanagi::S_MDL_CHUNK_HEADER sChunkHeader; sChunkHeader.magicChunk = izanagi::MDL_CHUNK_MAGIC_MESH; ret = IZ_OUTPUT_WRITE(&m_Out, &sChunkHeader, 0, sizeof(sChunkHeader)); VGOTO(ret, __EXIT__); ret = CGeometryChunk::GetInstance().Export( maxJointMtxNum, &m_Out, pImporter); } // Skeleton chunk. { izanagi::S_MDL_CHUNK_HEADER sChunkHeader; sChunkHeader.magicChunk = izanagi::MDL_CHUNK_MAGIC_SKELETON; ret = IZ_OUTPUT_WRITE(&m_Out, &sChunkHeader, 0, sizeof(sChunkHeader)); VGOTO(ret, __EXIT__); ret = CJointChunk::Export( &m_Out, pImporter); } // Export terminater. { izanagi::S_MDL_CHUNK_HEADER sChunkHeader; sChunkHeader.magicChunk = izanagi::MDL_CHUNK_MAGIC_TERMINATE; ret = IZ_OUTPUT_WRITE(&m_Out, &sChunkHeader, 0, sizeof(sChunkHeader)); VGOTO(ret, __EXIT__); } // Export files's header. { sHeader.sizeFile = m_Out.GetCurPos(); VGOTO(ret = cSeekHelper.Return(), __EXIT__); ret = IZ_OUTPUT_WRITE(&m_Out, &sHeader, 0, sizeof(sHeader)); VGOTO(ret, __EXIT__); } #endif __EXIT__: m_Out.Finalize(); return ret; }
IZ_BOOL UnityChanApp::initModel( izanagi::IMemoryAllocator* allocator, izanagi::graph::CGraphicsDevice* device) { IZ_BOOL result = IZ_FALSE; static const char* imgPath = "data/UnityChanImg.img"; static const char* mshPath = "data/unitychan.msh"; static const char* sklPath = "data/unitychan.skl"; static const char* shdPath = "data/SkinShader.shd"; // Texture { izanagi::CFileInputStream in; VRETURN(in.Open(imgPath)); m_Img = izanagi::CImage::CreateImage( allocator, device, &in); VGOTO(result = (m_Img != IZ_NULL), __EXIT__); } // Mesh { izanagi::CFileInputStream in; VRETURN(in.Open(mshPath)); m_Msh = izanagi::CMesh::CreateMesh( allocator, device, &in); VGOTO(result = (m_Msh != IZ_NULL), __EXIT__); } // Skelton { izanagi::CFileInputStream in; VRETURN(in.Open(sklPath)); m_Skl = izanagi::CSkeleton::CreateSkeleton( allocator, &in); VGOTO(result = (m_Skl != IZ_NULL), __EXIT__); } // Shader { izanagi::CFileInputStream in; VRETURN(in.Open(shdPath)); m_Shd = izanagi::shader::CShaderBasic::CreateShader<izanagi::shader::CShaderBasic>( allocator, device, &in); VGOTO(result = (m_Shd != IZ_NULL), __EXIT__); // ジョイントマトリクスを描画時に設定するためのハンドラ m_MdlRenderHandler = izanagi::IMshRenderHandler::CreateMshRenderHandler<izanagi::sample::CSampleMdlRenderHandler>(allocator); m_MdlRenderHandler->SetShader(m_Shd); VGOTO(result = (m_MdlRenderHandler != IZ_NULL), __EXIT__); } // Model { m_Mdl = izanagi::CModel::CreateModel( allocator, m_Msh, m_Skl, m_MdlRenderHandler); VGOTO(result = (m_Mdl != IZ_NULL), __EXIT__); } // レンダーグラフ m_RenderGraph = izanagi::CRenderGraph::CreateRenderGraph(allocator, 5); VGOTO(result = (m_RenderGraph != IZ_NULL), __EXIT__); // レンダラ m_Renderer = izanagi::CSceneRenderer::CreateSceneRenderer(allocator); VGOTO(result = (m_Renderer != IZ_NULL), __EXIT__); CreateMaterial(allocator); __EXIT__: return result; }