Пример #1
0
void MDLMeshImporter::CreateShader( NWN::TrimeshGeometryNode* pTrimesh, Mesh* pMesh, Bool pMetallic )
{
    TextureShader* shader = NULL;    

    if( ToLower(pTrimesh->mBitmap) != "null" )
    {
        String textureName = "Data/Textures/";
        if( pTrimesh->mBitmap.find( '.' ) != -1 )
        {
            textureName += pTrimesh->mBitmap;
        }
        else
        {
            textureName += pTrimesh->mBitmap;
            textureName += String(".tga");
        }


        HTexture2D hdl( textureName );

        if( hdl && (hdl->GetFormat() == Image::Format_R8G8B8A8 || hdl->GetFormat() == Image::Format_B8G8R8A8) )
        {
            if( pMetallic )
            {
                //shader = GD_NEW(MetallicShader, this, "MetallicShader");
                //((MetallicShader*)shader)->mReflectionTexture.GetTexture( "Data/Textures/chrome1.tga" );

                shader = GD_NEW(TextureShader, this, "TextureShader");
            }
            else
            {
                shader = GD_NEW(TransparencyTextureShader, this, "TransparencyTextureShader");
            }
        }
        else 
        {
            shader = GD_NEW(TextureShader, this, "TextureShader");
        }
                        
        shader->mTexture = hdl;
    }

    if( !shader )
        shader = GD_NEW(TextureShader, this, "TextureShader");

    shader->mMaterial.mAmbient   = pTrimesh->mAmbient;
    shader->mMaterial.mDiffuse   = pTrimesh->mDiffuse;
    shader->mMaterial.mSpecular  = pTrimesh->mSpecular;
    shader->mMaterial.mShininess = pTrimesh->mShininess;
    shader->mMaterial.mEmissive  = pTrimesh->mEmissive;

    pMesh->mShader = shader;
}
Пример #2
0
void kDOPTree::BuildTree( Vector<Trianglef>& pTriangleSoup, Vector<Vector3f>& pVertices )
{
    // Keep a copy of the vertices and triangles.
    mVertices.resize( pVertices.size() );
    for( UInt32 i = 0; i < pVertices.size(); i++ )
        mVertices[i] = pVertices[i];
            
    mTriangles.resize( pTriangleSoup.size() );
    for( UInt32 i = 0; i < pTriangleSoup.size(); i++ )
    {
        mTriangles[i].mIndices[0] = pTriangleSoup[i].mIndices[0];
        mTriangles[i].mIndices[1] = pTriangleSoup[i].mIndices[1];
        mTriangles[i].mIndices[2] = pTriangleSoup[i].mIndices[2];
    }
    
    mTrianglesCentroids.resize( pTriangleSoup.size() );

    // Find each triangle center.
    for( UInt32 i = 0; i < pTriangleSoup.size(); i++ )
    {
        mTrianglesCentroids[i]  = mVertices[mTriangles[i].mIndices[0]];
        mTrianglesCentroids[i] += mVertices[mTriangles[i].mIndices[1]];
        mTrianglesCentroids[i] += mVertices[mTriangles[i].mIndices[2]];
        mTrianglesCentroids[i] *= (1.0f / 3.0f);
    }

    mNumNodes  = 1;
    mNumLeaves = 0;
    mMaxDepth  = 0;
    mDepth     = 0;

    // Create the root node.
    kDOPNode* root = GD_NEW(kDOPNode, this, "Engine::Collision::kDOPTree");
    mNodes.push_back( root );
    
    // Insert the triangles indices in the root node list.
    root->mTriangleIndices.resize( pTriangleSoup.size() );
    for( UInt32 i = 0; i < pTriangleSoup.size(); i++ )
    {
        root->mTriangleIndices[i] = i;
    }

    // Recursively build kDOP tree.
    BuildNode( root );

    // No need to store centroids.
    mTrianglesCentroids.clear();

/*
#ifdef GD_DEBUG
    // 
    // Report memory usage
    UInt32 memUsage = 0;
    memUsage += (mNodes.size() * 4) + (mNodes.size() * sizeof(kDOPNode));
    memUsage += mVertices.size() * sizeof(mVertices[0]);
    memUsage += mTriangles.size() * sizeof(mTriangles[0]);
    printf( "kDOPTree mem usage = %08d bytes", memUsage );
#endif
*/
}
Пример #3
0
void EditorBase::LoadTools()
{
    ModuleManager::Instance()->LoadModulesInFolder( "Plugins/Tools/" );

    // Create the tools and init their UI;
    Class::Iterator itClassesNew( EditorTool::StaticClass() );
    for( ; itClassesNew.IsValid(); ++itClassesNew )
    {
        EditorTool* newTool = Cast<EditorTool>((*itClassesNew)->AllocateNew());

        try
        {
            newTool->SetEditor(this);

            QWidget* toolWidget = newTool->CreateUI();
            if( toolWidget != mMainView )
            {
                QDockWidget* contentsWindow = GD_NEW(QDockWidget, this, 0)(toolWidget->objectName(), this);
                contentsWindow->setWidget(toolWidget);
                addDockWidget(Qt::LeftDockWidgetArea, contentsWindow);
            }

            newTool->Hide();
            mTools[(*itClassesNew)->GetName()] = newTool;
        }
        catch( Exception& e )
        {
            qWarning( e.GetMessage().c_str() );
            GD_DELETE(newTool);
        }
    }
}
Пример #4
0
void LWOReader::ReadPOLS( UInt32 pChunkSize )
{
    UInt32      dataRead = 0;
    UInt16      numVertex;
    UInt32      polygonType;
    LWPolygon*  newPolygon;
    
    dataRead += ReadID4( polygonType );

    while( dataRead < pChunkSize )
    {   
        newPolygon = GD_NEW(LWPolygon, this, "Polygon");

        dataRead += ReadU2( numVertex );

        newPolygon->mFlags       = (0xFC00 & numVertex) >> 10;                		
		numVertex                = 0x03FF & numVertex;
		        
        newPolygon->mType        = polygonType;
        newPolygon->mVertex      = GD_NEW_ARRAY(LWPolygonVertex, numVertex, this, "Polygon::Vertex");
        newPolygon->mVertexCount = numVertex;

        // Read indices and assign them to each vertex
		for( UInt32 iIndex = 0; iIndex < newPolygon->mVertexCount; iIndex++ )
            dataRead += ReadVX( newPolygon->mVertex[iIndex].mIndex );
        
        GetCurrentLayer()->mPolygonList.mPolygons.push_back( newPolygon );
    }
}
Пример #5
0
    void Init()
    {
        Super::Init();

        mWorld = GD_NEW(World, this, "Launch::Gamedesk");
        mWorld->Init(&mOctree);

        Model3D* pModel = Cast<Model3D>(mWorld->SpawnEntity(Model3D::StaticClass()));
        pModel->SetMesh("link's house.ase");
        pModel->Select(true);

		Keyboard& keyboard = InputSubsystem::GetKeyboard();
		keyboard.AddKeyListener(this, Keyboard::Key_W, Keyboard::Key_Down);
		keyboard.AddKeyListener(this, Keyboard::Key_S, Keyboard::Key_Down);
		keyboard.AddKeyListener(this, Keyboard::Key_A, Keyboard::Key_Down);
		keyboard.AddKeyListener(this, Keyboard::Key_D, Keyboard::Key_Down);
        keyboard.AddKeyListener(this, Keyboard::Key_Escape, Keyboard::Key_Down);
	        
		Mouse& mouse = InputSubsystem::GetMouse();
		mouse.AddMoveListener(this);

        mMainWindow->AddListener(this);

        mFont.GetFont( "Data/Fonts/tahoma.ttf", 14 );
    }
Пример #6
0
LWLayer* LWOReader::GetCurrentLayer()
{
    if( mObject->mLayers.size() == 0 )
        mObject->mLayers.push_back( GD_NEW(LWLayer, this, "Layer") );

    return mObject->mLayers.back();
}
Пример #7
0
void BSPReader::Read( const String& pFileName )
{
    mMemoryFile		 = GD_NEW(MemoryFile, this, "BSPImporter::BSPReader::MemoryFile")( pFileName, true );
	mBSPFile.mData	 = GD_NEW_ARRAY(Byte, mMemoryFile->GetSize(), this, "BSPImporter::BSPReader::BSP Data");
	
	memcpy( mBSPFile.mData, mMemoryFile->GetMemory(), mMemoryFile->GetSize() ); 
	mBSPFile.mHeader = (BSPHeader*)mBSPFile.mData;
}
Пример #8
0
void kDOPTree::BuildNode( kDOPTree::kDOPNode* pNode )
{
    mDepth++;
    
    if( mDepth > mMaxDepth )
        mMaxDepth = mDepth;

    FindBoundingBox( pNode );

    // Test if we're creating a leaf or a node.
    if( pNode->mTriangleIndices.size() > 5 )
    {
        mNumNodes++;

        Float axisMean;
        Axis splitAxis = SelectSplitAxis( pNode->mTriangleIndices, axisMean );

        // Add two nodes.
        kDOPNode* leftNode  = GD_NEW(kDOPNode, this, "Engine::Collision::kDOPTree");
        kDOPNode* rightNode = GD_NEW(kDOPNode, this, "Engine::Collision::kDOPTree");

        pNode->mChildsIndex = mNodes.size();
        
        mNodes.push_back( leftNode );
        mNodes.push_back( rightNode );

        // Split triangles into two list.
        SplitTriangles( pNode, splitAxis, axisMean );

        // No need to store this in nodes.
        pNode->mTriangleIndices.clear();

        // Recursively call build tree.
        BuildNode( leftNode );
        BuildNode( rightNode );
    }
    else
    {
        // No work to do for leaves!
        mNumLeaves++;
    }

    mDepth--;
}
Пример #9
0
Mesh* MDLMeshImporter::CreateMesh( NWN::GeometryNode* pNode, Mesh* pParent, Bool pMetallic )
{
    Mesh* mesh = NULL;

    switch( pNode->GetType() )
    {
    // Trimesh (& danglymesh) have geometry, so create it.
    case NWN::DANGLY_MESH_ID:
    case NWN::TRIMESH_ID:
    
        mesh = GD_NEW(Mesh, this, "Mesh");
        if( ((NWN::TrimeshGeometryNode*)pNode)->mRender && !((NWN::TrimeshGeometryNode*)pNode)->mTransparencyHint )
        {
            CreateGeometry( (NWN::TrimeshGeometryNode*)pNode, mesh );
            CreateShader( (NWN::TrimeshGeometryNode*)pNode, mesh, pMetallic );
        }
        break;
        
    case NWN::EMITTER_ID:
    case NWN::DUMMY_ID:
    case NWN::AABB_ID:
        mesh = GD_NEW(Mesh, this, "Mesh");
        break;
    
    default:
        return NULL;
    }    

    // Create all childs recursivly.
    for( std::map<String,NWN::Node*>::iterator itMap = pNode->mChilds.begin(); itMap != pNode->mChilds.end(); ++itMap )
        CreateMesh( (NWN::GeometryNode*)(itMap->second), mesh, pMetallic );
    
    // Add the new mesh to it's parent (and store his relative position and orientation).
    if( pParent )
	{
		mesh->SetName(pNode->mName);
		//mesh->SetPosition(((NWN::DummyGeometryNode*)pNode)->mPosition);
		//mesh->SetOrientation(Quaternionf( ((NWN::DummyGeometryNode*)pNode)->mRotationVector, ((NWN::DummyGeometryNode*)pNode)->mRotationAngle));
        pParent->AddChild(mesh);
	}

    return mesh;
}
	// ------------------------------------------------------------------------------------------
	//! Creates a 2D text renderer with specified parameters.
	//! @param gfxSamplerStatePtr Pointer for output.
	//! @param gfxSamplerStateCreationInfo Pointer to the sampler state creation information.
	//! @returns Non-negative value if the operation succeeded.
	GDAPI IResult IGraphics2DDirect2DWithFonts::GfxImm_FontCreate(IGraphics2DFont** gfxFontPtr
		, IGraphics2DFontCreationInfo const* const gfxFontCreationInfo)
	{
#if GD_DEBUG
		if (!GD_IGRAPHICS_CHECK_ARGS(GfxImm_FontCreate(gfxFontPtr, gfxFontCreationInfo)))
			return IResult::InvalidArguments;
#endif	// if GD_DEBUG

		*gfxFontPtr = GD_NEW(IGraphics2DDirect2DFont, gfxFontCreationInfo);
		return IResult::Ok;
	}
Пример #11
0
void LWOReader::ReadLAYR( UInt32 pChunkSize )
{
    UInt32      dataRead = 0;
    LWLayer*    newLayer = GD_NEW(LWLayer, this, "Layer");
    
    dataRead += ReadU2( newLayer->mNumber );
    dataRead += ReadU2( newLayer->mFlags );
    dataRead += ReadVEC12( newLayer->mPivot );
    dataRead += ReadS0( newLayer->mName );

    if( dataRead < pChunkSize )
        dataRead += ReadU2( newLayer->mParent );

    mObject->mLayers.push_back( newLayer );
}
Пример #12
0
Variant& ConfigSection::Get( const String& pVarName, Variant pDefaultValue )
{
    Variant*                          variant = NULL;
    Map<String,Variant*>::iterator    itMap = mVars.find( pVarName );
        
    // If we've found the section in our map, return it immediately.
    if( itMap != mVars.end() )
    {
        variant = (*itMap).second;
    }
    // Otherwise we need to create it.
    else
    {
        variant = GD_NEW(Variant, this, "Core::Config::ConfigSection::Variant")( pDefaultValue );
        mVars[pVarName] = variant;
    }

    return *variant;
}
Пример #13
0
ConfigSection& ConfigFile::operator [] ( const String& pSectionName )
{
    ConfigSection*                          section = NULL;
    Map<String,ConfigSection*>::iterator    itMap = mSections.find( pSectionName );
        
    // If we've found the section in our map, return it immediately.
    if( itMap != mSections.end() )
    {
        section = (*itMap).second;
    }
    // Otherwise we need to create it.
    else
    {
        section = GD_NEW(ConfigSection, this, "Core::Config::ConfigFile::ConfigSection")( pSectionName, *this );
        mSections[pSectionName] = section;
    }

    return *section;
}
Пример #14
0
QRenderWindow::QRenderWindow( QWidget* parent, RenderListener* pRenderListener ) : 
    QWidget( parent, 0 ),
    mRefreshRate(0),
    mRenderWindow(NULL),
    mRenderListener(pRenderListener),
    mFPS(0),
    mTime(0),
	mLastTime(0),
	mFrameCount(0)
{
    if( !mRenderWindowClass )
    {
        ConfigFile editorConfig( "editor.cfg" );
        editorConfig.Load();

        String renderWndClassName = editorConfig["RenderWindow"]["ClassName"];

        if( renderWndClassName.empty() )
            throw ConfigFileMissingValueException( "editor.cfg", "RenderWindow", "ClassName", Here );
    
        mRenderWindowClass = ModuleManager::Instance()->LoadClass( renderWndClassName.c_str() );
    }

    RenderWindow::WindowInfo windowInfo;
    windowInfo.mWindowInternal  = (Handle)this;
    windowInfo.mWindowHandle    = (Handle)winId();
    windowInfo.mSize.x          = width();
    windowInfo.mSize.y          = height();
    windowInfo.mFullscreen      = false;

    RenderTarget::Format targetFormat;
    targetFormat.mAlpha         = true;
    targetFormat.mDepth         = true;
    targetFormat.mDoubleBuffer  = true;
    targetFormat.mStencil       = true;
    targetFormat.mStereo        = false;

    mRenderWindow = Cast<RenderWindow>( mRenderWindowClass->AllocateNew() );
    mRenderWindow->Create( windowInfo, targetFormat );
    
    mAVIEncoder = GD_NEW(AVIEncoder, this, "EditorLib::Viewer::QRenderWindow")( this );
}
Пример #15
0
EditorBase::EditorBase( QWidget* parent, const char* name, Qt::WFlags f ) :
    QMainWindow( parent, f ),
    mMainView(0),
    mWorldManager(0),    
    mTime(0),
    mLastTime(0)
{
    mInstance = this;

    setObjectName(name);
    setWindowTitle("Gamedesk Editor");
    statusBar()->showMessage(tr("Ready"));
    
    InitActions();
    InitMenu();

    QBrush bgBrush( QColor( 0, 0, 0 ) );

    mWorldManager = GD_NEW(WorldManager, this, "EditorLib::EditorBase");

    LoadTools();
}
Пример #16
0
    void SetupWindows()
    {
        mMainWindow = GD_NEW(Win32Window, this, "Launch::Gamedesk");
        mMainWindow->Init( "Gamedesk", 800, 600, true, false );
        
        RenderWindow::WindowInfo windowInfo;
        windowInfo.mWindowInternal = (Handle)mMainWindow;
        windowInfo.mWindowHandle   = (Handle)mMainWindow->GetHandle();
        windowInfo.mFullscreen     = mMainWindow->IsFullScreen();
        windowInfo.mSize           = mMainWindow->GetClientSize();
        
        RenderTarget::Format targetFormat;
        targetFormat.mAlpha        = true;
        targetFormat.mDepth        = true;
        targetFormat.mDoubleBuffer = true;
        targetFormat.mStencil      = true;
        targetFormat.mStereo       = false;

        Class* renderWindowClass = ModuleManager::Instance()->LoadClass( "Win32OGLRenderWindow.Win32OGLRenderWindow" );
        mRenderWindow = Cast<RenderWindow>( renderWindowClass->AllocateNew() );
        mRenderWindow->Create( windowInfo, targetFormat );
        mLastTime = SystemInfo::Instance()->GetSeconds();
    }
Пример #17
0
void LWOReader::ReadCLIP( UInt32 pChunkSize )
{
    UInt32  dataRead = 0;
    UInt32  subChunkTag;
    UInt16  subChunkSize;
    UInt32  bytesHold;    

    LWClip* newClip = GD_NEW(LWClip, this, "Clip");

    dataRead += ReadU4( newClip->mIndex );

    // Read all subchunks
    while( dataRead < pChunkSize )
    {
        if( (pChunkSize - dataRead) < 6 )
        {
            dataRead += Skip( pChunkSize - dataRead );
            return;
	    }

        subChunkTag = ReadSubChunk(subChunkSize);
        dataRead += sizeof(subChunkTag);   // Subchunk tag.
        dataRead += sizeof(subChunkSize);  // Subchunk size.

        bytesHold = dataRead;

        switch( subChunkTag )
        {
        case ID_STIL:
            dataRead += ReadS0( newClip->mStillImage ); 
            break;

        case ID_XREF:   
            dataRead += ReadVX( newClip->mXRefIndex ); 
            dataRead += ReadS0( newClip->mXRefInstName ); 
            break;
            
        case ID_ISEQ:
        case ID_ANIM:
        case ID_STCC:
        case ID_TIME:
        case ID_CONT:
        case ID_BRIT:
        case ID_SATR:
        case ID_HUE:
        case ID_GAMM:
        case ID_NEGA:
        case ID_IFLT:
        case ID_PFLT:
        default:        
            dataRead += Skip( subChunkSize );   
            break;
        }

        // Make sure we've read all subchunk bytes (given by the size).
        if( (subChunkSize - dataRead + bytesHold) > 0 )
            dataRead += Skip( subChunkSize - dataRead + bytesHold );
    }

    mObject->mClips.push_back( newClip );
}
Пример #18
0
Resource* ASEImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
    ASEFile aseFile;

    try
    {
        ASE::MeshReader   reader(aseFile);
        reader.Read( pFilename );
    }
    catch( Exception& /*e*/ )
    {
        return NULL;
    }    

    if(aseFile.mGeomObjects.size() == 0)
        return NULL;
	
    Map<const ASEFile::Material*, ASESubMesh> mSubMeshes; 
    GenerateSubMeshes(aseFile, mSubMeshes);

    // Create mesh instance
    Mesh* newMesh = Cast<Mesh>(GraphicSubsystem::Instance()->Create( Mesh::StaticClass() ));
    
    // Create all submeshes
    Map<const ASEFile::Material*, ASESubMesh>::const_iterator itSubMesh;
    Map<const ASEFile::Material*, ASESubMesh>::const_iterator itSubMeshBegin = mSubMeshes.begin();
    Map<const ASEFile::Material*, ASESubMesh>::const_iterator itSubMeshEnd = mSubMeshes.end();
    for(itSubMesh = itSubMeshBegin; itSubMesh != itSubMeshEnd; ++itSubMesh)
    {
        const ASEFile::Material& mat = *(*itSubMesh).first;
        const ASESubMesh& aseSubMesh = (*itSubMesh).second;

        // Create the sub mesh
        Mesh* subMesh = Cast<Mesh>(GraphicSubsystem::Instance()->Create( Mesh::StaticClass() ));
        newMesh->AddChild(subMesh);

        // Create VB
	    subMesh->GetVertexList().Allocate( aseSubMesh.mVertices.size(), (VertexFormat::Component) (VertexFormat::Position3 | VertexFormat::Normal3 | VertexFormat::TexCoord2 ));
        Vector3f* ptrPosition = subMesh->GetVertexList().GetPositions();
        Vector3f* ptrNormal   = subMesh->GetVertexList().GetNormals();
        Vector2f* ptrTexCoord = subMesh->GetVertexList().GetTextureCoords();

        UInt32 i = 0;
        for(Vector<ASEVertex>::const_iterator itVertex = aseSubMesh.mVertices.begin(); itVertex != aseSubMesh.mVertices.end(); ++itVertex, ++i)
        {
            ptrPosition[i].x = (*itVertex).mPosition.x;
            ptrPosition[i].y = (*itVertex).mPosition.z;
            ptrPosition[i].z = (*itVertex).mPosition.y;
            
            ptrNormal[i].x = (*itVertex).mNormal.x; 
            ptrNormal[i].y = (*itVertex).mNormal.z; 
            ptrNormal[i].z = (*itVertex).mNormal.y; 

            ptrTexCoord[i] = (*itVertex).mUV; 
        }

        // Create IB
        {
            subMesh->GetTriangles().Allocate( TriangleBatch::TriangleList, aseSubMesh.mIndices.size());
            UInt16* ptrIndices = subMesh->GetTriangles().GetIndices();
        
            UInt32 i = 0;
            for(Vector<UInt32>::const_iterator itIndex = aseSubMesh.mIndices.begin(); itIndex != aseSubMesh.mIndices.end(); ++itIndex, ++i)
                ptrIndices[i] = *itIndex;
        }

        // Shader
        {
            TextureShader* shader = GD_NEW(TextureShader, this, "TextureShader");

            if(mat.mMapDiffuse.mBitmap.size() != 0)
            {
                HTexture2D hdl( mat.mMapDiffuse.mBitmap );
                hdl->GetImage().FlipY();
                hdl->Update();
                shader->mTexture = hdl;
            }
            else if(mat.mMapGeneric.mBitmap.size() != 0)
            {
                HTexture2D hdl( mat.mMapGeneric.mBitmap );
                hdl->GetImage().FlipY();
                hdl->Update();
                shader->mTexture = hdl;
            }

            shader->mMaterial.mAmbient   = Color4f(mat.mAmbient.R, mat.mAmbient.G, mat.mAmbient.B);
            shader->mMaterial.mDiffuse   = Color4f(mat.mDiffuse.R, mat.mDiffuse.G, mat.mDiffuse.B);
            //shader->mMaterial.mSpecular  = Color4f(mat.mSpecular.R, mat.mSpecular.G, mat.mSpecular.B);
            shader->mMaterial.mShininess = mat.mShine;
            subMesh->mShader = shader;
        }
    }    

	return newMesh;
}
Пример #19
0
void LWOReader::ReadVMAP( UInt32 pChunkSize, Bool pPerPoly )
{
    UInt32              dataRead = 0;
    UInt16              dimension;
    LWIndex             vertexIndex;
    LWIndex             polygonIndex;
    
    LWVertexMap*        newVertexMap = GD_NEW(LWVertexMap, this, "VertexMap");

    newVertexMap->mPerPoly = pPerPoly;

    dataRead += ReadID4( newVertexMap->mType );
    dataRead += ReadU2( dimension );
    dataRead += ReadS0( newVertexMap->mName );

    while( dataRead < pChunkSize )
    {
        dataRead += ReadVX( vertexIndex );
        newVertexMap->mVertexIndex.push_back( vertexIndex );

        if( pPerPoly )
        {
            dataRead += ReadVX( polygonIndex );
            newVertexMap->mPolygonIndex.push_back( polygonIndex );
        }

        LWMapValue mapping;

        switch( newVertexMap->mType )
        {
        case ID_PICK:
            mapping.mPick = vertexIndex;
            break;

        case ID_WGHT:
            dataRead += ReadF4( mapping.mWeight );
            break;

        case ID_TXUV:   
            dataRead += ReadF4( mapping.mUV.U );
            dataRead += ReadF4( mapping.mUV.V );
            break;

        case ID_RGB:
            dataRead += ReadF4( mapping.mRGB.R );
            dataRead += ReadF4( mapping.mRGB.G );
            dataRead += ReadF4( mapping.mRGB.B );
            break;

        case ID_RGBA:
            dataRead += ReadF4( mapping.mRGBA.R );
            dataRead += ReadF4( mapping.mRGBA.G );
            dataRead += ReadF4( mapping.mRGBA.B );
            dataRead += ReadF4( mapping.mRGBA.A ); 
            break;

        case ID_MORF:
        case ID_SPOT:
        case ID_MNVW:   
        default:       
            dataRead += Skip( dimension * sizeof(Float) );      
            break;
        }   

        newVertexMap->mValues.push_back( mapping );
    }

    GetCurrentLayer()->mVertexMaps.push_back( newVertexMap );
}
Пример #20
0
void LWOReader::ReadSURF( UInt32 pChunkSize )
{
    UInt32      dataRead = 0;
    UInt16      subChunkSize;
    UInt32      subChunkTag;
    UInt32      bytesHold;
    LWIndex     env;
    
    LWSurface*  newSurface = GD_NEW(LWSurface, this, "Surface");

    dataRead += ReadS0( newSurface->mSurfaceName );
    dataRead += ReadS0( newSurface->mSurfaceFile );

    // Read all subchunks
    while( dataRead < pChunkSize )
    {
        if( (pChunkSize - dataRead) < 6 )
        {
            dataRead += Skip( pChunkSize - dataRead );
            return;
	    }

        subChunkTag = ReadSubChunk(subChunkSize);
        dataRead += sizeof(subChunkTag);   // Subchunk tag.
        dataRead += sizeof(subChunkSize);  // Subchunk size.

        bytesHold = dataRead;

        switch( subChunkTag )
        {
        case ID_COLR:   
            dataRead += ReadCOL12( newSurface->mBaseColor );    
            dataRead += ReadVX( env );
            break;
            
        case ID_DIFF:
            dataRead += ReadFP4( newSurface->mDiffuse );    
            dataRead += ReadVX( env );
            break;

        case ID_LUMI:
            dataRead += ReadFP4( newSurface->mLuminosity );    
            dataRead += ReadVX( env );
            break;

        case ID_SPEC:
            dataRead += ReadFP4( newSurface->mSpecular );    
            dataRead += ReadVX( env );
            break;

        case ID_REFL:
            dataRead += ReadFP4( newSurface->mReflection );    
            dataRead += ReadVX( env );
            break;

        case ID_TRAN:
            dataRead += ReadFP4( newSurface->mTransparency );    
            dataRead += ReadVX( env );
            break;

        case ID_TRNL:
            dataRead += ReadFP4( newSurface->mTranslucency );    
            dataRead += ReadVX( env );
            break;
            
        case ID_GLOS:
            dataRead += ReadFP4( newSurface->mSpecularGlossiness );    
            dataRead += ReadVX( env );
            break;

        case ID_SHRP:
            dataRead += ReadFP4( newSurface->mDiffuseSharpness );    
            dataRead += ReadVX( env );
            break;

        case ID_BUMP:
            dataRead += ReadFP4( newSurface->mBumpStrength );    
            dataRead += ReadVX( env );
            break;
            
        case ID_SIDE:
            dataRead += ReadU2( newSurface->mPolySide );    
            break;
            
        case ID_SMAN:
            dataRead += ReadANG4( newSurface->mMaxSmoothingAngle );
            break;
            
        case ID_RFOP:
            dataRead += ReadU2( newSurface->mReflectionOptions );
            break;
            
        case ID_RIMG:
            dataRead += ReadVX( newSurface->mReflectionMapImage );
            break;
            
        case ID_RSAN:
            dataRead += ReadANG4( newSurface->mReflMapSeamAngle );
            dataRead += ReadVX( env );
            break;

        case ID_RBLR:
            dataRead += ReadFP4( newSurface->mReflBlurPercent );
            dataRead += ReadVX( env );
            break;

        case ID_CLRH:
            dataRead += ReadFP4( newSurface->mColorHighlights );
            dataRead += ReadVX( env );
            break;

        case ID_TROP:
            dataRead += ReadU2( newSurface->mTransparencyOptions );
            dataRead += Skip( subChunkSize - sizeof(UInt16) );
            break;

        case ID_CLRF:
            dataRead += ReadFP4( newSurface->mColorFilter );
            dataRead += ReadVX( env );
            break;

        case ID_ADTR:
            dataRead += ReadFP4( newSurface->mAdditiveTransparency );
            dataRead += ReadVX( env );
            break;         
        
        case ID_ALPH:
            dataRead += ReadU2( newSurface->mAlphaMode );
            dataRead += ReadFP4( newSurface->mAlphaValue );
            break;

        case ID_BLOK:
            ReadBLOK( newSurface, subChunkSize );
            dataRead += subChunkSize;
            break;
        
        case ID_VCOL:
        case ID_LINE:
        case ID_GLOW:
        case ID_TBLR:
        case ID_TIMG:
        case ID_RIND:
        default:    dataRead += Skip( subChunkSize );   break;
        }

        // Make sure we've read all subchunk bytes (given by the size).
        if( (subChunkSize - dataRead + bytesHold) > 0 )
            dataRead += Skip( subChunkSize - dataRead + bytesHold );
    }

    mObject->mSurfaces.push_back( newSurface );
}
Пример #21
0
void LWOReader::ReadBLOK( LWSurface* pSurface, UInt32 pChunkSize )
{
    UInt32      dataRead = 0;
    UInt16      subChunkSize;
    UInt32      subChunkTag;
    UInt32      bytesHold;

    LWSurfaceBlock*     newSurfaceBlock = GD_NEW(LWSurfaceBlock, this, "SurfaceBlock");

    //dataRead += ReadS0( newSurfaceBlock->mOrdinalString );

    // Read all subchunks
    while( dataRead < pChunkSize )
    {
        subChunkTag = ReadSubChunk(subChunkSize,1);
        dataRead += sizeof(subChunkTag);   // Subchunk tag.
        dataRead += sizeof(subChunkSize);  // Subchunk size.

        bytesHold = dataRead;

        switch( subChunkTag )
        {
        case ID_IMAP:
        case ID_PROC:
        case ID_GRAD:
        case ID_SHDR:
            newSurfaceBlock->mType = subChunkTag;
	        ReadHEAD( newSurfaceBlock, subChunkSize );
            dataRead += subChunkSize;
            break;

        case ID_TMAP:
            ReadTMAP( &newSurfaceBlock->mTextureMapping, subChunkSize );
            dataRead += subChunkSize;
            break;

        case ID_PROJ:
            dataRead += ReadU2( newSurfaceBlock->mImageMap.mProjectionMode );
            break;

        case ID_AXIS:
            dataRead += ReadU2( newSurfaceBlock->mImageMap.mProjectionAxis );
            break;

        case ID_IMAG:
            newSurfaceBlock->mImageMap.mValid = true;
            dataRead += ReadVX( newSurfaceBlock->mImageMap.mImageMap );
            break;

        case ID_WRAP:
            dataRead += ReadU2( newSurfaceBlock->mImageMap.mWrapModeWidth );
            dataRead += ReadU2( newSurfaceBlock->mImageMap.mWrapModeHeight );
            break;

        case ID_VMAP:
            dataRead += ReadS0( newSurfaceBlock->mImageMap.mUVVertexMapName );
            break;

        default:
           dataRead += Skip( subChunkSize );   
           break;
        }

        // Make sure we've read all subchunk bytes (given by the size).
        if( (subChunkSize - dataRead + bytesHold) > 0 )
            dataRead += Skip( subChunkSize - dataRead + bytesHold );
    }

    pSurface->mBlocks.push_back( newSurfaceBlock );
}
Пример #22
0
Resource* WoWImporter::Import( const String& pFilename, const String& /*pParams*/ )
{
    WoW::ADTFile        adtFile;
    WoW::ADTFileReader  adtFileReader( adtFile );

    adtFileReader.Read( pFilename );


    WorldTile* worldTile = GD_NEW(WorldTile, this, "WoW::WorldTile");
    worldTile->GetTerrainChunks().resize( 256 );
    worldTile->GetVertexList().Allocate( 16*16 * (9*9 + 8*8), (VertexFormat::Component) (VertexFormat::Position3 | VertexFormat::TexCoord2 | VertexFormat::TexCoord2_2 | VertexFormat::Normal3) );

    Vector3f* ptrPosition = worldTile->GetVertexList().GetPositions();
    Vector3f* ptrNormal   = worldTile->GetVertexList().GetNormals();
	Vector2f* ptrTexCoord = worldTile->GetVertexList().GetTextureCoords();
    Vector2f* ptrTexCoordAlpha = worldTile->GetVertexList().GetTextureCoords_2();
    UInt32    verticesOffset = 0;

    Vector3f firstChunkPos(0,0,0);//-1.0f*adtFile.mMapChunks[0].mHeader.mPosition.y, adtFile.mMapChunks[0].mHeader.mPosition.z, -1.0f*adtFile.mMapChunks[0].mHeader.mPosition.x );

    for( UInt32 iChunk = 0; iChunk < 256; iChunk++ )
    {
        WoW::ADTFile::MapChunk* mapChunk = &adtFile.mMapChunks[iChunk];

        // Append vertex data to vertex buffer
        Float* ptrDataHeight  = mapChunk->mHeightMap;
        Char*  ptrDataNormals = mapChunk->mHeightMapNormals[0];

        Vector3f chunkPos( -1.0f*mapChunk->mHeader.mPosition.y, mapChunk->mHeader.mPosition.z, -1.0f*mapChunk->mHeader.mPosition.x );
        Float  posX = chunkPos.x - firstChunkPos.x;
        Float  posZ = chunkPos.z - firstChunkPos.z;
        for( UInt32 z = 0; z < 9; z++ )
        {
            // Normal row
            posX = chunkPos.x - firstChunkPos.x;
            for( UInt32 x = 0; x < 9; x++ )
            {
                ptrPosition->x = posX;
                ptrPosition->y = chunkPos.y + (*ptrDataHeight) - firstChunkPos.y;
                ptrPosition->z = posZ;
                (*ptrPosition) *= 0.1f;

                ptrNormal->x = ((Float)ptrDataNormals[0]) / 127.0f;
                ptrNormal->y = ((Float)ptrDataNormals[1]) / 127.0f;
                ptrNormal->z = ((Float)ptrDataNormals[2]) / 127.0f;

                ptrTexCoord->x = x / 8.0f;
                ptrTexCoord->y = z / 8.0f;

				ptrTexCoordAlpha->x = (x+0.125f) / 8.25f;
				ptrTexCoordAlpha->y = (z+0.125f) / 8.25f;

                ptrDataHeight++;
                ptrDataNormals += 3;

                ptrPosition++;
                ptrNormal++;
				ptrTexCoord++;
                ptrTexCoordAlpha++;

                posX += UNIT_SIZE;
            }
            posZ += 0.5f * UNIT_SIZE;

            if( z == 8 )
                break;

            // Detailed row
            posX = chunkPos.x + 0.5f * UNIT_SIZE - firstChunkPos.x;
            for( UInt32 x = 0; x < 8; x++ )
            {
                ptrPosition->x = posX;
                ptrPosition->y = chunkPos.y + (*ptrDataHeight) - firstChunkPos.y;
                ptrPosition->z = posZ;
                (*ptrPosition) *= 0.1f;

                ptrNormal->x = ((Float)ptrDataNormals[0]) / 127.0f;
                ptrNormal->y = ((Float)ptrDataNormals[1]) / 127.0f;
                ptrNormal->z = ((Float)ptrDataNormals[2]) / 127.0f;

                ptrTexCoord->x = (x+0.5f) / 8.0f;
                ptrTexCoord->y = (z+0.5f) / 8.0f;

				ptrTexCoordAlpha->x = (x+0.5f+0.125f) / 8.25f;
				ptrTexCoordAlpha->y = (z+0.5f+0.125f) / 8.25f;

                ptrDataHeight++;
                ptrDataNormals += 3;
                
				ptrPosition++;
                ptrNormal++;
				ptrTexCoord++;
                ptrTexCoordAlpha++;

                posX += UNIT_SIZE;
            }
            posZ += 0.5f * UNIT_SIZE;
        }


        WorldTile::TerrainChunk* newChunk = GD_NEW(WorldTile::TerrainChunk, this, "WoW::WorldTile::TerrainChunk");

		for( UInt32 iLayer = 0; iLayer < mapChunk->mTextureLayers.size(); iLayer++ )
        {
			String textureName("Data/");
			textureName += adtFile.mTextureNames[mapChunk->mTextureLayers[iLayer].mTextureID];
			HTexture2D texture(textureName);

            Texture2D* alpha = NULL;

            if( iLayer != 0 )
            {
                alpha = Cast<Texture2D>(Texture2D::StaticClass()->AllocateNew( "AlphaMap" ));
                alpha->Create( mapChunk->mAlphaMaps[iLayer-1], true );
                alpha->Init();
                alpha->SetWrapMode( Texture::Wrap_S, Texture::Wrap_Clamp );
                alpha->SetWrapMode( Texture::Wrap_T, Texture::Wrap_Clamp );
                alpha->SetMinFilter( Texture::MinFilter_Linear );
                alpha->SetMagFilter( Texture::MagFilter_Linear );
            }

			newChunk->AddTextureLayer( texture, alpha );
		}

        UInt32 detailedStripSize = (16*18 + 7*2 + 8*2);
        UInt32 normalStripSize   = 158;

        // Build index buffer
        newChunk->GetHiResTriangles().Allocate( TriangleBatch::TriangleStrip, detailedStripSize );
        newChunk->GetLowResTriangles().Allocate( TriangleBatch::TriangleStrip, normalStripSize );
        UInt16* ptrHiIndices = newChunk->GetHiResTriangles().GetIndices();
        UInt16* ptrLoIndices = newChunk->GetLowResTriangles().GetIndices();
        
        for( int row = 0; row < 8; row++ )
        { 
            UInt32 topRow       = verticesOffset + row*(9+8);
            UInt32 detailrow    = verticesOffset + row*(9+8) + 9;
            UInt32 nextRow      = verticesOffset + (row+1)*(9+8);
            
            if( row > 0 )
            {
                *ptrHiIndices++ = topRow + 0;     // jump end
                *ptrLoIndices++ = topRow + 0;
            }
            
            for( int col = 0; col < 8; col++ )
            {
                *ptrHiIndices++ = topRow + col;
                *ptrHiIndices++ = detailrow + col;
                *ptrLoIndices++ = topRow + col;
                *ptrLoIndices++ = nextRow + col;
            }
            
            *ptrHiIndices++ = topRow  + 8;
            *ptrHiIndices++ = nextRow + 8;
            *ptrHiIndices++ = nextRow + 8;        // jump start
            *ptrHiIndices++ = topRow  + 0;        // jump end
            *ptrHiIndices++ = topRow  + 0;   
            
            *ptrLoIndices++ = topRow  + 8;
            *ptrLoIndices++ = nextRow + 8;
            
            for( int col = 0; col < 8; col++ )
            {
                *ptrHiIndices++ = nextRow + col;
                *ptrHiIndices++ = detailrow + col;
            }

            if( row < 8 )
                *ptrHiIndices++ = nextRow + 8;

            if( row < 7 ) 
            {
                *ptrHiIndices++ = nextRow + 8;    // jump start
                *ptrLoIndices++ = nextRow + 8;
            }
        }

        verticesOffset += 9*9 + 8*8;

        worldTile->GetTerrainChunks()[iChunk] = newChunk;
    }
    
    return (Resource*)worldTile;
}
Пример #23
0
ModelBrowserTool::ModelBrowserTool() : 
    mModelBrowserWindow(NULL),
	mModel(NULL)
{
	mModel = GD_NEW(Model3D, this, "Model3D");
}
	GDEXP extern IGraphics* CreateIGraphicsInstance()
	{
		return GD_NEW(IGraphicsOpenGL);
	}
	GDEXP IDateTime* CreateIDateTimeInstance()
	{
		return GD_NEW(IDateTimeMicrosoft);
	}
Пример #26
0
SoundData* WavReader::Read(const String& pFileName)
{
    SoundData* newSoundData = GD_NEW(SoundData, this, "SoundData");
    newSoundData->SetFileName(pFileName);

    Char identifier[5];
    identifier[4] = '\0';

    // Open the file stream.
    std::ifstream fileStream(pFileName.c_str(), std::ios::in | std::ios::binary);

    // Read "RIFF"
    fileStream.read(identifier, 4);
    if(strcmp(identifier, "RIFF") != 0)
        throw ResourceImportException( String("The wav file should start with RIFF"), Here );

    // Read the total length (filesize - 8).
    Int32 fileDataSize;
    fileStream.read((Char*)(&fileDataSize), 4);
    fileDataSize += 8;
    newSoundData->SetFileDataSize(fileDataSize);

    // Read "WAVE".
    fileStream.read(identifier, 4);
    if(strcmp(identifier, "WAVE") != 0)
        throw ResourceImportException( String("The wav file should contain the WAVE identifier."), Here );
    
    // Read "fmt_"
    fileStream.read(identifier, 4);
    if(strcmp(identifier, "fmt ") != 0)
        throw ResourceImportException( String("The wav file should contain the fmt_ identifier."), Here );
    
    // Read the Length of the format chunk.
    Int32 chunkFileSize;
    fileStream.read((Char*)(&chunkFileSize), 4);
 
    // Read a drummy short.
    Int16 dummyShort;
    fileStream.read((Char*)(&dummyShort), 2);

    // Read the number of channels.
    Int16 nbChannels;
    fileStream.read((Char*)(&nbChannels), 2);
    newSoundData->SetNbChannels(nbChannels);

    // Read the sample rate.
    Int32 sampleRate;
    fileStream.read((Char*)(&sampleRate), 4);
    newSoundData->SetSampleRate(sampleRate);

    // Read the bytes per second.
    Int32 bytesPerSecond;
    fileStream.read((Char*)(&bytesPerSecond), 4);
    newSoundData->SetBytesPerSecond(bytesPerSecond);

    // Read the bytes per sample.
    Int16 bytesPerSample;
    fileStream.read((Char*)(&bytesPerSample), 2);
    newSoundData->SetBytesPerSample(bytesPerSample);

    // Read the bits per sample.
    Int16 bitsPerSample;
    fileStream.read((Char*)(&bitsPerSample), 2);
    newSoundData->SetBitsPerSample(bitsPerSample);

    // Read "data"
    fileStream.read(identifier, 4);
    if(strcmp(identifier, "data") != 0)
        throw ResourceImportException( String("The wav file should contain the data identifier."), Here );

    // Read the size of sound data.
    Int32 soundDataSize;
    fileStream.read((Char*)(&soundDataSize), 4);
    newSoundData->SetSoundDataSize(soundDataSize);
    newSoundData->SetSoundDataOffset(44);
    
    // Read the data itself.
    fileStream.seekg(0, std::ios::beg);
    Char* data = GD_NEW_ARRAY(Char, fileDataSize + 1, this, "Data");
    data[fileDataSize] = '\0';
    fileStream.read(data, fileDataSize);
    newSoundData->SetFileData(data);

    fileStream.close();
 
    return newSoundData;
}