SpatialAwarenessSystem* Factory::Create(SpatialAwarenessStrategy strategy,SpatialAwarenessObserver *observer) { SpatialAwarenessSystem *ret = 0; switch ( strategy ) { case SAS_BUFFER: { SAS_Buffer *sas = MEMALLOC_NEW(SAS_Buffer)(observer); ret = static_cast< SpatialAwarenessSystem * >(sas); } break; case SAS_LOG: { SAS_Log *sas = MEMALLOC_NEW(SAS_Log)(observer); ret = static_cast< SpatialAwarenessSystem * >(sas); } break; case SAS_LAZY_KDTREE: { SAS_LazyKdTree *sas = MEMALLOC_NEW(SAS_LazyKdTree)(observer); ret = static_cast< SpatialAwarenessSystem * >(sas); } break; } if ( ret ) { mList.push_back(ret); } return ret; }
//----------------------------------------------------------------------------- HRESULT CDXUTMeshFile::LoadMesh( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData, CDXUTMeshFrame* pParentFrame ) { // Currently only allowing one mesh per frame if( pParentFrame->m_pMesh ) return E_FAIL; // Get the mesh name CHAR strAnsiName[512] = {0}; WCHAR strName[512]; SIZE_T dwNameLength = 512; HRESULT hr; if( FAILED( hr = pFileData->GetName( strAnsiName, &dwNameLength ) ) ) return hr; MultiByteToWideChar( CP_ACP, 0, strAnsiName, -1, strName, 512 ); strName[511] = 0; // Create the mesh pParentFrame->m_pMesh = MEMALLOC_NEW(CDXUTMesh)( strName ); if( pParentFrame->m_pMesh == NULL ) return E_OUTOFMEMORY; pParentFrame->m_pMesh->Create( pd3dDevice, pFileData ); return S_OK; }
_FILE_INTERFACE(const char *fname,const char *spec,void *mem,size_t len) { mHeadBlock = 0; mTailBlock = 0; mMyAlloc = false; mRead = true; // default is read access. mFph = 0; mData = (char *) mem; mLen = len; mLoc = 0; if ( spec && _stricmp(spec,"wmem") == 0 ) { mRead = false; if ( mem == 0 || len == 0 ) { mHeadBlock = MEMALLOC_NEW(MemoryBlock)(DEFAULT_BUFFER_SIZE); mTailBlock = mHeadBlock; mData = 0; mLen = 0; mMyAlloc = true; } } if ( mData == 0 && mHeadBlock == 0 ) { mFph = fopen(fname,spec); } strncpy(mName,fname,512); }
FileFind::FileFind(WildCard *wild,const char *dirname) { mWildCard = wild; if ( dirname ) sprintf(mSearchName,"%s\\*.*",dirname); else sprintf(mSearchName,"*.*"); mInternalFind = MEMALLOC_NEW(InternalFind); }
FBX_DLL_API MeshImportFBX * getInterface(int version_number) #endif { assert( gInterface == 0 ); if ( gInterface == 0 && version_number == MESHIMPORTFBX_VERSION ) { gInterface = MEMALLOC_NEW(MeshImportFBX); } return static_cast<MeshImportFBX *>(gInterface); };
MyMenu(void) { gSendTextMessage = this; mMainMenu = CreateMenu(); HMENU m = CreatePopupMenu(); mFileMenu = m; AppendMenu( mMainMenu, MF_POPUP, (UINT_PTR)m, L"&File" ); AppendMenu( m, MF_STRING, MO_RUN_SCRIPT, L"Run Demo Script"); AppendMenu( m, MF_STRING, MO_EXIT, L"E&xit"); // ok, now initialize the scripted menu interface. gFileSystem = this; gLog = MEMALLOC_NEW(Log)("ThreadFrac.txt",true); gLog->Display("ThreadFrac initialized.\r\n"); gTheCommandParser = MEMALLOC_NEW(TheCommandParser); gTui = MEMALLOC_NEW(TextUserInterface)("ThreadFrac.tui"); gTui->setTuiSaveCallback(this); }
FILE_INTERFACE * fi_fopen(const char *fname,const char *spec,void *mem,size_t len) { _FILE_INTERFACE *ret = 0; ret = MEMALLOC_NEW(_FILE_INTERFACE)(fname,spec,mem,len); if ( mem == 0 && ret->mData == 0 && ret->mHeadBlock == 0 ) { if ( ret->mFph == 0 ) { delete ret; ret = 0; } } return (FILE_INTERFACE *)ret; }
size_t write(const char *data,size_t size) { size_t ret = 0; if ( mMyAlloc ) { #ifdef _DEBUG validateLen(); #endif size_t remaining; data = mTailBlock->write(data,size,remaining); while ( data ) { size_t _size = remaining; MemoryBlock *block = MEMALLOC_NEW(MemoryBlock)(BUFFER_GROW_SIZE); mTailBlock->mNextBlock = block; mTailBlock = block; data = mTailBlock->write(data,_size,remaining); } mLoc+=size; #ifdef _DEBUG validateLen(); #endif ret = 1; } else { if ( (mLoc+size) <= mLen ) { memcpy(&mData[mLoc],data,size); mLoc+=size; ret = 1; } } return ret; }
MeshImporter * createMeshImportPSK(void) { MeshImporterPSK *m = MEMALLOC_NEW(MeshImporterPSK); return static_cast< MeshImporter *>(m); }
iRayCast *createRayCast(const NxF32 *vertices,NxU32 tcount,const NxU32 *indices) { RayCast *rc = MEMALLOC_NEW(RayCast)(vertices,tcount,indices); return static_cast< iRayCast *>(rc); }
//-------------------------------------------------------------------------------------- // Enumerates available D3D adapters, devices, modes, etc. //-------------------------------------------------------------------------------------- HRESULT CD3DEnumeration::Enumerate( IDirect3D9* pD3D, LPDXUTCALLBACKISDEVICEACCEPTABLE IsDeviceAcceptableFunc, void* pIsDeviceAcceptableFuncUserContext ) { if( pD3D == NULL ) { pD3D = DXUTGetD3DObject(); if( pD3D == NULL ) return DXUTERR_NODIRECT3D; } m_pD3D = pD3D; m_IsDeviceAcceptableFunc = IsDeviceAcceptableFunc; m_pIsDeviceAcceptableFuncUserContext = pIsDeviceAcceptableFuncUserContext; HRESULT hr; ClearAdapterInfoList(); CGrowableArray<D3DFORMAT> adapterFormatList; const D3DFORMAT allowedAdapterFormatArray[] = { D3DFMT_X8R8G8B8, D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_A2R10G10B10 }; const UINT allowedAdapterFormatArrayCount = sizeof(allowedAdapterFormatArray) / sizeof(allowedAdapterFormatArray[0]); UINT numAdapters = pD3D->GetAdapterCount(); for (UINT adapterOrdinal = 0; adapterOrdinal < numAdapters; adapterOrdinal++) { CD3DEnumAdapterInfo* pAdapterInfo = MEMALLOC_NEW(CD3DEnumAdapterInfo); if( pAdapterInfo == NULL ) return E_OUTOFMEMORY; pAdapterInfo->AdapterOrdinal = adapterOrdinal; pD3D->GetAdapterIdentifier(adapterOrdinal, 0, &pAdapterInfo->AdapterIdentifier); // Get list of all display modes on this adapter. // Also build a temporary list of all display adapter formats. adapterFormatList.RemoveAll(); for( UINT iFormatList = 0; iFormatList < allowedAdapterFormatArrayCount; iFormatList++ ) { D3DFORMAT allowedAdapterFormat = allowedAdapterFormatArray[iFormatList]; UINT numAdapterModes = pD3D->GetAdapterModeCount( adapterOrdinal, allowedAdapterFormat ); for (UINT mode = 0; mode < numAdapterModes; mode++) { D3DDISPLAYMODE displayMode; pD3D->EnumAdapterModes( adapterOrdinal, allowedAdapterFormat, mode, &displayMode ); if( displayMode.Width < m_nMinWidth || displayMode.Height < m_nMinHeight || displayMode.Width > m_nMaxWidth || displayMode.Height > m_nMaxHeight || displayMode.RefreshRate < m_nRefreshMin || displayMode.RefreshRate > m_nRefreshMax ) { continue; } pAdapterInfo->displayModeList.Add( displayMode ); if( !adapterFormatList.Contains(displayMode.Format) ) adapterFormatList.Add( displayMode.Format ); } } D3DDISPLAYMODE displayMode; pD3D->GetAdapterDisplayMode( adapterOrdinal, &displayMode ); if( !adapterFormatList.Contains(displayMode.Format) ) adapterFormatList.Add( displayMode.Format ); // Sort displaymode list ::qsort( pAdapterInfo->displayModeList.GetData(), pAdapterInfo->displayModeList.GetSize(), sizeof( D3DDISPLAYMODE ), SortModesCallback ); // Get info for each device on this adapter if( FAILED( EnumerateDevices( pAdapterInfo, &adapterFormatList ) ) ) { delete pAdapterInfo; continue; } // If at least one device on this adapter is available and compatible // with the app, add the adapterInfo to the list if( pAdapterInfo->deviceInfoList.GetSize() > 0 ) { hr = m_AdapterInfoList.Add( pAdapterInfo ); if( FAILED(hr) ) return hr; } else delete pAdapterInfo; } bool bUniqueDesc = true; CD3DEnumAdapterInfo* pAdapterInfo; for( NxI32 i=0; i<m_AdapterInfoList.GetSize(); i++ ) { CD3DEnumAdapterInfo* pAdapterInfo1 = m_AdapterInfoList.GetAt(i); for( NxI32 j=i+1; j<m_AdapterInfoList.GetSize(); j++ ) { CD3DEnumAdapterInfo* pAdapterInfo2 = m_AdapterInfoList.GetAt(j); if( _stricmp( pAdapterInfo1->AdapterIdentifier.Description, pAdapterInfo2->AdapterIdentifier.Description ) == 0 ) { bUniqueDesc = false; break; } } if( !bUniqueDesc ) break; } for( NxI32 i=0; i<m_AdapterInfoList.GetSize(); i++ ) { pAdapterInfo = m_AdapterInfoList.GetAt(i); MultiByteToWideChar( CP_ACP, 0, pAdapterInfo->AdapterIdentifier.Description, -1, pAdapterInfo->szUniqueDescription, 100 ); pAdapterInfo->szUniqueDescription[100] = 0; if( !bUniqueDesc ) { WCHAR sz[100]; StringCchPrintf( sz, 100, L" (#%d)", pAdapterInfo->AdapterOrdinal ); StringCchCat( pAdapterInfo->szUniqueDescription, 256, sz ); } } return S_OK; }
//-------------------------------------------------------------------------------------- // Enumerates DeviceCombos for a particular device. //-------------------------------------------------------------------------------------- HRESULT CD3DEnumeration::EnumerateDeviceCombos( CD3DEnumAdapterInfo* pAdapterInfo, CD3DEnumDeviceInfo* pDeviceInfo, CGrowableArray<D3DFORMAT>* pAdapterFormatList ) { const D3DFORMAT backBufferFormatArray[] = { D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_A2R10G10B10, D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5 }; const UINT backBufferFormatArrayCount = sizeof(backBufferFormatArray) / sizeof(backBufferFormatArray[0]); // See which adapter formats are supported by this device for( NxI32 iFormat=0; iFormat<pAdapterFormatList->GetSize(); iFormat++ ) { D3DFORMAT adapterFormat = pAdapterFormatList->GetAt(iFormat); for( UINT iBackBufferFormat = 0; iBackBufferFormat < backBufferFormatArrayCount; iBackBufferFormat++ ) { D3DFORMAT backBufferFormat = backBufferFormatArray[iBackBufferFormat]; for( NxI32 nWindowed = 0; nWindowed < 2; nWindowed++) { if( !nWindowed && pAdapterInfo->displayModeList.GetSize() == 0 ) continue; if (FAILED( m_pD3D->CheckDeviceType( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, adapterFormat, backBufferFormat, nWindowed ))) { continue; } if( m_bRequirePostPixelShaderBlending ) { // If the backbuffer format doesn't support D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING // then alpha test, pixel fog, render-target blending, color write enable, and dithering. // are not supported. if( FAILED( m_pD3D->CheckDeviceFormat( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, adapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_TEXTURE, backBufferFormat ) ) ) { continue; } } // If an application callback function has been provided, make sure this device // is acceptable to the app. if( m_IsDeviceAcceptableFunc != NULL ) { if( !m_IsDeviceAcceptableFunc( &pDeviceInfo->Caps, adapterFormat, backBufferFormat, FALSE != nWindowed, m_pIsDeviceAcceptableFuncUserContext ) ) continue; } // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed // DeviceCombo that is supported by the system and acceptable to the app. We still // need to find one or more suitable depth/stencil buffer format, // multisample type, and present interval. CD3DEnumDeviceSettingsCombo* pDeviceCombo = MEMALLOC_NEW(CD3DEnumDeviceSettingsCombo); if( pDeviceCombo == NULL ) return E_OUTOFMEMORY; pDeviceCombo->AdapterOrdinal = pAdapterInfo->AdapterOrdinal; pDeviceCombo->DeviceType = pDeviceInfo->DeviceType; pDeviceCombo->AdapterFormat = adapterFormat; pDeviceCombo->BackBufferFormat = backBufferFormat; pDeviceCombo->Windowed = (nWindowed != 0); BuildDepthStencilFormatList( pDeviceCombo ); BuildMultiSampleTypeList( pDeviceCombo ); if (pDeviceCombo->multiSampleTypeList.GetSize() == 0) { delete pDeviceCombo; continue; } BuildDSMSConflictList( pDeviceCombo ); BuildPresentIntervalList(pDeviceInfo, pDeviceCombo ); pDeviceCombo->pAdapterInfo = pAdapterInfo; pDeviceCombo->pDeviceInfo = pDeviceInfo; pDeviceInfo->deviceSettingsComboList.Add( pDeviceCombo ); } } } return S_OK; }
//-------------------------------------------------------------------------------------- // Enumerates D3D devices for a particular adapter. //-------------------------------------------------------------------------------------- HRESULT CD3DEnumeration::EnumerateDevices( CD3DEnumAdapterInfo* pAdapterInfo, CGrowableArray<D3DFORMAT>* pAdapterFormatList ) { HRESULT hr; const D3DDEVTYPE devTypeArray[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_SW, D3DDEVTYPE_REF }; const UINT devTypeArrayCount = sizeof(devTypeArray) / sizeof(devTypeArray[0]); // Enumerate each Direct3D device type for( UINT iDeviceType = 0; iDeviceType < devTypeArrayCount; iDeviceType++ ) { CD3DEnumDeviceInfo* pDeviceInfo = MEMALLOC_NEW(CD3DEnumDeviceInfo); if( pDeviceInfo == NULL ) return E_OUTOFMEMORY; // Fill struct w/ AdapterOrdinal and D3DDEVTYPE pDeviceInfo->DeviceType = devTypeArray[iDeviceType]; // Store device caps if( FAILED( hr = m_pD3D->GetDeviceCaps( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, &pDeviceInfo->Caps ) ) ) { delete pDeviceInfo; continue; } // Create a temp device to verify that it is really possible to create a REF device // [the developer DirectX redist has to be installed] D3DDISPLAYMODE Mode; m_pD3D->GetAdapterDisplayMode(0, &Mode); D3DPRESENT_PARAMETERS pp; ZeroMemory( &pp, sizeof(D3DPRESENT_PARAMETERS) ); pp.BackBufferWidth = 1; pp.BackBufferHeight = 1; pp.BackBufferFormat = Mode.Format; pp.BackBufferCount = 1; pp.SwapEffect = D3DSWAPEFFECT_COPY; pp.Windowed = TRUE; pp.hDeviceWindow = DXUTGetHWNDFocus(); IDirect3DDevice9 *pDevice = NULL; if( FAILED( hr = m_pD3D->CreateDevice( pAdapterInfo->AdapterOrdinal, pDeviceInfo->DeviceType, DXUTGetHWNDFocus(), D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &pp, &pDevice ) ) ) { if( hr == D3DERR_NOTAVAILABLE ) { delete pDeviceInfo; continue; } } SAFE_RELEASE( pDevice ); // Get info for each devicecombo on this device if( FAILED( hr = EnumerateDeviceCombos( pAdapterInfo, pDeviceInfo, pAdapterFormatList ) ) ) { delete pDeviceInfo; continue; } // If at least one devicecombo for this device is found, // add the deviceInfo to the list if (pDeviceInfo->deviceSettingsComboList.GetSize() > 0 ) pAdapterInfo->deviceInfoList.Add( pDeviceInfo ); else delete pDeviceInfo; } return S_OK; }
void queueMessage(const char *msg) { WindowsMessage *wm = MEMALLOC_NEW(WindowsMessage)(msg); mStrings.push(wm); }
void queueMessageBlob(const char *blobType,const void *mem,NxU32 len) { WindowsMessage *wm = MEMALLOC_NEW(WindowsMessage)(blobType,mem,len); mBlobs.push(wm); }
//----------------------------------------------------------------------------- HRESULT CDXUTMeshFile::LoadFrame( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData, CDXUTMeshFrame* pParentFrame ) { LPD3DXFILEDATA pChildData = NULL; GUID Guid; SIZE_T cbSize; CDXUTMeshFrame* pCurrentFrame; HRESULT hr; // Get the type of the object if( FAILED( hr = pFileData->GetType( &Guid ) ) ) return hr; if( Guid == TID_D3DRMMesh ) { hr = LoadMesh( pd3dDevice, pFileData, pParentFrame ); if( FAILED(hr) ) return hr; } if( Guid == TID_D3DRMFrameTransformMatrix ) { D3DXMATRIX* pmatMatrix; hr = pFileData->Lock(&cbSize, (LPCVOID*)&pmatMatrix ); if( FAILED(hr) ) return hr; // Update the parent's matrix with the new one pParentFrame->SetMatrix( pmatMatrix ); } if( Guid == TID_D3DRMFrame ) { // Get the frame name CHAR strAnsiName[512] = ""; WCHAR strName[512]; SIZE_T dwNameLength = 512; SIZE_T cChildren; if( FAILED( hr = pFileData->GetName( strAnsiName, &dwNameLength ) ) ) return hr; MultiByteToWideChar( CP_ACP, 0, strAnsiName, -1, strName, 512 ); strName[511] = 0; // Create the frame pCurrentFrame = MEMALLOC_NEW(CDXUTMeshFrame)( strName ); if( pCurrentFrame == NULL ) return E_OUTOFMEMORY; pCurrentFrame->m_pNext = pParentFrame->m_pChild; pParentFrame->m_pChild = pCurrentFrame; // Enumerate child objects pFileData->GetChildren(&cChildren); for (UINT iChild = 0; iChild < cChildren; iChild++) { // Query the child for its FileData hr = pFileData->GetChild(iChild, &pChildData ); if( SUCCEEDED(hr) ) { hr = LoadFrame( pd3dDevice, pChildData, pCurrentFrame ); SAFE_RELEASE( pChildData ); } if( FAILED(hr) ) return hr; } } return S_OK; }
// warning, this code will not work on big endian processors. virtual bool importMesh(const char *_meshName,const void *_data,NxU32 dlen,MeshImportInterface *callback,const char *options,MeshImportApplicationResource *appResource) { bool ret = false; const char *meshName = _meshName; const char *slash = lastSlash(meshName); if ( slash ) { slash++; meshName = slash; } char scratch[2048]; strncpy(scratch,_meshName,2048); char *psk = stristr(scratch,".psk"); if ( psk ) { *psk = 0; strcat(scratch,".psa"); } callback->importAssetName(meshName,0); callback->importMesh(meshName,meshName); // have to make a local copy of the data because we are going to modify some of it. // Primarily just truncating some whitespace from bone names. void *data = MEMALLOC_MALLOC(dlen); memcpy(data,_data,dlen); if ( appResource ) { NxU32 len; void *mem = appResource->getApplicationResource(meshName,scratch,len); if ( mem ) { char *scan = ( char *)mem; Header *baseHeader = ( Header *)scan; scan+=sizeof(Header); Header *bonesHeader = ( Header *)scan; scan+=sizeof(Header); Bone *bones = ( Bone *)scan; assert(sizeof(Bone)==bonesHeader->mLen); scan+=(bonesHeader->mLen*bonesHeader->mCount); Header *animInfo = ( Header *)scan; scan+=sizeof(Header); assert( animInfo->mLen == sizeof(AnimInfo)); AnimInfo *ainfo = ( AnimInfo *)scan; scan+=(animInfo->mLen*animInfo->mCount); Header *animKeysHeader = ( Header *)scan; scan+=sizeof(Header); assert( animKeysHeader->mLen == sizeof(AnimKey) ); AnimKey *keys = ( AnimKey *)scan; scan+=(animKeysHeader->mLen*animKeysHeader->mCount); Header *scaleKeysHeader = ( Header *)scan; scan+=sizeof(Header); MeshAnimation ma; ma.mName = ainfo->mName; ma.mTrackCount = ainfo->mTotalBones; ma.mFrameCount = ainfo->mNumRawFrames; ma.mDtime = 1.0f / (NxF32)(ainfo->mAnimRate); ma.mDuration = ma.mDtime*ainfo->mNumRawFrames; ma.mTracks = (MeshAnimTrack **)MEMALLOC_MALLOC(sizeof(MeshAnimTrack *)*ma.mTrackCount); for (NxI32 i=0; i<ma.mTrackCount; i++) { Bone &b = bones[i]; fixName(b.mName); MeshAnimTrack *track = MEMALLOC_NEW(MeshAnimTrack); ma.mTracks[i] = track; track->mName = b.mName; track->mFrameCount = ma.mFrameCount; track->mDuration = ma.mDuration; track->mDtime = ma.mDtime; track->mPose = MEMALLOC_NEW(MeshAnimPose)[track->mFrameCount]; for (NxI32 j=0; j<ma.mFrameCount; j++) { NxU32 index = (j*ma.mTrackCount)+i; AnimKey &key = keys[index]; MeshAnimPose &p = track->mPose[j]; p.mPos[0] = key.mPosition[0]*IMPORT_SCALE; #if HACK_ANIMATION_POSITION p.mPos[1] = -key.mPosition[1]*IMPORT_SCALE; #else p.mPos[1] = key.mPosition[1]*IMPORT_SCALE; #endif p.mPos[2] = key.mPosition[2]*IMPORT_SCALE; p.mQuat[0] = key.mOrientation[0]; #if HACK_ANIMATION_ROTATION p.mQuat[1] = -key.mOrientation[1]; #else p.mQuat[1] = key.mOrientation[1]; #endif p.mQuat[2] = key.mOrientation[2]; p.mQuat[3] = key.mOrientation[3]; #if HACK_ANIMATION_ROOT if ( i == 0) { p.mQuat[3] = -p.mQuat[3]; } #endif index++; } } callback->importAnimation(ma); for (NxI32 i=0; i<ma.mTrackCount; i++) { MeshAnimTrack *track = ma.mTracks[i]; delete []track->mPose; delete track; } delete []ma.mTracks; appResource->releaseApplicationResource(mem); } } char *scan = ( char *)data; char *end = scan+dlen; Header *baseHeader = ( Header *)scan; scan+=sizeof(Header); // skip first dummy header Header *h = 0; Header *positionsHeader = h = (Header *)scan; assert( positionsHeader->mLen == sizeof(Vector)); scan+=sizeof(Header); Vector *positions = ( Vector *)scan; scan+=h->mLen*h->mCount; #if HACK_MESH_POSITION for (NxI32 i=0; i<positionsHeader->mCount; i++) { Vector &v = positions[i]; v.y*=-1; // flip the Y-coordinate } #endif Header *verticesHeader = h = ( Header *)scan; assert( verticesHeader->mLen == sizeof(Vertex)); scan+=sizeof(Header); Vertex *vertices = ( Vertex *)scan; scan+=h->mLen*h->mCount; Header *trianglesHeader = h = ( Header *)scan; assert( trianglesHeader->mLen == sizeof(Triangle)); scan+=sizeof(Header); Triangle *triangles = ( Triangle *)scan; scan+=h->mLen*h->mCount; Header *materialsHeader = h = ( Header *)scan; assert( materialsHeader->mLen == sizeof(Material)); scan+=sizeof(Header); Material *materials= ( Material *)scan; scan+=h->mLen*h->mCount; Header *bonesHeader = h = ( Header *)scan; assert( bonesHeader->mLen == sizeof(Bone)); scan+=sizeof(Header); Bone *bones= ( Bone *)scan; scan+=h->mLen*h->mCount; Header *boneInfluencesHeader = h = ( Header *)scan; assert( boneInfluencesHeader->mLen == sizeof(BoneInfluence)); scan+=sizeof(Header); BoneInfluence *boneInfluences = ( BoneInfluence *)scan; scan+=h->mLen*h->mCount; if ( bonesHeader->mCount > 0 ) { MeshSkeleton *ms = MEMALLOC_NEW(MeshSkeleton); ms->mName = meshName; ms->mBoneCount = bonesHeader->mCount; ms->mBones = MEMALLOC_NEW(MeshBone)[ms->mBoneCount]; for (NxI32 i=0; i<ms->mBoneCount; i++) { MeshBone &dest = ms->mBones[i]; Bone &src = bones[i]; fixName(src.mName); dest.mName = src.mName; dest.mParentIndex = (i==0) ? -1 : src.mParentIndex; dest.mPosition[0] = src.mPosition[0]*IMPORT_SCALE; #if HACK_SKELETON_POSITION dest.mPosition[1] = -src.mPosition[1]*IMPORT_SCALE; #else dest.mPosition[1] = src.mPosition[1]*IMPORT_SCALE; #endif dest.mPosition[2] = src.mPosition[2]*IMPORT_SCALE; dest.mOrientation[0] = src.mOrientation[0]; #if HACK_SKELETON_ROTATION dest.mOrientation[1] = -src.mOrientation[1]; #else dest.mOrientation[1] = src.mOrientation[1]; #endif dest.mOrientation[2] = src.mOrientation[2]; dest.mOrientation[3] = src.mOrientation[3]; #if HACK_SKELETON_ROOT if ( i == 0 ) { dest.mOrientation[3]*=-1; } #endif dest.mScale[0] = 1; //src.mXSize; dest.mScale[1] = 1; //src.mYSize; dest.mScale[2] = 1; //src.mZSize; } callback->importSkeleton(*ms); delete []ms->mBones; delete ms; } assert( scan == end ); DeformVector *dvertices = MEMALLOC_NEW(DeformVector)[positionsHeader->mCount]; for (NxI32 i=0; i<boneInfluencesHeader->mCount; i++) { BoneInfluence &b = boneInfluences[i]; DeformVector &d = dvertices[b.mVertexIndex]; if ( d.mCount < 4 ) { d.mWeight[d.mCount] = b.mWeight; d.mBone[d.mCount] = (NxU16)b.mBoneIndex; d.mCount++; } } Vector *normals = (Vector *)MEMALLOC_MALLOC( sizeof(Vector)*positionsHeader->mCount); memset(normals,0,sizeof(Vector)*positionsHeader->mCount); for (NxI32 i=0; i<trianglesHeader->mCount; i++) { Triangle &t = triangles[i]; MeshVertex mv1,mv2,mv3; Vertex &v1 = vertices[t.mWedgeIndex[0]]; Vertex &v2 = vertices[t.mWedgeIndex[1]]; Vertex &v3 = vertices[t.mWedgeIndex[2]]; Vector &p1 = positions[v1.mIndex]; Vector &p2 = positions[v2.mIndex]; Vector &p3 = positions[v3.mIndex]; Vector &n1 = normals[v1.mIndex]; Vector &n2 = normals[v2.mIndex]; Vector &n3 = normals[v3.mIndex]; Vector normal; fm_computePlane( &p1.x, &p3.x, &p2.x, &normal.x ); n1.x+=normal.x; n1.y+=normal.y; n1.z+=normal.z; n2.x+=normal.x; n2.y+=normal.y; n2.z+=normal.z; n3.x+=normal.x; n3.y+=normal.y; n3.z+=normal.z; } for (NxI32 i=0; i<positionsHeader->mCount; i++) { Vector &n = normals[i]; fm_normalize(&n.x); } for (NxI32 i=0; i<trianglesHeader->mCount; i++) { Triangle &t = triangles[i]; MeshVertex mv1,mv2,mv3; Vertex &v1 = vertices[t.mWedgeIndex[0]]; Vertex &v2 = vertices[t.mWedgeIndex[1]]; Vertex &v3 = vertices[t.mWedgeIndex[2]]; Vector &p1 = positions[v1.mIndex]; Vector &p2 = positions[v2.mIndex]; Vector &p3 = positions[v3.mIndex]; Vector &n1 = normals[v1.mIndex]; Vector &n2 = normals[v2.mIndex]; Vector &n3 = normals[v3.mIndex]; DeformVector &dv1 = dvertices[v1.mIndex]; DeformVector &dv2 = dvertices[v2.mIndex]; DeformVector &dv3 = dvertices[v3.mIndex]; getVertex(mv1,p1,v1,dv1,n1); getVertex(mv2,p2,v2,dv2,n2); getVertex(mv3,p3,v3,dv3,n3); const char *material = "default"; if ( t.mMaterialIndex >= 0 && t.mMaterialIndex < materialsHeader->mCount ) { material = materials[ t.mMaterialIndex ].mMaterialName; } #if HACK_MESH_WINDING callback->importTriangle(meshName,material, MIVF_ALL, mv1, mv3, mv2 ); #else callback->importTriangle(meshName,material, MIVF_ALL, mv1, mv2, mv3 ); #endif } delete []dvertices; MEMALLOC_FREE(data); return ret; }
AsciiPath * createAsciiPath(void) { MyAsciiPath *ma = MEMALLOC_NEW(MyAsciiPath); return static_cast< AsciiPath *>(ma); }
HMENU createMyMenu(void) { gMyMenu = MEMALLOC_NEW(MyMenu); return gMyMenu->mMainMenu; }
JobSwarmContext * createJobSwarmContext(unsigned int maxThreads) { JobScheduler *tjf = MEMALLOC_NEW(JobScheduler)(maxThreads); JobSwarmContext *ret = static_cast< JobSwarmContext *>(tjf); return ret; }