通过文件路径获取图片纹理

if (! FPaths :: FileExists ( FilePath ))
       {
               UE_LOG (LogTemp, Error , TEXT ( "File not found: %s" ), * FilePath );
               return nullptr ;
       }
        // Load the compressed byte data from the file
        TArray < uint8 > FileData ;
        if (! FFileHelper :: LoadFileToArray ( FileData , * FilePath ))
       {
               UE_LOG (LogTemp, Error , TEXT ( "Failed to load file: %s" ), * FilePath );
               return nullptr ;
       }
        // Detect the image type using the ImageWrapper module
        IImageWrapperModule & ImageWrapperModule = FModuleManager :: LoadModuleChecked < IImageWrapperModule >( TEXT ( "ImageWrapper" ));
        EImageFormat :: Type ImageFormat = ImageWrapperModule . DetectImageFormat ( FileData . GetData (), FileData . Num ());
        if ( ImageFormat == EImageFormat :: Invalid )
       {
               UE_LOG (LogTemp, Error , TEXT ( "Unrecognized image file format: %s" ), * FilePath );
               return nullptr ;
       }
        // Create an image wrapper for the detected image format
        IImageWrapperPtr ImageWrapper = ImageWrapperModule . CreateImageWrapper ( ImageFormat );
        if (! ImageWrapper . IsValid ())
       {
               UE_LOG (LogTemp, Error , TEXT ( "Failed to create image wrapper for file: %s" ), * FilePath );
               return nullptr ;
       }
        // Decompress the image data
        const TArray < uint8 >* RawData = nullptr ;
        ImageWrapper -> SetCompressed ( FileData . GetData (), FileData . Num ());
        ImageWrapper -> GetRaw ( ERGBFormat :: BGRA , 8, RawData );
        if ( RawData == nullptr )
       {
               UE_LOG (LogTemp, Error , TEXT ( "Failed to decompress image file: %s" ), * FilePath );
               return nullptr ;
       }
        // Create the texture and upload the uncompressed image data
        FString TextureBaseName = TEXT ( "Texture_" ) + FPaths :: GetBaseFilename ( FilePath );
        // UObject* Outer = nullptr;
        UTexture2D * mytexture = MyCreateTexture (* RawData , ImageWrapper -> GetWidth (), ImageWrapper -> GetHeight (), EPixelFormat :: PF_B8G8R8A8 , FName ( * TextureBaseName ));
        return mytexture ;


UTexture2D * SDrawHouseTypeTools :: MyCreateTexture ( const TArray < uint8 >& PixelData , int32 InSizeX , int32 InSizeY , EPixelFormat InFormat , FName BaseName )
{
        // Shamelessly copied from UTexture2D::CreateTransient with a few modifications
        if ( InSizeX <= 0 || InSizeY <= 0 ||
              ( InSizeX % GPixelFormats [ InFormat ]. BlockSizeX ) != 0 ||
              ( InSizeY % GPixelFormats [ InFormat ]. BlockSizeY ) != 0)
       {
               //UIL_LOG(Warning, TEXT("Invalid parameters specified for UImageLoader::CreateTexture()"));
               return nullptr ;
       }
        // Most important difference with UTexture2D::CreateTransient: we provide the new texture with a name and an owner
#if 0
        FName TextureName = MakeUniqueObjectName ( Outer , UTexture2D :: StaticClass (), BaseName );
#endif
        UTexture2D * NewTexture = NewObject < UTexture2D >( GetTransientPackage (), NAME_None , RF_Transient );
        NewTexture -> PlatformData = new FTexturePlatformData ();
        NewTexture -> PlatformData -> SizeX = InSizeX ;
        NewTexture -> PlatformData -> SizeY = InSizeY ;
        NewTexture -> PlatformData -> PixelFormat = InFormat ;
        // Allocate first mipmap and upload the pixel data
        int32 NumBlocksX = InSizeX / GPixelFormats [ InFormat ]. BlockSizeX ;
        int32 NumBlocksY = InSizeY / GPixelFormats [ InFormat ]. BlockSizeY ;
        FTexture2DMipMap * Mip = new ( NewTexture -> PlatformData -> Mips ) FTexture2DMipMap ();
        Mip -> SizeX = InSizeX ;
        Mip -> SizeY = InSizeY ;
        Mip -> BulkData . Lock ( LOCK_READ_WRITE );
        void * TextureData = Mip -> BulkData . Realloc ( NumBlocksX * NumBlocksY * GPixelFormats [ InFormat ]. BlockBytes );
        FMemory :: Memcpy ( TextureData , PixelData . GetData (), PixelData . Num ());
        Mip -> BulkData . Unlock ();
        NewTexture -> UpdateResource ();
        return NewTexture ;
}

转载于:https://www.cnblogs.com/huojiaoqingchun0123/p/7083920.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要将 Revit 模型中的纹理图片单独导出,可以这样做: 1. 打开 Revit 模型,选择你要导出纹理的元素。 2. 选择 "视图" 菜单,然后选择 "纹理" 选项卡。 3. 在 "纹理" 选项卡中,选择你要导出的纹理。 4. 右键单击纹理,然后选择 "导出"。 5. 选择你要保存纹理文件夹,然后输入文件名。 6. 点击 "保存",纹理将被导出到指定文件夹中。 请注意,这可能因 Revit 版本的不同而有所不同,因此建议查阅 Revit 帮助文档以获取最新的操作步骤。 ### 回答2: 要将Revit模型中的纹理图片单独导出,您可以按照以下步骤操作: 1. 打开Revit软件,并加载您想要导出纹理的模型。 2. 进入3D视图或者在视图中选择一个特定的元素,这些元素将使用纹理。 3. 在Revit界面的“查看”选项卡下,找到“生成”面板,并选择“导出”工具。 4. 在弹出的导出对话框中,选择希望导出的文件格式,例如OBJ或FBX。 5. 在导出对话框的“选项”面板中,您可以设置一些导出选项,比如文件路径和名称。 6. 在“选项”面板中,找到“材质”选项,将其设置为“链接至原始文件”。这将确保导出的模型文件将链接到原始纹理文件,而不是复制它们。 7. 点击“确定”按钮开始导出模型。导出的文件将包含模型的几何形状和链接的纹理文件。 8. 打开导出的模型文件,使用相应的3D建模软件(如3ds Max或Maya)加载它。 9. 在加载的模型中,您可以找到和提取链接的纹理文件。这些纹理文件通常以特定的命名约定进行存储,您可以在软件的资源浏览器或贴图编辑器中找到它们。 需要注意的是,导出的模型和纹理文件可能不会与Revit中的完全一致,因为不同软件之间存在一些差异。但是,此方法可以让您单独导出纹理文件,以便后续在其他软件中使用。 ### 回答3: 要将Revit模型中的纹理图片单独导出,你可以按照以下步骤操作: 1. 打开Revit软件并加载你想要导出纹理图片的模型。 2. 单击顶部菜单中的“视图”选项,然后在下拉菜单中选择“3D视图”。 3. 在“3D视图”中,旋转和缩放模型以确保你可以清楚地看到想要导出的纹理。 4. 单击顶部菜单中的“添加-图像”选项。这将打开一个新的对话框。 5. 在对话框中,点击“浏览”按钮,选择一个保存纹理的目录。 6. 点击“确定”按钮后,会自动将选中的视图导出为纹理图片。你可以在选定的目录中找到导出的纹理图片文件。 注意事项: - 确保你已经将模型中的所有纹理正确应用于对象。 - 导出的纹理图片可能包含整个模型的视角,所以在进行导出前需要根据需要调整视图和尺寸。 - 需要在模型中进行材质编辑时慎重使用这个方法,因为导出的纹理可能与实际效果略有不同。 通过以上步骤,你可以将Revit模型中的纹理图片单独导出。这对于创建项目文档、制作展示或在其他设计软件中使用纹理都非常有用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值