Integrating ozz-animation C++ Library with CMake on Windows & Ubuntu Интеграция C++-библиотеки ozz-animation с CMake под Windows и Ubuntu
A step-by-step guide to configuring and integrating the ozz-animation 3D animation library in your CMake projects on Windows and Ubuntu. Пошаговое руководство по настройке и интеграции библиотеки 3D-анимации ozz-animation в проекты CMake под Windows и Ubuntu.
Step 1: Create Project Directory Шаг 1: Создание директории проекта
Create a workspace folder and a new directory for your ozz-animation test project: Создайте рабочую папку для проектов и новую директорию для вашего тестового проекта ozz-animation:
Windows (Command Prompt / PowerShell)
mkdir C:\projects\ozz-test
cd C:\projects\ozz-test
Ubuntu (Terminal)
mkdir -p ~/projects/ozz-test
cd ~/projects/ozz-test
Step 2: Create Source Files (main.cpp & CMakeLists.txt) Шаг 2: Создание исходных файлов (main.cpp и CMakeLists.txt)
You can create these files using Notepad / Sublime Text on Windows, or nano in Ubuntu terminal:
Вы можете создать эти файлы через Блокнот / Sublime Text в Windows или с помощью nano в терминале Ubuntu:
Windows (Terminal / Notepad)
notepad main.cpp
notepad CMakeLists.txt
Ubuntu (Terminal / Nano)
nano main.cpp
nano CMakeLists.txt
1. File Contents for main.cpp 1. Содержимое файла main.cpp
#include <iostream>
#include <ozz/base/maths/vec_float.h>
int main() {
ozz::math::Float3 v1(1.0f, 2.0f, 3.0f);
ozz::math::Float3 v2(4.0f, 5.0f, 6.0f);
ozz::math::Float3 result = v1 + v2;
std::cout << "Result vector: [" << result.x << ", " << result.y << ", " << result.z << "]" << std::endl;
return 0;
}
2. File Contents for CMakeLists.txt 2. Содержимое файла CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(ozz_test CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(app main.cpp)
if(WIN32)
set(OZZ_DIR "C:/libs/ozz-animation-0.17.0-mingw")
target_include_directories(app PRIVATE ${OZZ_DIR}/include)
target_link_directories(app PRIVATE ${OZZ_DIR}/lib)
target_link_libraries(app PRIVATE ozz_base_r)
else()
set(OZZ_DIR "$ENV{HOME}/libs/ozz-animation-0.17.0-ubuntu")
target_include_directories(app PRIVATE ${OZZ_DIR}/include)
target_link_directories(app PRIVATE ${OZZ_DIR}/lib)
target_link_libraries(app PRIVATE ozz_base_r)
endif()
Step 3: Create Build & Execution Scripts Шаг 3: Создание скриптов сборки и запуска
Windows (MinGW / Batch Scripts)
config-exe.bat
cmake -G Ninja -S . -B dist/win
build-exe.bat
cmake --build dist/win
run-exe.bat
@echo off
.\dist\win\app.exe
Run the scripts sequentially in Command Prompt or PowerShell: Последовательно запустите скрипты в командной строке или PowerShell:
config-exe.bat
build-exe.bat
run-exe.bat
Ubuntu (Bash Scripts)
config-bin.sh
#!/usr/bin/env bash
set -e
cmake -G Ninja -S . -B dist/linux
build-bin.sh
#!/usr/bin/env bash
set -e
cmake --build dist/linux
run-bin.sh
#!/usr/bin/env bash
set -e
./dist/linux/app
Grant execute permissions on Ubuntu before running: Предоставьте права на выполнение в Ubuntu перед запуском:
chmod +x config-bin.sh build-bin.sh run-bin.sh
./config-bin.sh
./build-bin.sh
./run-bin.sh
Step 4: Expected Output Шаг 4: Ожидаемый результат
After running the build and execution scripts, you should see output similar to this: После запуска скриптов сборки и выполнения вы должны увидеть результат, похожий на следующий:
C:\projects\ozz-test>run-exe
Result vector: [5, 7, 9]
Step 5: Convert glTF / GLB to .ozz Format (gltf2ozz) Шаг 5: Конвертация glTF / GLB в формат .ozz (gltf2ozz)
To convert a 3D model (glTF / GLB) containing a skeleton and animations into runtime-ready binary .ozz files, run the gltf2ozz command-line tool with a JSON configuration:
Чтобы преобразовать 3D-модель (glTF / GLB), содержащую скелет и анимации, в готовые к загрузке бинарные файлы .ozz, выполните утилиту gltf2ozz с JSON-конфигурацией:
gltf2ozz --file="scene.glb" --config="{\"skeleton\":{\"filename\":\"skeleton.ozz\"},\"animations\":[{\"clip\":\"*\",\"filename\":\"animation.ozz\"}]}"
This exports the model hierarchy into skeleton.ozz and all matching animation clips into animation.ozz.
Эта команда экспортирует иерархию костей в skeleton.ozz, а все подходящие анимационные клипы — в animation.ozz.
Support My Work Поддержать проект
If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.
Sberbank (Russia only) Сбербанк (только для РФ)
Direct transfer via phone number (Russia only) Перевод по номеру телефона (только для РФ)
USDT TRC20
Support via Cryptocurrency Поддержка криптовалютой