file_path
stringlengths
21
202
content
stringlengths
19
1.02M
size
int64
19
1.02M
lang
stringclasses
8 values
avg_line_length
float64
5.88
100
max_line_length
int64
12
993
alphanum_fraction
float64
0.27
0.93
isaac-orbit/orbit.ext_template/README.md
# Extension Template for Orbit [![IsaacSim](https://img.shields.io/badge/IsaacSim-2023.1.1-silver.svg)](https://docs.omniverse.nvidia.com/isaacsim/latest/overview.html) [![Orbit](https://img.shields.io/badge/Orbit-0.2.0-silver)](https://isaac-orbit.github.io/orbit/) [![Python](https://img.shields.io/badge/python-3.10-blue.svg)](https://docs.python.org/3/whatsnew/3.10.html) [![Linux platform](https://img.shields.io/badge/platform-linux--64-orange.svg)](https://releases.ubuntu.com/20.04/) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://pre-commit.com/) ## Overview This repository serves as a template for building projects or extensions based on Orbit. It allows you to develop in an isolated environment, outside of the core Orbit repository. Furthermore, this template serves three use cases: - **Python Package** Can be installed into Isaac Sim's Python environment, making it suitable for users who want to integrate their extension to `Orbit` as a python package. - **Project Template** Ensures access to `Isaac Sim` and `Orbit` functionalities, which can be used as a project template. - **Omniverse Extension** Can be used as an Omniverse extension, ideal for projects that leverage the Omniverse platform's graphical user interface. **Key Features:** - `Isolation` Work outside the core Orbit repository, ensuring that your development efforts remain self-contained. - `Flexibility` This template is set up to allow your code to be run as an extension in Omniverse. **Keywords:** extension, template, orbit ### License The source code is released under a [BSD 3-Clause license](https://opensource.org/licenses/BSD-3-Clause). **Author: The ORBIT Project Developers<br /> Affiliation: [The AI Institute](https://theaiinstitute.com/)<br /> Maintainer: Nico Burger, [email protected]** ## Setup Depending on the use case defined [above](#overview), follow the instructions to set up your extension template. Start with the [Basic Setup](#basic-setup), which is required for either use case. ### Basic Setup #### Dependencies This template depends on Isaac Sim and Orbit. For detailed instructions on how to install these dependencies, please refer to the [installation guide](https://isaac-orbit.github.io/orbit/source/setup/installation.html). - [Isaac Sim](https://docs.omniverse.nvidia.com/isaacsim/latest/index.html) - [Orbit](https://isaac-orbit.github.io/orbit/) #### Configuration Decide on a name for your project or extension. This guide will refer to this name as `<your_extension_name>`. - Create a new repository based off this template [here](https://github.com/new?owner=isaac-orbit&template_name=orbit.ext_template&template_owner=isaac-orbit). Name your forked repository using the following convention: `"orbit.<your_extension_name>"`. - Clone your forked repository to a location **outside** the orbit repository. ```bash git clone <your_repository_url> ``` - Configure the template. Search for and replace **`TODO`**'s according to your extension's needs within the following files: - `config/extension.toml` - `pyproject.toml` - Rename your source folder. ```bash cd orbit.<your_extension_name> mv orbit/ext_template orbit/<your_extension_name> ``` - Set up a symbolic link from Orbit to this directory. This makes it convenient to index the python modules and look for extensions shipped with Isaac Sim and Orbit. ```bash ln -s <your_orbit_path> _orbit ``` #### Environment (Optional) For clarity, we will be using the `${ISAACSIM_PATH}/python.sh` command to call the Orbit specific python interpreter. However, you might be working from within a virtual environment, allowing you to use the `python` command directly, instead of `${ISAACSIM_PATH}/python.sh`. Information on setting up a virtual environment for Orbit can be found [here](https://isaac-orbit.github.io/orbit/source/setup/installation.html#setting-up-the-environment). The `ISAACSIM_PATH` should already be set from installing Orbit, see [here](https://isaac-orbit.github.io/orbit/source/setup/installation.html#configuring-the-environment-variables). #### Configure Python Interpreter In the provided configuration, we set the default Python interpreter to use the Python executable provided by Omniverse. This is specified in the `.vscode/settings.json` file: ```json "python.defaultInterpreterPath": "${env:ISAACSIM_PATH}/python.sh" ``` This setup requires you to have set up the `ISAACSIM_PATH` environment variable. If you want to use a different Python interpreter, you need to change the Python interpreter used by selecting and activating the Python interpreter of your choice in the bottom left corner of VSCode, or opening the command palette (`Ctrl+Shift+P`) and selecting `Python: Select Interpreter`. #### Set up IDE To setup the IDE, please follow these instructions: 1. Open the `orbit.<your_extension_template>` directory on Visual Studio Code IDE 2. Run VSCode Tasks, by pressing Ctrl+Shift+P, selecting Tasks: Run Task and running the setup_python_env in the drop down menu. If everything executes correctly, it should create a file .python.env in the .vscode directory. The file contains the python paths to all the extensions provided by Isaac Sim and Omniverse. This helps in indexing all the python modules for intelligent suggestions while writing code. ### Setup as Python Package / Project Template From within this repository, install your extension as a Python package to the Isaac Sim Python executable. ```bash ${ISAACSIM_PATH}/python.sh -m pip install --upgrade pip ${ISAACSIM_PATH}/python.sh -m pip install -e . ``` ### Setup as Omniverse Extension To enable your extension, follow these steps: 1. **Add the search path of your repository** to the extension manager: - Navigate to the extension manager using `Window` -> `Extensions`. - Click on the **Hamburger Icon** (☰), then go to `Settings`. - In the `Extension Search Paths`, enter the path that goes up to your repository's location without actually including the repository's own directory. For example, if your repository is located at `/home/code/orbit.ext_template`, you should add `/home/code` as the search path. - If not already present, in the `Extension Search Paths`, enter the path that leads to your local Orbit directory. For example: `/home/orbit/source/extensions` - Click on the **Hamburger Icon** (☰), then click `Refresh`. 2. **Search and enable your extension**: - Find your extension under the `Third Party` category. - Toggle it to enable your extension. ## Usage ### Python Package Import your python package within `Isaac Sim` and `Orbit` using: ```python import orbit.<your_extension_name> ``` ### Project Template We provide an example for training and playing a policy for ANYmal on flat terrain. Install [RSL_RL](https://github.com/leggedrobotics/rsl_rl) outside of the orbit repository, e.g. `home/code/rsl_rl`. ```bash git clone https://github.com/leggedrobotics/rsl_rl.git cd rsl_rl ${ISAACSIM_PATH}/python.sh -m pip install -e . ``` Train a policy. ```bash cd <path_to_your_extension> ${ISAACSIM_PATH}/python.sh scripts/rsl_rl/train.py --task Isaac-Velocity-Flat-Anymal-D-Template-v0 --num_envs 4096 --headless ``` Play the trained policy. ```bash ${ISAACSIM_PATH}/python.sh scripts/rsl_rl/play.py --task Isaac-Velocity-Flat-Anymal-D-Template-Play-v0 --num_envs 16 ``` ### Omniverse Extension We provide an example UI extension that will load upon enabling your extension defined in `orbit/ext_template/ui_extension_example.py`. For more information on UI extensions, enable and check out the source code of the `omni.isaac.ui_template` extension and refer to the introduction on [Isaac Sim Workflows 1.2.3. GUI](https://docs.omniverse.nvidia.com/isaacsim/latest/introductory_tutorials/tutorial_intro_workflows.html#gui). ## Pre-Commit Pre-committing involves using a framework to automate the process of enforcing code quality standards before code is actually committed to a version control system, like Git. This process involves setting up hooks that run automated checks, such as code formatting, linting (checking for programming errors, bugs, stylistic errors, and suspicious constructs), and running tests. If these checks pass, the commit is allowed; if not, the commit is blocked until the issues are resolved. This ensures that all code committed to the repository adheres to the defined quality standards, leading to a cleaner, more maintainable codebase. To do so, we use the [pre-commit](https://pre-commit.com/) module. Install the module using: ```bash pip install pre-commit ``` Run the pre-commit with: ```bash pre-commit run --all-files ``` ## Finalize You are all set and no longer need the template instructions - The `orbit/ext_template` and `scripts/rsl_rl` directories act as a reference template for your convenience. Delete them if no longer required. - When ready, use this `README.md` as a template and customize where appropriate. ## Docker / Cluster We are currently working on a docker and cluster setup for this template. In the meanwhile, please refer to the current setup provided in the Orbit [documentation](https://isaac-orbit.github.io/orbit/source/deployment/index.html). ## Troubleshooting ### Docker Container When running within a docker container, the following error has been encountered: `ModuleNotFoundError: No module named 'orbit'`. To mitigate, please comment out the docker specific environment definitions in `.vscode/launch.json` and run the following: ```bash echo -e "\nexport PYTHONPATH=\$PYTHONPATH:/workspace/orbit.<your_extension_name>" >> ~/.bashrc source ~/.bashrc ``` ## Bugs & Feature Requests Please report bugs and request features using the [Issue Tracker](https://github.com/isaac-orbit/orbit.ext_template/issues).
9,898
Markdown
47.053398
724
0.761871
isaac-orbit/orbit.ext_template/scripts/rsl_rl/play.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Script to play a checkpoint if an RL agent from RSL-RL.""" from __future__ import annotations """Launch Isaac Sim Simulator first.""" import argparse from omni.isaac.orbit.app import AppLauncher # local imports import cli_args # isort: skip # add argparse arguments parser = argparse.ArgumentParser(description="Train an RL agent with RSL-RL.") parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.") parser.add_argument("--num_envs", type=int, default=None, help="Number of environments to simulate.") parser.add_argument("--task", type=str, default=None, help="Name of the task.") parser.add_argument("--seed", type=int, default=None, help="Seed used for the environment") # append RSL-RL cli arguments cli_args.add_rsl_rl_args(parser) # append AppLauncher cli args AppLauncher.add_app_launcher_args(parser) args_cli = parser.parse_args() # launch omniverse app app_launcher = AppLauncher(args_cli) simulation_app = app_launcher.app """Rest everything follows.""" import os import gymnasium as gym import omni.isaac.contrib_tasks # noqa: F401 import omni.isaac.orbit_tasks # noqa: F401 import torch from omni.isaac.orbit_tasks.utils import get_checkpoint_path, parse_env_cfg from omni.isaac.orbit_tasks.utils.wrappers.rsl_rl import ( RslRlOnPolicyRunnerCfg, RslRlVecEnvWrapper, export_policy_as_onnx, ) from rsl_rl.runners import OnPolicyRunner # Import extensions to set up environment tasks import orbit.ext_template.tasks # noqa: F401 TODO: import orbit.<your_extension_name> def main(): """Play with RSL-RL agent.""" # parse configuration env_cfg = parse_env_cfg(args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs) agent_cfg: RslRlOnPolicyRunnerCfg = cli_args.parse_rsl_rl_cfg(args_cli.task, args_cli) # create isaac environment env = gym.make(args_cli.task, cfg=env_cfg) # wrap around environment for rsl-rl env = RslRlVecEnvWrapper(env) # specify directory for logging experiments log_root_path = os.path.join("logs", "rsl_rl", agent_cfg.experiment_name) log_root_path = os.path.abspath(log_root_path) print(f"[INFO] Loading experiment from directory: {log_root_path}") resume_path = get_checkpoint_path(log_root_path, agent_cfg.load_run, agent_cfg.load_checkpoint) print(f"[INFO]: Loading model checkpoint from: {resume_path}") # load previously trained model ppo_runner = OnPolicyRunner(env, agent_cfg.to_dict(), log_dir=None, device=agent_cfg.device) ppo_runner.load(resume_path) print(f"[INFO]: Loading model checkpoint from: {resume_path}") # obtain the trained policy for inference policy = ppo_runner.get_inference_policy(device=env.unwrapped.device) # export policy to onnx export_model_dir = os.path.join(os.path.dirname(resume_path), "exported") export_policy_as_onnx(ppo_runner.alg.actor_critic, export_model_dir, filename="policy.onnx") # reset environment obs, _ = env.get_observations() # simulate environment while simulation_app.is_running(): # run everything in inference mode with torch.inference_mode(): # agent stepping actions = policy(obs) # env stepping obs, _, _, _ = env.step(actions) # close the simulator env.close() if __name__ == "__main__": # run the main execution main() # close sim app simulation_app.close()
3,566
Python
32.027777
101
0.706955
isaac-orbit/orbit.ext_template/scripts/rsl_rl/cli_args.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from __future__ import annotations import argparse from typing import TYPE_CHECKING if TYPE_CHECKING: from omni.isaac.orbit_tasks.utils.wrappers.rsl_rl import RslRlOnPolicyRunnerCfg def add_rsl_rl_args(parser: argparse.ArgumentParser): """Add RSL-RL arguments to the parser. Args: parser: The parser to add the arguments to. """ # create a new argument group arg_group = parser.add_argument_group("rsl_rl", description="Arguments for RSL-RL agent.") # -- experiment arguments arg_group.add_argument( "--experiment_name", type=str, default=None, help="Name of the experiment folder where logs will be stored." ) arg_group.add_argument("--run_name", type=str, default=None, help="Run name suffix to the log directory.") # -- load arguments arg_group.add_argument("--resume", type=bool, default=None, help="Whether to resume from a checkpoint.") arg_group.add_argument("--load_run", type=str, default=None, help="Name of the run folder to resume from.") arg_group.add_argument("--checkpoint", type=str, default=None, help="Checkpoint file to resume from.") # -- logger arguments arg_group.add_argument( "--logger", type=str, default=None, choices={"wandb", "tensorboard", "neptune"}, help="Logger module to use." ) arg_group.add_argument( "--log_project_name", type=str, default=None, help="Name of the logging project when using wandb or neptune." ) def parse_rsl_rl_cfg(task_name: str, args_cli: argparse.Namespace) -> RslRlOnPolicyRunnerCfg: """Parse configuration for RSL-RL agent based on inputs. Args: task_name: The name of the environment. args_cli: The command line arguments. Returns: The parsed configuration for RSL-RL agent based on inputs. """ from omni.isaac.orbit_tasks.utils.parse_cfg import load_cfg_from_registry # load the default configuration rslrl_cfg: RslRlOnPolicyRunnerCfg = load_cfg_from_registry(task_name, "rsl_rl_cfg_entry_point") # override the default configuration with CLI arguments if args_cli.seed is not None: rslrl_cfg.seed = args_cli.seed if args_cli.resume is not None: rslrl_cfg.resume = args_cli.resume if args_cli.load_run is not None: rslrl_cfg.load_run = args_cli.load_run if args_cli.checkpoint is not None: rslrl_cfg.load_checkpoint = args_cli.checkpoint if args_cli.run_name is not None: rslrl_cfg.run_name = args_cli.run_name if args_cli.logger is not None: rslrl_cfg.logger = args_cli.logger # set the project name for wandb and neptune if rslrl_cfg.logger in {"wandb", "neptune"} and args_cli.log_project_name: rslrl_cfg.wandb_project = args_cli.log_project_name rslrl_cfg.neptune_project = args_cli.log_project_name return rslrl_cfg
2,981
Python
38.759999
117
0.688695
isaac-orbit/orbit.ext_template/scripts/rsl_rl/train.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Script to train RL agent with RSL-RL.""" from __future__ import annotations """Launch Isaac Sim Simulator first.""" import argparse import os from omni.isaac.orbit.app import AppLauncher # local imports import cli_args # isort: skip # add argparse arguments parser = argparse.ArgumentParser(description="Train an RL agent with RSL-RL.") parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.") parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).") parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).") parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.") parser.add_argument("--num_envs", type=int, default=None, help="Number of environments to simulate.") parser.add_argument("--task", type=str, default=None, help="Name of the task.") parser.add_argument("--seed", type=int, default=None, help="Seed used for the environment") # append RSL-RL cli arguments cli_args.add_rsl_rl_args(parser) # append AppLauncher cli args AppLauncher.add_app_launcher_args(parser) args_cli = parser.parse_args() # load cheaper kit config in headless if args_cli.headless: app_experience = f"{os.environ['EXP_PATH']}/omni.isaac.sim.python.gym.headless.kit" else: app_experience = f"{os.environ['EXP_PATH']}/omni.isaac.sim.python.kit" # launch omniverse app app_launcher = AppLauncher(args_cli, experience=app_experience) simulation_app = app_launcher.app """Rest everything follows.""" import os from datetime import datetime import gymnasium as gym import omni.isaac.orbit_tasks # noqa: F401 import torch from omni.isaac.orbit.envs import RLTaskEnvCfg from omni.isaac.orbit.utils.dict import print_dict from omni.isaac.orbit.utils.io import dump_pickle, dump_yaml from omni.isaac.orbit_tasks.utils import get_checkpoint_path, parse_env_cfg from omni.isaac.orbit_tasks.utils.wrappers.rsl_rl import ( RslRlOnPolicyRunnerCfg, RslRlVecEnvWrapper, ) from rsl_rl.runners import OnPolicyRunner # Import extensions to set up environment tasks import orbit.ext_template.tasks # noqa: F401 TODO: import orbit.<your_extension_name> torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = True torch.backends.cudnn.deterministic = False torch.backends.cudnn.benchmark = False def main(): """Train with RSL-RL agent.""" # parse configuration env_cfg: RLTaskEnvCfg = parse_env_cfg(args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs) agent_cfg: RslRlOnPolicyRunnerCfg = cli_args.parse_rsl_rl_cfg(args_cli.task, args_cli) # specify directory for logging experiments log_root_path = os.path.join("logs", "rsl_rl", agent_cfg.experiment_name) log_root_path = os.path.abspath(log_root_path) print(f"[INFO] Logging experiment in directory: {log_root_path}") # specify directory for logging runs: {time-stamp}_{run_name} log_dir = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") if agent_cfg.run_name: log_dir += f"_{agent_cfg.run_name}" log_dir = os.path.join(log_root_path, log_dir) # create isaac environment env = gym.make(args_cli.task, cfg=env_cfg, render_mode="rgb_array" if args_cli.video else None) # wrap for video recording if args_cli.video: video_kwargs = { "video_folder": os.path.join(log_dir, "videos"), "step_trigger": lambda step: step % args_cli.video_interval == 0, "video_length": args_cli.video_length, "disable_logger": True, } print("[INFO] Recording videos during training.") print_dict(video_kwargs, nesting=4) env = gym.wrappers.RecordVideo(env, **video_kwargs) # wrap around environment for rsl-rl env = RslRlVecEnvWrapper(env) # create runner from rsl-rl runner = OnPolicyRunner(env, agent_cfg.to_dict(), log_dir=log_dir, device=agent_cfg.device) # write git state to logs runner.add_git_repo_to_log(__file__) # save resume path before creating a new log_dir if agent_cfg.resume: # get path to previous checkpoint resume_path = get_checkpoint_path(log_root_path, agent_cfg.load_run, agent_cfg.load_checkpoint) print(f"[INFO]: Loading model checkpoint from: {resume_path}") # load previously trained model runner.load(resume_path) # set seed of the environment env.seed(agent_cfg.seed) # dump the configuration into log-directory dump_yaml(os.path.join(log_dir, "params", "env.yaml"), env_cfg) dump_yaml(os.path.join(log_dir, "params", "agent.yaml"), agent_cfg) dump_pickle(os.path.join(log_dir, "params", "env.pkl"), env_cfg) dump_pickle(os.path.join(log_dir, "params", "agent.pkl"), agent_cfg) # run training runner.learn(num_learning_iterations=agent_cfg.max_iterations, init_at_random_ep_len=True) # close the simulator env.close() if __name__ == "__main__": # run the main execution main() # close sim app simulation_app.close()
5,231
Python
36.640288
117
0.703307
isaac-orbit/orbit.ext_template/config/extension.toml
[package] # Semantic Versioning is used: https://semver.org/ version = "0.1.0" # Description title = "Extension Template" # TODO: Please adapt to your title. description="Extension Template for Orbit" #TODO: Please adapt to your description. repository = "https://github.com/isaac-orbit/orbit.ext_template.git" # TODO: Please adapt to your repository. keywords = ["extension", "template", "orbit"] # TODO: Please adapt to your keywords. category = "orbit" readme = "README.md" [dependencies] "omni.kit.uiapp" = {} "omni.isaac.orbit" = {} "omni.isaac.orbit_assets" = {} "omni.isaac.orbit_tasks" = {} "omni.isaac.core" = {} "omni.isaac.gym" = {} "omni.replicator.isaac" = {} # Note: You can add additional dependencies here for your extension. # For example, if you want to use the omni.kit module, you can add it as a dependency: # "omni.kit" = {} [[python.module]] name = "orbit.ext_template" # TODO: Please adapt to your package name.
946
TOML
32.821427
110
0.700846
isaac-orbit/orbit.ext_template/orbit/ext_template/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """ Python module serving as a project/extension template. """ # Register Gym environments. from .tasks import * # Register UI extensions. from .ui_extension_example import *
300
Python
19.066665
56
0.743333
isaac-orbit/orbit.ext_template/orbit/ext_template/ui_extension_example.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause import omni.ext import omni.ui as ui # Functions and vars are available to other extension as usual in python: `example.python_ext.some_public_function(x)` def some_public_function(x: int): print("[orbit.ext_template] some_public_function was called with x: ", x) return x**x # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled # on_shutdown() is called. class ExampleExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[orbit.ext_template] startup") self._count = 0 self._window = ui.Window("My Window", width=300, height=300) with self._window.frame: with ui.VStack(): label = ui.Label("") def on_click(): self._count += 1 label.text = f"count: {self._count}" def on_reset(): self._count = 0 label.text = "empty" on_reset() with ui.HStack(): ui.Button("Add", clicked_fn=on_click) ui.Button("Reset", clicked_fn=on_reset) def on_shutdown(self): print("[orbit.ext_template] shutdown")
1,650
Python
33.395833
119
0.609697
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Package containing task implementations for various robotic environments.""" import os import toml # Conveniences to other module directories via relative paths ORBIT_TASKS_EXT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../")) """Path to the extension source directory.""" ORBIT_TASKS_METADATA = toml.load(os.path.join(ORBIT_TASKS_EXT_DIR, "config", "extension.toml")) """Extension metadata dictionary parsed from the extension.toml file.""" # Configure the module-level variables __version__ = ORBIT_TASKS_METADATA["package"]["version"] ## # Register Gym environments. ## from omni.isaac.orbit_tasks.utils import import_packages # The blacklist is used to prevent importing configs from sub-packages _BLACKLIST_PKGS = ["utils"] # Import all configs in this package import_packages(__name__, _BLACKLIST_PKGS)
969
Python
29.312499
95
0.744066
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Locomotion environments for legged robots.""" from .velocity import * # noqa
205
Python
21.888886
56
0.731707
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/velocity_env_cfg.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from __future__ import annotations import math from dataclasses import MISSING import omni.isaac.orbit.sim as sim_utils from omni.isaac.orbit.assets import ArticulationCfg, AssetBaseCfg from omni.isaac.orbit.envs import RLTaskEnvCfg from omni.isaac.orbit.managers import CurriculumTermCfg as CurrTerm from omni.isaac.orbit.managers import ObservationGroupCfg as ObsGroup from omni.isaac.orbit.managers import ObservationTermCfg as ObsTerm from omni.isaac.orbit.managers import RandomizationTermCfg as RandTerm from omni.isaac.orbit.managers import RewardTermCfg as RewTerm from omni.isaac.orbit.managers import SceneEntityCfg from omni.isaac.orbit.managers import TerminationTermCfg as DoneTerm from omni.isaac.orbit.scene import InteractiveSceneCfg from omni.isaac.orbit.sensors import ContactSensorCfg, RayCasterCfg, patterns from omni.isaac.orbit.terrains import TerrainImporterCfg from omni.isaac.orbit.utils import configclass from omni.isaac.orbit.utils.noise import AdditiveUniformNoiseCfg as Unoise import orbit.ext_template.tasks.locomotion.velocity.mdp as mdp ## # Pre-defined configs ## from omni.isaac.orbit.terrains.config.rough import ROUGH_TERRAINS_CFG # isort: skip ## # Scene definition ## @configclass class MySceneCfg(InteractiveSceneCfg): """Configuration for the terrain scene with a legged robot.""" # ground terrain terrain = TerrainImporterCfg( prim_path="/World/ground", terrain_type="generator", terrain_generator=ROUGH_TERRAINS_CFG, max_init_terrain_level=5, collision_group=-1, physics_material=sim_utils.RigidBodyMaterialCfg( friction_combine_mode="multiply", restitution_combine_mode="multiply", static_friction=1.0, dynamic_friction=1.0, ), visual_material=sim_utils.MdlFileCfg( mdl_path="{NVIDIA_NUCLEUS_DIR}/Materials/Base/Architecture/Shingles_01.mdl", project_uvw=True, ), debug_vis=False, ) # robots robot: ArticulationCfg = MISSING # sensors height_scanner = RayCasterCfg( prim_path="{ENV_REGEX_NS}/Robot/base", offset=RayCasterCfg.OffsetCfg(pos=(0.0, 0.0, 20.0)), attach_yaw_only=True, pattern_cfg=patterns.GridPatternCfg(resolution=0.1, size=[1.6, 1.0]), debug_vis=False, mesh_prim_paths=["/World/ground"], ) contact_forces = ContactSensorCfg(prim_path="{ENV_REGEX_NS}/Robot/.*", history_length=3, track_air_time=True) # lights light = AssetBaseCfg( prim_path="/World/light", spawn=sim_utils.DistantLightCfg(color=(0.75, 0.75, 0.75), intensity=3000.0), ) sky_light = AssetBaseCfg( prim_path="/World/skyLight", spawn=sim_utils.DomeLightCfg(color=(0.13, 0.13, 0.13), intensity=1000.0), ) ## # MDP settings ## @configclass class CommandsCfg: """Command specifications for the MDP.""" base_velocity = mdp.UniformVelocityCommandCfg( asset_name="robot", resampling_time_range=(10.0, 10.0), rel_standing_envs=0.02, rel_heading_envs=1.0, heading_command=True, heading_control_stiffness=0.5, debug_vis=True, ranges=mdp.UniformVelocityCommandCfg.Ranges( lin_vel_x=(-1.0, 1.0), lin_vel_y=(-1.0, 1.0), ang_vel_z=(-1.0, 1.0), heading=(-math.pi, math.pi) ), ) @configclass class ActionsCfg: """Action specifications for the MDP.""" joint_pos = mdp.JointPositionActionCfg(asset_name="robot", joint_names=[".*"], scale=0.5, use_default_offset=True) @configclass class ObservationsCfg: """Observation specifications for the MDP.""" @configclass class PolicyCfg(ObsGroup): """Observations for policy group.""" # observation terms (order preserved) base_lin_vel = ObsTerm(func=mdp.base_lin_vel, noise=Unoise(n_min=-0.1, n_max=0.1)) base_ang_vel = ObsTerm(func=mdp.base_ang_vel, noise=Unoise(n_min=-0.2, n_max=0.2)) projected_gravity = ObsTerm( func=mdp.projected_gravity, noise=Unoise(n_min=-0.05, n_max=0.05), ) velocity_commands = ObsTerm(func=mdp.generated_commands, params={"command_name": "base_velocity"}) joint_pos = ObsTerm(func=mdp.joint_pos_rel, noise=Unoise(n_min=-0.01, n_max=0.01)) joint_vel = ObsTerm(func=mdp.joint_vel_rel, noise=Unoise(n_min=-1.5, n_max=1.5)) actions = ObsTerm(func=mdp.last_action) height_scan = ObsTerm( func=mdp.height_scan, params={"sensor_cfg": SceneEntityCfg("height_scanner")}, noise=Unoise(n_min=-0.1, n_max=0.1), clip=(-1.0, 1.0), ) def __post_init__(self): self.enable_corruption = True self.concatenate_terms = True # observation groups policy: PolicyCfg = PolicyCfg() @configclass class RandomizationCfg: """Configuration for randomization.""" # startup physics_material = RandTerm( func=mdp.randomize_rigid_body_material, mode="startup", params={ "asset_cfg": SceneEntityCfg("robot", body_names=".*"), "static_friction_range": (0.8, 0.8), "dynamic_friction_range": (0.6, 0.6), "restitution_range": (0.0, 0.0), "num_buckets": 64, }, ) add_base_mass = RandTerm( func=mdp.add_body_mass, mode="startup", params={"asset_cfg": SceneEntityCfg("robot", body_names="base"), "mass_range": (-5.0, 5.0)}, ) # reset base_external_force_torque = RandTerm( func=mdp.apply_external_force_torque, mode="reset", params={ "asset_cfg": SceneEntityCfg("robot", body_names="base"), "force_range": (0.0, 0.0), "torque_range": (-0.0, 0.0), }, ) reset_base = RandTerm( func=mdp.reset_root_state_uniform, mode="reset", params={ "pose_range": {"x": (-0.5, 0.5), "y": (-0.5, 0.5), "yaw": (-3.14, 3.14)}, "velocity_range": { "x": (-0.5, 0.5), "y": (-0.5, 0.5), "z": (-0.5, 0.5), "roll": (-0.5, 0.5), "pitch": (-0.5, 0.5), "yaw": (-0.5, 0.5), }, }, ) reset_robot_joints = RandTerm( func=mdp.reset_joints_by_scale, mode="reset", params={ "position_range": (0.5, 1.5), "velocity_range": (0.0, 0.0), }, ) # interval push_robot = RandTerm( func=mdp.push_by_setting_velocity, mode="interval", interval_range_s=(10.0, 15.0), params={"velocity_range": {"x": (-0.5, 0.5), "y": (-0.5, 0.5)}}, ) @configclass class RewardsCfg: """Reward terms for the MDP.""" # -- task track_lin_vel_xy_exp = RewTerm( func=mdp.track_lin_vel_xy_exp, weight=1.0, params={"command_name": "base_velocity", "std": math.sqrt(0.25)} ) track_ang_vel_z_exp = RewTerm( func=mdp.track_ang_vel_z_exp, weight=0.5, params={"command_name": "base_velocity", "std": math.sqrt(0.25)} ) # -- penalties lin_vel_z_l2 = RewTerm(func=mdp.lin_vel_z_l2, weight=-2.0) ang_vel_xy_l2 = RewTerm(func=mdp.ang_vel_xy_l2, weight=-0.05) dof_torques_l2 = RewTerm(func=mdp.joint_torques_l2, weight=-1.0e-5) dof_acc_l2 = RewTerm(func=mdp.joint_acc_l2, weight=-2.5e-7) action_rate_l2 = RewTerm(func=mdp.action_rate_l2, weight=-0.01) feet_air_time = RewTerm( func=mdp.feet_air_time, weight=0.125, params={ "sensor_cfg": SceneEntityCfg("contact_forces", body_names=".*FOOT"), "command_name": "base_velocity", "threshold": 0.5, }, ) undesired_contacts = RewTerm( func=mdp.undesired_contacts, weight=-1.0, params={"sensor_cfg": SceneEntityCfg("contact_forces", body_names=".*THIGH"), "threshold": 1.0}, ) # -- optional penalties flat_orientation_l2 = RewTerm(func=mdp.flat_orientation_l2, weight=0.0) dof_pos_limits = RewTerm(func=mdp.joint_pos_limits, weight=0.0) @configclass class TerminationsCfg: """Termination terms for the MDP.""" time_out = DoneTerm(func=mdp.time_out, time_out=True) base_contact = DoneTerm( func=mdp.illegal_contact, params={"sensor_cfg": SceneEntityCfg("contact_forces", body_names="base"), "threshold": 1.0}, ) @configclass class CurriculumCfg: """Curriculum terms for the MDP.""" terrain_levels = CurrTerm(func=mdp.terrain_levels_vel) ## # Environment configuration ## @configclass class LocomotionVelocityRoughEnvCfg(RLTaskEnvCfg): """Configuration for the locomotion velocity-tracking environment.""" # Scene settings scene: MySceneCfg = MySceneCfg(num_envs=4096, env_spacing=2.5) # Basic settings observations: ObservationsCfg = ObservationsCfg() actions: ActionsCfg = ActionsCfg() commands: CommandsCfg = CommandsCfg() # MDP settings rewards: RewardsCfg = RewardsCfg() terminations: TerminationsCfg = TerminationsCfg() randomization: RandomizationCfg = RandomizationCfg() curriculum: CurriculumCfg = CurriculumCfg() def __post_init__(self): """Post initialization.""" # general settings self.decimation = 4 self.episode_length_s = 20.0 # simulation settings self.sim.dt = 0.005 self.sim.disable_contact_processing = True self.sim.physics_material = self.scene.terrain.physics_material # update sensor update periods # we tick all the sensors based on the smallest update period (physics update period) if self.scene.height_scanner is not None: self.scene.height_scanner.update_period = self.decimation * self.sim.dt if self.scene.contact_forces is not None: self.scene.contact_forces.update_period = self.sim.dt # check if terrain levels curriculum is enabled - if so, enable curriculum for terrain generator # this generates terrains with increasing difficulty and is useful for training if getattr(self.curriculum, "terrain_levels", None) is not None: if self.scene.terrain.terrain_generator is not None: self.scene.terrain.terrain_generator.curriculum = True else: if self.scene.terrain.terrain_generator is not None: self.scene.terrain.terrain_generator.curriculum = False
10,649
Python
32.596214
118
0.626538
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Locomotion environments with velocity-tracking commands. These environments are based on the `legged_gym` environments provided by Rudin et al. Reference: https://github.com/leggedrobotics/legged_gym """
336
Python
24.923075
86
0.764881
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/mdp/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """This sub-module contains the functions that are specific to the locomotion environments.""" from omni.isaac.orbit.envs.mdp import * # noqa: F401, F403 from .curriculums import * # noqa: F401, F403 from .rewards import * # noqa: F401, F403
370
Python
29.916664
94
0.732432
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/mdp/curriculums.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Common functions that can be used to create curriculum for the learning environment. The functions can be passed to the :class:`omni.isaac.orbit.managers.CurriculumTermCfg` object to enable the curriculum introduced by the function. """ from __future__ import annotations from collections.abc import Sequence from typing import TYPE_CHECKING import torch from omni.isaac.orbit.assets import Articulation from omni.isaac.orbit.managers import SceneEntityCfg from omni.isaac.orbit.terrains import TerrainImporter if TYPE_CHECKING: from omni.isaac.orbit.envs import RLTaskEnv def terrain_levels_vel( env: RLTaskEnv, env_ids: Sequence[int], asset_cfg: SceneEntityCfg = SceneEntityCfg("robot") ) -> torch.Tensor: """Curriculum based on the distance the robot walked when commanded to move at a desired velocity. This term is used to increase the difficulty of the terrain when the robot walks far enough and decrease the difficulty when the robot walks less than half of the distance required by the commanded velocity. .. note:: It is only possible to use this term with the terrain type ``generator``. For further information on different terrain types, check the :class:`omni.isaac.orbit.terrains.TerrainImporter` class. Returns: The mean terrain level for the given environment ids. """ # extract the used quantities (to enable type-hinting) asset: Articulation = env.scene[asset_cfg.name] terrain: TerrainImporter = env.scene.terrain command = env.command_manager.get_command("base_velocity") # compute the distance the robot walked distance = torch.norm(asset.data.root_pos_w[env_ids, :2] - env.scene.env_origins[env_ids, :2], dim=1) # robots that walked far enough progress to harder terrains move_up = distance > terrain.cfg.terrain_generator.size[0] / 2 # robots that walked less than half of their required distance go to simpler terrains move_down = distance < torch.norm(command[env_ids, :2], dim=1) * env.max_episode_length_s * 0.5 move_down *= ~move_up # update terrain levels terrain.update_env_origins(env_ids, move_up, move_down) # return the mean terrain level return torch.mean(terrain.terrain_levels.float())
2,376
Python
41.446428
112
0.742424
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/mdp/rewards.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from __future__ import annotations from typing import TYPE_CHECKING import torch from omni.isaac.orbit.managers import SceneEntityCfg from omni.isaac.orbit.sensors import ContactSensor if TYPE_CHECKING: from omni.isaac.orbit.envs import RLTaskEnv def feet_air_time(env: RLTaskEnv, command_name: str, sensor_cfg: SceneEntityCfg, threshold: float) -> torch.Tensor: """Reward long steps taken by the feet using L2-kernel. This function rewards the agent for taking steps that are longer than a threshold. This helps ensure that the robot lifts its feet off the ground and takes steps. The reward is computed as the sum of the time for which the feet are in the air. If the commands are small (i.e. the agent is not supposed to take a step), then the reward is zero. """ # extract the used quantities (to enable type-hinting) contact_sensor: ContactSensor = env.scene.sensors[sensor_cfg.name] # compute the reward first_contact = contact_sensor.compute_first_contact(env.step_dt)[:, sensor_cfg.body_ids] last_air_time = contact_sensor.data.last_air_time[:, sensor_cfg.body_ids] reward = torch.sum((last_air_time - threshold) * first_contact, dim=1) # no reward for zero command reward *= torch.norm(env.command_manager.get_command(command_name)[:, :2], dim=1) > 0.1 return reward def feet_air_time_positive_biped(env, command_name: str, threshold: float, sensor_cfg: SceneEntityCfg) -> torch.Tensor: """Reward long steps taken by the feet for bipeds. This function rewards the agent for taking steps up to a specified threshold and also keep one foot at a time in the air. If the commands are small (i.e. the agent is not supposed to take a step), then the reward is zero. """ contact_sensor: ContactSensor = env.scene.sensors[sensor_cfg.name] # compute the reward air_time = contact_sensor.data.current_air_time[:, sensor_cfg.body_ids] contact_time = contact_sensor.data.current_contact_time[:, sensor_cfg.body_ids] in_contact = contact_time > 0.0 in_mode_time = torch.where(in_contact, contact_time, air_time) single_stance = torch.sum(in_contact.int(), dim=1) == 1 reward = torch.min(torch.where(single_stance.unsqueeze(-1), in_mode_time, 0.0), dim=1)[0] reward = torch.clamp(reward, max=threshold) # no reward for zero command reward *= torch.norm(env.command_manager.get_command(command_name)[:, :2], dim=1) > 0.1 return reward
2,595
Python
43.75862
119
0.717148
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/config/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause """Configurations for velocity-based locomotion environments.""" # We leave this file empty since we don't want to expose any configs in this package directly. # We still need this file to import the "config" module in the parent package.
363
Python
35.399996
94
0.763085
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/config/anymal_d/rough_env_cfg.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from omni.isaac.orbit.utils import configclass from orbit.ext_template.tasks.locomotion.velocity.velocity_env_cfg import ( LocomotionVelocityRoughEnvCfg, ) ## # Pre-defined configs ## from omni.isaac.orbit_assets.anymal import ANYMAL_D_CFG # isort: skip @configclass class AnymalDRoughEnvCfg(LocomotionVelocityRoughEnvCfg): def __post_init__(self): # post init of parent super().__post_init__() # switch robot to anymal-d self.scene.robot = ANYMAL_D_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") @configclass class AnymalDRoughEnvCfg_PLAY(AnymalDRoughEnvCfg): def __post_init__(self): # post init of parent super().__post_init__() # make a smaller scene for play self.scene.num_envs = 50 self.scene.env_spacing = 2.5 # spawn the robot randomly in the grid (instead of their terrain levels) self.scene.terrain.max_init_terrain_level = None # reduce the number of terrains to save memory if self.scene.terrain.terrain_generator is not None: self.scene.terrain.terrain_generator.num_rows = 5 self.scene.terrain.terrain_generator.num_cols = 5 self.scene.terrain.terrain_generator.curriculum = False # disable randomization for play self.observations.policy.enable_corruption = False # remove random pushing self.randomization.base_external_force_torque = None self.randomization.push_robot = None
1,617
Python
32.020408
81
0.683364
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/config/anymal_d/flat_env_cfg.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from omni.isaac.orbit.utils import configclass from .rough_env_cfg import AnymalDRoughEnvCfg @configclass class AnymalDFlatEnvCfg(AnymalDRoughEnvCfg): def __post_init__(self): # post init of parent super().__post_init__() # override rewards self.rewards.flat_orientation_l2.weight = -5.0 self.rewards.dof_torques_l2.weight = -2.5e-5 self.rewards.feet_air_time.weight = 0.5 # change terrain to flat self.scene.terrain.terrain_type = "plane" self.scene.terrain.terrain_generator = None # no height scan self.scene.height_scanner = None self.observations.policy.height_scan = None # no terrain curriculum self.curriculum.terrain_levels = None class AnymalDFlatEnvCfg_PLAY(AnymalDFlatEnvCfg): def __post_init__(self) -> None: # post init of parent super().__post_init__() # make a smaller scene for play self.scene.num_envs = 50 self.scene.env_spacing = 2.5 # disable randomization for play self.observations.policy.enable_corruption = False # remove random pushing self.randomization.base_external_force_torque = None self.randomization.push_robot = None
1,382
Python
30.431817
60
0.656295
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/config/anymal_d/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause import gymnasium as gym from . import agents, flat_env_cfg, rough_env_cfg ## # Register Gym environments. ## gym.register( id="Isaac-Velocity-Flat-Anymal-D-Template-v0", entry_point="omni.isaac.orbit.envs:RLTaskEnv", disable_env_checker=True, kwargs={ "env_cfg_entry_point": flat_env_cfg.AnymalDFlatEnvCfg, "rsl_rl_cfg_entry_point": agents.rsl_rl_cfg.AnymalDFlatPPORunnerCfg, }, ) gym.register( id="Isaac-Velocity-Flat-Anymal-D-Template-Play-v0", entry_point="omni.isaac.orbit.envs:RLTaskEnv", disable_env_checker=True, kwargs={ "env_cfg_entry_point": flat_env_cfg.AnymalDFlatEnvCfg_PLAY, "rsl_rl_cfg_entry_point": agents.rsl_rl_cfg.AnymalDFlatPPORunnerCfg, }, ) gym.register( id="Isaac-Velocity-Rough-Anymal-D-Template-v0", entry_point="omni.isaac.orbit.envs:RLTaskEnv", disable_env_checker=True, kwargs={ "env_cfg_entry_point": rough_env_cfg.AnymalDRoughEnvCfg, "rsl_rl_cfg_entry_point": agents.rsl_rl_cfg.AnymalDRoughPPORunnerCfg, }, ) gym.register( id="Isaac-Velocity-Rough-Anymal-D-Template-Play-v0", entry_point="omni.isaac.orbit.envs:RLTaskEnv", disable_env_checker=True, kwargs={ "env_cfg_entry_point": rough_env_cfg.AnymalDRoughEnvCfg_PLAY, "rsl_rl_cfg_entry_point": agents.rsl_rl_cfg.AnymalDRoughPPORunnerCfg, }, )
1,498
Python
27.283018
77
0.688251
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/config/anymal_d/agents/rsl_rl_cfg.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from omni.isaac.orbit.utils import configclass from omni.isaac.orbit_tasks.utils.wrappers.rsl_rl import ( RslRlOnPolicyRunnerCfg, RslRlPpoActorCriticCfg, RslRlPpoAlgorithmCfg, ) @configclass class AnymalDRoughPPORunnerCfg(RslRlOnPolicyRunnerCfg): num_steps_per_env = 24 max_iterations = 1500 save_interval = 50 experiment_name = "anymal_d_rough" empirical_normalization = False policy = RslRlPpoActorCriticCfg( init_noise_std=1.0, actor_hidden_dims=[512, 256, 128], critic_hidden_dims=[512, 256, 128], activation="elu", ) algorithm = RslRlPpoAlgorithmCfg( value_loss_coef=1.0, use_clipped_value_loss=True, clip_param=0.2, entropy_coef=0.005, num_learning_epochs=5, num_mini_batches=4, learning_rate=1.0e-3, schedule="adaptive", gamma=0.99, lam=0.95, desired_kl=0.01, max_grad_norm=1.0, ) @configclass class AnymalDFlatPPORunnerCfg(AnymalDRoughPPORunnerCfg): def __post_init__(self): super().__post_init__() self.max_iterations = 300 self.experiment_name = "anymal_d_flat" self.policy.actor_hidden_dims = [128, 128, 128] self.policy.critic_hidden_dims = [128, 128, 128]
1,417
Python
26.26923
58
0.645025
isaac-orbit/orbit.ext_template/orbit/ext_template/tasks/locomotion/velocity/config/anymal_d/agents/__init__.py
# Copyright (c) 2022-2024, The ORBIT Project Developers. # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause from . import rsl_rl_cfg # noqa: F401, F403
168
Python
23.142854
56
0.720238
isaac-orbit/orbit.ext_template/docs/CHANGELOG.rst
Changelog --------- 0.1.0 (2024-01-29) ~~~~~~~~~~~~~~~~~~ Added ^^^^^ * Created an initial template for building an extension or project based on Orbit
155
reStructuredText
13.181817
81
0.593548
MomentFactory/Omniverse-NDI-extension/README.md
# mf.ov.ndi An extension to enable NDI® live video input in Omniverse. ## Getting started - Requires Omniverse Kit >= 105 - Requires USD Composer > 2023.1.0 - Requires [NDI® 5.5.3 runtime for Windows](https://go.ndi.tv/tools-for-windows) Previous releases should still be supported in USD composer 2022.x This plugin leverages the `dynamic://` keyword which is currently a beta feature of Omniverse. ## Using the extension ⚠️You should disable Render Settings > Raytracing > Eco Mode for the extension to work properly. ### Enable the extension In USD Composer : - Windows > Extensions. - Switch to THIRD PARY tab. - Install and enable the extension. You may want to use [example.usda](./example.usda) in Create for your first test. ### Extension window If not opened automatically : Windows > NDI®. ![preview](./exts/mf.ov.ndi/data/ui.png) ### Window header - ➕**Create Dynamic Texture**: Creates a new material and shader under /Looks with the associated configuration for dynamic texture rendering. The text field `myDynamicMaterial` allows to customize the identifier for the dynamic texture to register. - 🔄**Discover Dynamic Textures** searches through the USD stage hierarchy for any material with a `dynamic://` asset source (like the one created by “Create Dynamic Material”). Will add a collapsible section for each unique id found - ⏹️**Stop all streams** stops the reception of the video stream for every dynamic texture. A material with a dynamic texture source will still display the last frame it received. ### Dynamic material component Each dynamic texture will be represented in a collapsible component. The title is the name of your dynamic texture. - ☑️ Indicates the health of the video feed. - **NDI® feed combobox** Select which NDI® feed to use for this dynamic texture identifier. This value is saved in USD as a custom property in the shader under `ndi:source` - ⏸️ Allows to start/stop the video feed. - 🖼️ Allows to switch the feed to Low bandwidth mode, saving performance by decreasing resolution for a particular feed. - 🗇 To copy to clipboard the identifiers of the dynamic texture Example `dynamic://myDynamicMaterial` ## Resources - Inspired by : [kit-extension-template](https://github.com/NVIDIA-Omniverse/kit-extension-template) - [kit-cv-video-example](https://github.com/jshrake-nvidia/kit-cv-video-example) - [kit-dynamic-texture-example](https://github.com/jshrake-nvidia/kit-dynamic-texture-example) - [ndi-python](https://github.com/buresu/ndi-python) ## Known issues - Currently implemented with Python, performance could be greatly improved with C++ (but limited by DynamicTextureProvider implementation) - You can ignore warnings in the form of `[Warning] [omni.hydra] Material parameter '...' was assigned to incompatible texture: '...'` - You can ignore warnings in the form of `[Warning] [omni.ext._impl._internal] mf.ov.ndi-... -> <class 'mf.ov.ndi...'>: extension object is still alive, something holds a reference on it...` - You can ignore the first istance of `[Warning] Could not get stage`, because the extension loads before the stage is initialized
3,126
Markdown
51.116666
249
0.760077
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/NDItools.py
from .eventsystem import EventSystem import carb.profiler import logging from .deps import NDIlib as ndi import numpy as np import omni.ui import threading import time from typing import List import warp as wp class NDItools(): def __init__(self): self._ndi_ok = False self._ndi_find = None self._ndi_init() self._ndi_find_init() self._finder = None self._create_finder() self._streams = [] stream = omni.kit.app.get_app().get_update_event_stream() self._sub = stream.create_subscription_to_pop(self._on_update, name="update") def destroy(self): self._sub.unsubscribe() self._sub = None self._finder.destroy() for stream in self._streams: stream.destroy() self._streams.clear() if self._ndi_ok: if self._ndi_find is not None: ndi.find_destroy(self._ndi_find) ndi.destroy() self._ndi_ok = False def is_ndi_ok(self) -> bool: return self._ndi_ok def _on_update(self, e): to_remove = [] for stream in self._streams: if not stream.is_running(): to_remove.append(stream) for stream in to_remove: self._streams.remove(stream) EventSystem.send_event(EventSystem.STREAM_STOP_TIMEOUT_EVENT, payload={"dynamic_id": stream.get_id()}) stream.destroy() def _ndi_init(self): if not ndi.initialize(): logger = logging.getLogger(__name__) logger.error("Could not initialize NDI®") return self._ndi_ok = True def _ndi_find_init(self): self._ndi_find = ndi.find_create_v2() if self._ndi_find is None: logger = logging.getLogger(__name__) logger.error("Could not initialize NDI® find") return def _create_finder(self): if self._ndi_find: self._finder = NDIfinder(self) def get_ndi_find(self): return self._ndi_find def get_stream(self, dynamic_id): return next((x for x in self._streams if x.get_id() == dynamic_id), None) def try_add_stream(self, dynamic_id: str, ndi_source: str, lowbandwidth: bool, update_fps_fn, update_dimensions_fn) -> bool: stream: NDIVideoStream = NDIVideoStream(dynamic_id, ndi_source, lowbandwidth, self, update_fps_fn, update_dimensions_fn) if not stream.is_ok: logger = logging.getLogger(__name__) logger.error(f"Error opening stream: {ndi_source}") return False self._streams.append(stream) return True def try_add_stream_proxy(self, dynamic_id: str, ndi_source: str, fps: float, lowbandwidth: bool) -> bool: stream: NDIVideoStreamProxy = NDIVideoStreamProxy(dynamic_id, ndi_source, fps, lowbandwidth) if not stream.is_ok: logger = logging.getLogger(__name__) logger.error(f"Error opening stream: {ndi_source}") return False self._streams.append(stream) return True def stop_stream(self, dynamic_id: str): stream = self.get_stream(dynamic_id) if stream is not None: self._streams.remove(stream) stream.destroy() def stop_all_streams(self): for stream in self._streams: stream.destroy() self._streams.clear() class NDIfinder(): SLEEP_INTERVAL: float = 2 # seconds def __init__(self, tools: NDItools): self._tools = tools self._previous_sources: List[str] = [] self._is_running = True self._thread = threading.Thread(target=self._search) self._thread.start() def destroy(self): self._is_running = False self._thread.join() self._thread = None def _search(self): find = self._tools.get_ndi_find() if find: while self._is_running: sources = ndi.find_get_current_sources(find) result = [s.ndi_name for s in sources] delta = set(result) ^ set(self._previous_sources) if len(delta) > 0: self._previous_sources = result EventSystem.send_event(EventSystem.NDIFINDER_NEW_SOURCES, payload={"sources": result}) time.sleep(NDIfinder.SLEEP_INTERVAL) self._is_running = False class NDIVideoStream(): NO_FRAME_TIMEOUT = 5 # seconds def __init__(self, dynamic_id: str, ndi_source: str, lowbandwidth: bool, tools: NDItools, update_fps_fn, update_dimensions_fn): wp.init() self._dynamic_id = dynamic_id self._ndi_source = ndi_source self._lowbandwidth = lowbandwidth self._thread: threading.Thread = None self._ndi_recv = None self._update_fps_fn = update_fps_fn self._fps_current = 0.0 self._fps_avg_total = 0.0 self._fps_avg_count = 0 self._fps_expected = 0.0 self._update_dimensions_fn = update_dimensions_fn self.is_ok = False if not tools.is_ndi_ok(): return ndi_find = tools.get_ndi_find() source = None sources = ndi.find_get_current_sources(ndi_find) source_candidates = [s for s in sources if s.ndi_name == self._ndi_source] if len(source_candidates) != 0: source = source_candidates[0] if source is None: logger = logging.getLogger(__name__) logger.error(f"TIMEOUT: Could not find source at \"{self._ndi_source}\".") return if lowbandwidth: recv_create_desc = self.get_recv_low_bandwidth() else: recv_create_desc = self.get_recv_high_bandwidth() self._ndi_recv = ndi.recv_create_v3(recv_create_desc) if self._ndi_recv is None: logger = logging.getLogger(__name__) logger.error("Could not create NDI® receiver") return ndi.recv_connect(self._ndi_recv, source) self._is_running = True self._thread = threading.Thread(target=self._update_texture, args=(self._dynamic_id, )) self._thread.start() self.is_ok = True def _update_fps(self): self._update_fps_fn(self._fps_current, self._fps_avg_total / self._fps_avg_count if self._fps_avg_count != 0 else 0, self._fps_expected) def destroy(self): self._update_fps() self._is_running = False self._thread.join() self._thread = None ndi.recv_destroy(self._ndi_recv) def get_id(self) -> str: return self._dynamic_id def is_running(self) -> bool: return self._is_running def get_recv_high_bandwidth(self): recv_create_desc = ndi.RecvCreateV3() recv_create_desc.color_format = ndi.RECV_COLOR_FORMAT_RGBX_RGBA recv_create_desc.bandwidth = ndi.RECV_BANDWIDTH_HIGHEST return recv_create_desc def get_recv_low_bandwidth(self): recv_create_desc = ndi.RecvCreateV3() recv_create_desc.color_format = ndi.RECV_COLOR_FORMAT_RGBX_RGBA recv_create_desc.bandwidth = ndi.RECV_BANDWIDTH_LOWEST return recv_create_desc @carb.profiler.profile def _update_texture(self, dynamic_id: str): carb.profiler.begin(0, 'Omniverse NDI®::Init') dynamic_texture = omni.ui.DynamicTextureProvider(dynamic_id) last_read = time.time() - 1 # Make sure we run on the first frame fps = 120.0 no_frame_chances = NDIVideoStream.NO_FRAME_TIMEOUT * fps index = 0 self._fps_avg_total = 0.0 self._fps_avg_count = 0 carb.profiler.end(0) while self._is_running: carb.profiler.begin(1, 'Omniverse NDI®::loop outer') now = time.time() time_delta = now - last_read if (time_delta < 1.0 / fps): carb.profiler.end(1) continue carb.profiler.begin(2, 'Omniverse NDI®::loop inner') self._fps_current = 1.0 / time_delta last_read = now carb.profiler.begin(3, 'Omniverse NDI®::receive frame') t, v, _, _ = ndi.recv_capture_v2(self._ndi_recv, 0) carb.profiler.end(3) if t == ndi.FRAME_TYPE_VIDEO: carb.profiler.begin(3, 'Omniverse NDI®::prepare frame') fps = v.frame_rate_N / v.frame_rate_D self._fps_expected = fps if (index == 0): self._fps_current = fps color_format = v.FourCC frame = v.data height, width, channels = frame.shape isGPU = height == width carb.profiler.end(3) if isGPU: carb.profiler.begin(3, 'Omniverse NDI®::begin gpu') with wp.ScopedDevice("cuda"): # CUDA doesnt handle non square texture well, so we need to resize if the te # We are keeping this code in case we find a workaround # # carb.profiler.begin(4, 'Omniverse NDI®::begin cpu resize') # frame = np.resize(frame, (width, width, channels)) # carb.profiler.end(4) # 38 ms carb.profiler.begin(4, 'Omniverse NDI®::gpu uploading') pixels_data = wp.from_numpy(frame, dtype=wp.uint8, device="cuda") carb.profiler.end(4) # 1 ms carb.profiler.begin(4, 'Omniverse NDI®::create gpu texture') self._update_dimensions_fn(width, height, str(color_format)) dynamic_texture.set_bytes_data_from_gpu(pixels_data.ptr, [width, width]) carb.profiler.end(4) carb.profiler.end(3) else: carb.profiler.begin(3, 'Omniverse NDI®::begin cpu') self._update_dimensions_fn(width, height, str(color_format)) dynamic_texture.set_data_array(frame, [width, height, channels]) carb.profiler.end(3) ndi.recv_free_video_v2(self._ndi_recv, v) carb.profiler.end(3) self._fps_avg_total += self._fps_current self._fps_avg_count += 1 self._update_fps() index += 1 if t == ndi.FRAME_TYPE_NONE: no_frame_chances -= 1 if (no_frame_chances <= 0): self._is_running = False else: no_frame_chances = NDIVideoStream.NO_FRAME_TIMEOUT * fps carb.profiler.end(2) carb.profiler.end(1) class NDIVideoStreamProxy(): def __init__(self, dynamic_id: str, ndi_source: str, fps: float, lowbandwidth: bool): self._dynamic_id = dynamic_id self._ndi_source = ndi_source self._fps = fps self._lowbandwidth = lowbandwidth self._thread: threading.Thread = None self.is_ok = False denominator = 1 if lowbandwidth: denominator = 3 w = int(1920 / denominator) # TODO: dimensions from name like for fps h = int(1080 / denominator) self._is_running = True self._thread = threading.Thread(target=self._update_texture, args=(self._dynamic_id, self._fps, w, h, )) self._thread.start() self.is_ok = True def destroy(self): self._is_running = False self._thread.join() self._thread = None def get_id(self) -> str: return self._dynamic_id def is_running(self) -> bool: return self._is_running @carb.profiler.profile def _update_texture(self, dynamic_id: str, fps: float, width: float, height: float): carb.profiler.begin(0, 'Omniverse NDI®::Init') color = np.array([255, 0, 0, 255], np.uint8) channels = len(color) dynamic_texture = omni.ui.DynamicTextureProvider(dynamic_id) frame = np.full((height, width, channels), color, dtype=np.uint8) last_read = time.time() - 1 carb.profiler.end(0) while self._is_running: carb.profiler.begin(1, 'Omniverse NDI®::Proxy loop outer') now = time.time() time_delta = now - last_read if (time_delta < 1.0 / fps): carb.profiler.end(1) continue carb.profiler.begin(2, 'Omniverse NDI®::Proxy loop inner') last_read = now carb.profiler.begin(3, 'Omniverse NDI®::set_data') dynamic_texture.set_data_array(frame, [width, height, channels]) carb.profiler.end(3) carb.profiler.end(2) carb.profiler.end(1)
13,024
Python
33.276316
144
0.552288
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/extension.py
from .window import Window import asyncio import omni.ext import omni.kit.app import omni.kit.ui class MFOVNdiExtension(omni.ext.IExt): MENU_PATH = f"Window/{Window.WINDOW_NAME}" def on_startup(self, _): self._menu = None self._window: Window = None editor_menu = omni.kit.ui.get_editor_menu() if editor_menu: self._menu = editor_menu.add_item( MFOVNdiExtension.MENU_PATH, self._show_window, toggle=True, value=True ) self._show_window(None, True) def on_shutdown(self): if self._menu: self._menu = None if self._window: self._destroy_window() def _destroy_window(self): self._window.destroy() self._window = None def _set_menu(self, visible): editor_menu = omni.kit.ui.get_editor_menu() if editor_menu: editor_menu.set_value(MFOVNdiExtension.MENU_PATH, visible) async def _destroy_window_async(self): await omni.kit.app.get_app().next_update_async() if self._window: self._destroy_window() def _visibility_changed_fn(self, visible): self._set_menu(visible) if not visible: asyncio.ensure_future(self._destroy_window_async()) def _show_window(self, _, value): if value: self._window = Window(width=800, height=275) self._window.set_visibility_changed_fn(self._visibility_changed_fn) elif self._window: self._destroy_window()
1,541
Python
27.036363
86
0.595717
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/model.py
from .bindings import Binding, BindingsModel from .comboboxModel import ComboboxModel from .NDItools import NDItools from .USDtools import DynamicPrim, USDtools import logging import re from typing import List class Model(): def __init__(self): self._bindings_model: BindingsModel = BindingsModel() self._ndi: NDItools = NDItools() def destroy(self): self._ndi.destroy() self._bindings_model.destroy() # region bindings def get_bindings_count(self) -> int: return self._bindings_model.count() def get_binding_data_from_index(self, index: int): return self._bindings_model.get(index) def get_ndi_source_list(self) -> List[str]: return self._bindings_model.get_source_list() def apply_new_binding_source(self, dynamic_id: str, new_source: str): self._bindings_model.bind(dynamic_id, new_source) def apply_lowbandwidth_value(self, dynamic_id: str, value: bool): self._bindings_model.set_low_bandwidth(dynamic_id, value) # endregion # region dynamic def create_dynamic_material(self, name: str): safename = USDtools.make_name_valid(name) if name != safename: logger = logging.getLogger(__name__) logger.warn(f"Name \"{name}\" was not a valid USD identifier, changed it to \"{safename}\"") final_name = safename index = 1 while (self._bindings_model.find_binding_from_id(final_name) is not None): suffix = str(index) if index >= 10 else "0" + str(index) # name, name_01, name_02, ..., name_99, name_100 final_name = safename + "_" + suffix index += 1 USDtools.create_dynamic_material(final_name) self.search_for_dynamic_material() def search_for_dynamic_material(self): result: List[DynamicPrim] = USDtools.find_all_dynamic_sources() self._bindings_model.update_dynamic_prims(result) def _get_prims_with_id(self, dynamic_id: str) -> List[DynamicPrim]: prims: List[DynamicPrim] = self._bindings_model.get_prim_list() return [x for x in prims if x.dynamic_id == dynamic_id] def set_ndi_source_prim_attr(self, dynamic_id: str, source: str): for prim in self._get_prims_with_id(dynamic_id): USDtools.set_prim_ndi_attribute(prim.path, source) def set_lowbandwidth_prim_attr(self, dynamic_id: str, value: bool): for prim in self._get_prims_with_id(dynamic_id): USDtools.set_prim_lowbandwidth_attribute(prim.path, value) # endregion # region stream def try_add_stream(self, binding: Binding, lowbandwidth: bool, update_fps_fn, update_dimensions_fn) -> bool: if self._ndi.get_stream(binding.dynamic_id) is not None: logger = logging.getLogger(__name__) logger.warning(f"There's already a stream running for {binding.dynamic_id}") return False if binding.ndi_source == ComboboxModel.NONE_VALUE: logger = logging.getLogger(__name__) logger.warning("Won't create stream without NDI® source") return False if binding.ndi_source == ComboboxModel.PROXY_VALUE: fps = float(re.search("\((.*)\)", binding.ndi_source).group(1).split("p")[1]) success: bool = self._ndi.try_add_stream_proxy(binding.dynamic_id, binding.ndi_source, fps, lowbandwidth) return success else: success: bool = self._ndi.try_add_stream(binding.dynamic_id, binding.ndi_source, lowbandwidth, update_fps_fn, update_dimensions_fn) return success def stop_stream(self, binding: Binding): self._ndi.stop_stream(binding.dynamic_id) def stop_all_streams(self): self._ndi.stop_all_streams() # endregion
3,820
Python
37.989796
118
0.638482
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/eventsystem.py
import carb.events import omni.kit.app class EventSystem(): BINDINGS_CHANGED_EVENT = carb.events.type_from_string("mf.ov.ndi.BINDINGS_CHANGED_EVENT") COMBOBOX_CHANGED_EVENT = carb.events.type_from_string("mf.ov.ndi.COMBOBOX_CHANGED_EVENT") NDIFINDER_NEW_SOURCES = carb.events.type_from_string("mf.ov.ndi.NDIFINDER_NEW_SOURCES") COMBOBOX_SOURCE_CHANGE_EVENT = carb.events.type_from_string("mf.ov.ndi.COMBOBOX_SOURCE_CHANGE_EVENT") NDI_STATUS_CHANGE_EVENT = carb.events.type_from_string("mf.ov.ndi.NDI_STATUS_CHANGE_EVENT") STREAM_STOP_TIMEOUT_EVENT = carb.events.type_from_string("mf.ov.ndi.STREAM_STOP_TIMEOUT_EVENT") def subscribe(event: int, cb: callable) -> carb.events.ISubscription: bus = omni.kit.app.get_app().get_message_bus_event_stream() return bus.create_subscription_to_push_by_type(event, cb) def send_event(event: int, payload: dict = {}): bus = omni.kit.app.get_app().get_message_bus_event_stream() bus.push(event, payload=payload)
1,015
Python
49.799998
105
0.717241
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/USDtools.py
from .bindings import DynamicPrim import logging import numpy as np import omni.ext from pxr import Usd, UsdGeom, UsdShade, Sdf, UsdLux, Tf from typing import List from unidecode import unidecode class USDtools(): ATTR_NDI_NAME = 'ndi:source' ATTR_BANDWIDTH_NAME = "ndi:lowbandwidth" PREFIX = "dynamic://" SCOPE_NAME = "NDI_Looks" def get_stage() -> Usd.Stage: usd_context = omni.usd.get_context() return usd_context.get_stage() def make_name_valid(name: str) -> str: return Tf.MakeValidIdentifier(unidecode(name)) def create_dynamic_material(safename: str): stage = USDtools.get_stage() if not stage: logger = logging.getLogger(__name__) logger.error("Could not get stage") return scope_path: str = f"{stage.GetDefaultPrim().GetPath()}/{USDtools.SCOPE_NAME}" UsdGeom.Scope.Define(stage, scope_path) USDtools._create_material_and_shader(stage, scope_path, safename) USDtools._fill_dynamic_with_magenta(safename) def _create_material_and_shader(stage: Usd.Stage, scope_path: str, safename: str): material_path = f"{scope_path}/{safename}" material: UsdShade.Material = UsdShade.Material.Define(stage, material_path) shader: UsdShade.Shader = UsdShade.Shader.Define(stage, f"{material_path}/Shader") shader.SetSourceAsset("OmniPBR.mdl", "mdl") shader.SetSourceAssetSubIdentifier("OmniPBR", "mdl") shader.CreateIdAttr("OmniPBR") shader.CreateInput("diffuse_texture", Sdf.ValueTypeNames.Asset).Set(f"{USDtools.PREFIX}{safename}") material.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(), "surface") def _fill_dynamic_with_magenta(safename: str): magenta = np.array([255, 0, 255, 255], np.uint8) frame = np.full((1, 1, 4), magenta, dtype=np.uint8) height, width, channels = frame.shape dynamic_texture = omni.ui.DynamicTextureProvider(safename) dynamic_texture.set_data_array(frame, [width, height, channels]) def find_all_dynamic_sources() -> List[DynamicPrim]: stage = USDtools.get_stage() if not stage: logger = logging.getLogger(__name__) logger.warning("Could not get stage") return [] dynamic_sources: List[str] = [] dynamic_shaders, dynamic_sources = USDtools._find_all_dynamic_shaders(stage, dynamic_sources) dynamic_lights, _ = USDtools._find_all_dynamic_lights(stage, dynamic_sources) return dynamic_shaders + dynamic_lights def _find_all_dynamic_shaders(stage: Usd.Stage, sources: List[str]): shaders: List[UsdShade.Shader] = [UsdShade.Shader(x) for x in stage.Traverse() if x.IsA(UsdShade.Shader)] result: List[DynamicPrim] = [] prefix_length: int = len(USDtools.PREFIX) for shader in shaders: albedo = shader.GetInput("diffuse_texture").Get() # roughness = shader.GetInput("reflectionroughness_texture").Get() # metallic = shader.GetInput("metallic_texture").Get() # orm = shader.GetInput("ORM_texture").Get() # ambient_occlusion = shader.GetInput("ao_texture").Get() emissive = shader.GetInput("emissive_color_texture").Get() # emissive_mask = shader.GetInput("emissive_mask_texture").Get() # opacity = shader.GetInput("opacity_texture").Get() # normal = shader.GetInput("normalmap_texture").Get() # normal_detail = shader.GetInput("detail_normalmap_texture").Get() values_set = set([albedo, emissive]) values_unique = list(values_set) for texture_value in values_unique: if texture_value: path: str = texture_value.path if len(path) > prefix_length: candidate = path[:prefix_length] if candidate == USDtools.PREFIX: name = path[prefix_length:] if name not in sources: sources.append(name) attr_ndi = shader.GetPrim().GetAttribute(USDtools.ATTR_NDI_NAME) attr_ndi = attr_ndi.Get() if attr_ndi.IsValid() else None attr_low = shader.GetPrim().GetAttribute(USDtools.ATTR_BANDWIDTH_NAME) attr_low = attr_low.Get() if attr_low.IsValid() else False p = DynamicPrim(shader.GetPath().pathString, name, attr_ndi, attr_low) result.append(p) return result, sources def _find_all_dynamic_lights(stage: Usd.Stage, sources: List[str]): rect_lights: List[UsdLux.Rectlight] = [UsdLux.RectLight(x) for x in stage.Traverse() if x.IsA(UsdLux.RectLight)] result: List[DynamicPrim] = [] prefix_length: int = len(USDtools.PREFIX) for rect_light in rect_lights: # TODO: Filter those that have "isProjector" (the attribute doesn't exist) attribute = rect_light.GetPrim().GetAttribute("texture:file").Get() if attribute: path: str = attribute.path if len(path) > prefix_length: candidate = path[:prefix_length] if candidate == USDtools.PREFIX: name = path[prefix_length:] if name not in sources: attr_ndi = rect_light.GetPrim().GetAttribute(USDtools.ATTR_NDI_NAME) attr_ndi = attr_ndi.Get() if attr_ndi.IsValid() else None attr_low = rect_light.GetPrim().GetAttribute(USDtools.ATTR_BANDWIDTH_NAME) attr_low = attr_low.Get() if attr_low.IsValid() else False p = DynamicPrim(rect_light.GetPath().pathString, name, attr_ndi, attr_low) result.append(p) return result, sources def set_prim_ndi_attribute(path: str, value: str): stage = USDtools.get_stage() if not stage: logger = logging.getLogger(__name__) logger.error("Could not get stage") return prim: Usd.Prim = stage.GetPrimAtPath(path) if not prim.IsValid(): logger = logging.getLogger(__name__) logger.error(f"Could not set the ndi attribute of prim at {path}") return prim.CreateAttribute(USDtools.ATTR_NDI_NAME, Sdf.ValueTypeNames.String).Set(value) def set_prim_lowbandwidth_attribute(path: str, value: bool): stage = USDtools.get_stage() if not stage: logger = logging.getLogger(__name__) logger.error("Could not get stage") return prim: Usd.Prim = stage.GetPrimAtPath(path) if not prim.IsValid(): logger = logging.getLogger(__name__) logger.error(f"Could not set the bandwidth attribute of prim at {path}") prim.CreateAttribute(USDtools.ATTR_BANDWIDTH_NAME, Sdf.ValueTypeNames.Bool).Set(value) # region stage events def subscribe_to_stage_events(callback): return ( omni.usd.get_context() .get_stage_event_stream() .create_subscription_to_pop(callback, name="mf.ov.ndi.STAGE_EVENT") ) def is_StageEventType_OPENED(type) -> bool: return type == int(omni.usd.StageEventType.OPENED) def is_StageEventType_CLOSE(type) -> bool: return type == int(omni.usd.StageEventType.CLOSING) or type == int(omni.usd.StageEventType.CLOSED) # endregion
7,708
Python
44.081871
120
0.597172
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/comboboxModel.py
from .eventsystem import EventSystem import omni.ui as ui from typing import List class ComboboxItem(ui.AbstractItem): def __init__(self, value: str): super().__init__() self.model = ui.SimpleStringModel(value) def value(self): return self.model.get_value_as_string() class ComboboxModel(ui.AbstractItemModel): NONE_VALUE = "NONE" PROXY_VALUE = "PROXY (1080p30) - RED" def __init__(self, items: List[str], selected: str, name: str, index: int): super().__init__() self._name = name self._index = index # minimal model implementation self._current_index = ui.SimpleIntModel() self._current_index.add_value_changed_fn(lambda a: self._current_index_changed_fn()) self.set_items_and_current(items, selected) def _current_index_changed_fn(self): self._item_changed(None) EventSystem.send_event(EventSystem.COMBOBOX_CHANGED_EVENT, payload={"id": self._name, "index": self._index, "value": self._current_value()}) def set_items_and_current(self, items: List[str], current: str): self._items = [ComboboxItem(text) for text in items] self._set_current_from_value(current) def _set_current_from_value(self, current: str): index = next((i for i, item in enumerate(self._items) if item.value() == current), 0) self._current_index.set_value(index) self._item_changed(None) def _current_value(self) -> str: current_item = self._items[self._current_index.get_value_as_int()] return current_item.value() # minimal model implementation def get_item_children(self, item): return self._items # minimal model implementation def get_item_value_model(self, item, _): if item is None: return self._current_index return item.model
1,893
Python
31.655172
112
0.628632
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/window.py
from .bindings import Binding from .comboboxModel import ComboboxModel from .eventsystem import EventSystem from .model import Model from .USDtools import USDtools import asyncio import carb.events import omni.ui as ui import omni.kit.app import pyperclip from typing import List class Window(ui.Window): WINDOW_NAME = "NDI®" DEFAULT_TEXTURE_NAME = "myDynamicMaterial" NEW_TEXTURE_BTN_TXT = "Create Dynamic Texture" DISCOVER_TEX_BTN_TXT = "Discover Dynamic Textures" STOP_STREAMS_BTN_TXT = "Stop all streams" EMPTY_TEXTURE_LIST_TXT = "No dynamic texture found" def __init__(self, delegate=None, **kwargs): self._model: Model = Model() self._bindingPanels: List[BindingPanel] = [] self._last_material_name = Window.DEFAULT_TEXTURE_NAME super().__init__(Window.WINDOW_NAME, **kwargs) self.frame.set_build_fn(self._build_fn) self._subscribe() self._model.search_for_dynamic_material() def destroy(self): for panel in self._bindingPanels: panel.destroy() self._model.destroy() self._unsubscribe() super().destroy() def _subscribe(self): self._sub: List[carb.events.ISubscription] = [] self._sub.append(EventSystem.subscribe(EventSystem.BINDINGS_CHANGED_EVENT, self._bindings_updated_evt_callback)) self._sub.append(EventSystem.subscribe(EventSystem.COMBOBOX_CHANGED_EVENT, self._combobox_changed_evt_callback)) self._sub.append(EventSystem.subscribe(EventSystem.COMBOBOX_SOURCE_CHANGE_EVENT, self._ndi_sources_changed_evt_callback)) self._sub.append(EventSystem.subscribe(EventSystem.NDI_STATUS_CHANGE_EVENT, self._ndi_status_change_evt_callback)) self._sub.append(EventSystem.subscribe(EventSystem.STREAM_STOP_TIMEOUT_EVENT, self._stream_stop_timeout_evt_callback)) self._sub.append(USDtools.subscribe_to_stage_events(self._stage_event_evt_callback)) def _unsubscribe(self): for sub in self._sub: sub.unsubscribe() sub = None self._sub.clear() def _build_fn(self): with ui.VStack(style={"margin": 3}): self._ui_section_header() self._ui_section_bindings() # region events callback def _bindings_updated_evt_callback(self, e: carb.events.IEvent): self.frame.rebuild() def _combobox_changed_evt_callback(self, e: carb.events.IEvent): value: str = e.payload["value"] dynamic_id = e.payload["id"] panel_index = e.payload["index"] self._model.apply_new_binding_source(dynamic_id, value) self._model.set_ndi_source_prim_attr(dynamic_id, value) if (len(self._bindingPanels) > panel_index): self._bindingPanels[panel_index].combobox_item_changed() def _ndi_sources_changed_evt_callback(self, e: carb.events.IEvent): for panel in self._bindingPanels: panel.combobox_items_changed(e.payload["sources"]) def _ndi_status_change_evt_callback(self, e: carb.events.IEvent): for panel in self._bindingPanels: panel.check_for_ndi_status() def _stream_stop_timeout_evt_callback(self, e: carb.events.IEvent): panel: BindingPanel = next(x for x in self._bindingPanels if x.get_dynamic_id() == e.payload["dynamic_id"]) panel.on_stop_stream() def _stage_event_evt_callback(self, e: carb.events.IEvent): if USDtools.is_StageEventType_OPENED(e.type): self._model.search_for_dynamic_material() self._model.stop_all_streams() if USDtools.is_StageEventType_CLOSE(e.type): self._model.stop_all_streams() # endregion # region UI def _ui_section_header(self): button_style = {"Button": {"stack_direction": ui.Direction.LEFT_TO_RIGHT}} with ui.HStack(height=0): self._dynamic_name = ui.StringField() self._dynamic_name.model.set_value(self._last_material_name) ui.Button(Window.NEW_TEXTURE_BTN_TXT, image_url="resources/glyphs/menu_plus.svg", image_width=24, style=button_style, clicked_fn=self._on_click_create_dynamic_material) with ui.HStack(height=0): ui.Button(Window.DISCOVER_TEX_BTN_TXT, image_url="resources/glyphs/menu_refresh.svg", image_width=24, style=button_style, clicked_fn=self._on_click_refresh_materials) ui.Button(Window.STOP_STREAMS_BTN_TXT, clicked_fn=self._on_click_stop_all_streams) def _ui_section_bindings(self): self._bindingPanels = [] with ui.ScrollingFrame(): with ui.VStack(): count: int = self._model.get_bindings_count() if count == 0: ui.Label(Window.EMPTY_TEXTURE_LIST_TXT) else: for i in range(count): self._bindingPanels.append(BindingPanel(i, self, height=0)) # endregion # region controls def _on_click_create_dynamic_material(self): self._stop_all_streams() name: str = self._dynamic_name.model.get_value_as_string() self._last_material_name = name self._model.create_dynamic_material(name) def _on_click_refresh_materials(self): self._stop_all_streams() self._model.search_for_dynamic_material() def _on_click_stop_all_streams(self): self._stop_all_streams() def _stop_all_streams(self): self._model.stop_all_streams() for panel in self._bindingPanels: panel.on_stop_stream() # endregion # region BindingPanel Callable def get_binding_data_from_index(self, index: int): return self._model.get_binding_data_from_index(index) def get_choices_for_combobox(self) -> List[str]: return self._model.get_ndi_source_list() def apply_lowbandwidth_value(self, dynamic_id: str, value: bool): self._model.apply_lowbandwidth_value(dynamic_id, value) self._model.set_lowbandwidth_prim_attr(dynamic_id, value) def try_add_stream(self, binding: Binding, lowbandwidth: bool, update_fps_fn, update_dimensions_fn) -> bool: return self._model.try_add_stream(binding, lowbandwidth, update_fps_fn, update_dimensions_fn) def stop_stream(self, binding: Binding): return self._model.stop_stream(binding) # endregion class BindingPanel(ui.CollapsableFrame): NDI_COLOR_STOPPED = "#E6E7E8" NDI_COLOR_PLAYING = "#78B159" NDI_COLOR_WARNING = "#F4900C" NDI_COLOR_INACTIVE = "#DD2E45" NDI_STATUS = "resources/glyphs/circle.svg" PLAY_ICON = "resources/glyphs/timeline_play.svg" PAUSE_ICON = "resources/glyphs/toolbar_pause.svg" COPY_ICON = "resources/glyphs/copy.svg" LOW_BANDWIDTH_ICON = "resources/glyphs/AOV_dark.svg" PLAYPAUSE_BTN_NAME = "play_pause_btn" BANDWIDTH_BTN_NAME = "low_bandwidth_btn" COPYPATH_BTN_NAME = "copy_path_btn" RUNNING_LABEL_SUFFIX = " - running" def __init__(self, index: int, window: Window, **kwargs): self._index = index self._window = window binding, _, ndi = self._get_data() choices = self._get_choices() self._dynamic_id = binding.dynamic_id self._lowbandwidth_value = binding.lowbandwidth self._is_playing = False super().__init__(binding.dynamic_id, **kwargs) self._info_window = None with self: with ui.HStack(): self._status_icon = ui.Image(BindingPanel.NDI_STATUS, width=20, mouse_released_fn=self._show_info_window) self._set_ndi_status_icon(ndi.active) self._combobox_alt = ui.Label("") self._set_combobox_alt_text(binding.ndi_source) self._combobox_alt.visible = False self._combobox = ComboboxModel(choices, binding.ndi_source, binding.dynamic_id, self._index) self._combobox_ui = ui.ComboBox(self._combobox) self.play_pause_toolbutton = ui.Button(text="", image_url=BindingPanel.PLAY_ICON, height=30, width=30, clicked_fn=self._on_click_play_pause_ndi, name=BindingPanel.PLAYPAUSE_BTN_NAME) self._lowbandwidth_toolbutton = ui.ToolButton(image_url=BindingPanel.LOW_BANDWIDTH_ICON, width=30, height=30, tooltip="Low bandwidth mode", clicked_fn=self._set_low_bandwidth_value, name=BindingPanel.BANDWIDTH_BTN_NAME) self._lowbandwidth_toolbutton.model.set_value(self._lowbandwidth_value) ui.Button("", image_url=BindingPanel.COPY_ICON, width=30, height=30, clicked_fn=self._on_click_copy, tooltip="Copy dynamic texture path(dynamic://*)", name=BindingPanel.COPYPATH_BTN_NAME) def destroy(self): self._info_window_destroy() # region Info Window def _show_info_window(self, _x, _y, button, _modifier): if (button == 0): # left click binding, _, _ = self._get_data() if not self._info_window: self._info_window = StreamInfoWindow(f"{self._dynamic_id} info", binding.ndi_source, width=280, height=200) self._info_window.set_visibility_changed_fn(self._info_window_visibility_changed) elif self._info_window: self._info_window_destroy() def _info_window_visibility_changed(self, visible): if not visible: asyncio.ensure_future(self._info_window_destroy_async()) def _info_window_destroy(self): if self._info_window: self._info_window.destroy() self._info_window = None async def _info_window_destroy_async(self): await omni.kit.app.get_app().next_update_async() if self._info_window: self._info_window_destroy() def update_fps(self, fps_current: float, fps_average: float, fps_expected: float): if self._info_window: self._info_window.set_fps_values(fps_current, fps_average, fps_expected) def update_details(self, width: int, height: int, color_format: str): if self._info_window: self._info_window.set_stream_details(width, height, color_format) # endregion def combobox_items_changed(self, items: List[str]): binding, _, _ = self._get_data() self._combobox.set_items_and_current(items, binding.ndi_source) def check_for_ndi_status(self): _, _, ndi = self._get_data() self._set_ndi_status_icon(ndi.active) def combobox_item_changed(self): binding, _, ndi = self._get_data() self._set_combobox_alt_text(binding.ndi_source) self._set_ndi_status_icon(ndi.active) if self._info_window: self._info_window.set_stream_name(binding.ndi_source) def get_dynamic_id(self) -> str: return self._dynamic_id def _get_data(self): return self._window.get_binding_data_from_index(self._index) def _get_choices(self): return self._window.get_choices_for_combobox() def _on_click_copy(self): pyperclip.copy(f"{USDtools.PREFIX}{self._dynamic_id}") def _set_low_bandwidth_value(self): self._lowbandwidth_value = not self._lowbandwidth_value self._window.apply_lowbandwidth_value(self._dynamic_id, self._lowbandwidth_value) def _on_play_stream(self): self._is_playing = True self.play_pause_toolbutton.image_url = BindingPanel.PAUSE_ICON self._lowbandwidth_toolbutton.enabled = False self._combobox_ui.visible = False self._combobox_alt.visible = True self.check_for_ndi_status() def on_stop_stream(self): self._is_playing = False self.play_pause_toolbutton.image_url = BindingPanel.PLAY_ICON self._lowbandwidth_toolbutton.enabled = True self._combobox_ui.visible = True self._combobox_alt.visible = False self.check_for_ndi_status() def _on_click_play_pause_ndi(self): binding, _, _ = self._get_data() if self._is_playing: self._window.stop_stream(binding) self.on_stop_stream() else: if self._window.try_add_stream(binding, self._lowbandwidth_value, self.update_fps, self.update_details): self._on_play_stream() def _set_combobox_alt_text(self, text: str): self._combobox_alt.text = f"{text}{BindingPanel.RUNNING_LABEL_SUFFIX}" def _set_ndi_status_icon(self, active: bool): if active and self._is_playing: self._status_icon.style = {"color": ui.color(BindingPanel.NDI_COLOR_PLAYING)} elif active and not self._is_playing: self._status_icon.style = {"color": ui.color(BindingPanel.NDI_COLOR_STOPPED)} elif not active and self._is_playing: self._status_icon.style = {"color": ui.color(BindingPanel.NDI_COLOR_WARNING)} else: # not active and not self._is_playing self._status_icon.style = {"color": ui.color(BindingPanel.NDI_COLOR_INACTIVE)} class StreamInfoWindow(ui.Window): def __init__(self, dynamic_id: str, ndi_id: str, delegate=None, **kwargs): super().__init__(dynamic_id, **kwargs) self.frame.set_build_fn(self._build_fn) self._stream_name = ndi_id def destroy(self): super().destroy() def _build_fn(self): with ui.VStack(height=0): with ui.HStack(): ui.Label("Stream name:") self._stream_name_model = ui.StringField(enabled=False).model self._stream_name_model.set_value(self._stream_name) with ui.HStack(): ui.Label("Current fps:") self._fps_current_model = ui.FloatField(enabled=False).model self._fps_current_model.set_value(0.0) with ui.HStack(): ui.Label("Average fps:") self._fps_average_model = ui.FloatField(enabled=False).model self._fps_average_model.set_value(0.0) with ui.HStack(): ui.Label("Expected fps:") self._fps_expected_model = ui.FloatField(enabled=False).model self._fps_expected_model.set_value(0.0) with ui.HStack(): ui.Label("Width:") self._dimensions_width_model = ui.IntField(enabled=False).model self._dimensions_width_model.set_value(0) with ui.HStack(): ui.Label("Height:") self._dimensions_height_model = ui.IntField(enabled=False).model self._dimensions_height_model.set_value(0) with ui.HStack(): ui.Label("Color format:") self._color_format_model = ui.StringField(enabled=False).model self._color_format_model.set_value("") def set_fps_values(self, fps_current: float, fps_average: float, fps_expected: float): # If this property exists, all the other do as well since its the last one to be initialized if hasattr(self, "_fps_expected_model"): self._fps_current_model.set_value(fps_current) self._fps_average_model.set_value(fps_average) self._fps_expected_model.set_value(fps_expected) def set_stream_name(self, name: str): # No need to check if attribute exists because no possibility of concurrency between build fn and caller self._stream_name_model.set_value(name) # Reset other values self._fps_current_model.set_value(0.0) self._fps_average_model.set_value(0.0) self._fps_expected_model.set_value(0.0) self._dimensions_width_model.set_value(0) self._dimensions_height_model.set_value(0) self._color_format_model.set_value("") def set_stream_details(self, width: int, height: int, color_format: str): if hasattr(self, "_color_format_model"): self._dimensions_width_model.set_value(width) self._dimensions_height_model.set_value(height) # Original format is similar to FourCCVideoType.FOURCC_VIDEO_TYPE_RGBA, we want to display only "RGBA" color_format_simple = color_format.split("_")[-1] self._color_format_model.set_value(color_format_simple)
16,724
Python
41.128463
120
0.61032
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/bindings.py
from .comboboxModel import ComboboxModel from .eventsystem import EventSystem import carb.events from dataclasses import dataclass from typing import List @dataclass class DynamicPrim: path: str dynamic_id: str ndi_source_attr: str lowbandwidth_attr: bool @dataclass class Binding(): dynamic_id: str ndi_source: str lowbandwidth: bool @dataclass class NDIData(): source: str active: bool class BindingsModel(): NONE_DATA = NDIData(ComboboxModel.NONE_VALUE, False) def __init__(self): self._bindings: List[Binding] = [] self._dynamic_prims: List[DynamicPrim] = [] self._ndi_sources: List[NDIData] = [] self._ndi_sources.append(BindingsModel.NONE_DATA) self._sub = EventSystem.subscribe(EventSystem.NDIFINDER_NEW_SOURCES, self._ndi_sources_change_evt_callback) def destroy(self): self._sub.unsubscribe() self._sub = None self._dynamic_prims = [] self._bindings = [] self._ndi_sources = [] def count(self): return len(self._bindings) def get(self, index: int) -> Binding: binding: Binding = self._bindings[index] prim: DynamicPrim = self.find_binding_from_id(binding.dynamic_id) ndi: NDIData = self._find_ndi_from_source(binding.ndi_source) return binding, prim, ndi def get_source_list(self) -> List[str]: return [x.source for x in self._ndi_sources] def _get_non_static_source_list(self) -> List[NDIData]: return self._ndi_sources[1:] # Excludes NONE_DATA def get_prim_list(self) -> List[str]: return [x for x in self._dynamic_prims] def bind(self, dynamic_id, new_source): binding: Binding = self.find_binding_from_id(dynamic_id) binding.ndi_source = new_source def set_low_bandwidth(self, dynamic_id: str, value: bool): binding: Binding = self.find_binding_from_id(dynamic_id) binding.lowbandwidth = value def find_binding_from_id(self, dynamic_id: str) -> Binding: return next((x for x in self._bindings if x.dynamic_id == dynamic_id), None) def _find_binding_from_ndi(self, ndi_source: str) -> Binding: return next((x for x in self._bindings if x.source == ndi_source), None) def _find_ndi_from_source(self, ndi_source: str) -> NDIData: if ndi_source is None: return self._ndi_sources[0] return next((x for x in self._ndi_sources if x.source == ndi_source), None) def update_dynamic_prims(self, prims: List[DynamicPrim]): self._dynamic_prims = prims self._update_ndi_from_prims() self._update_bindings_from_prims() EventSystem.send_event(EventSystem.BINDINGS_CHANGED_EVENT) def _update_ndi_from_prims(self): for dynamic_prim in self._dynamic_prims: ndi: NDIData = self._find_ndi_from_source(dynamic_prim.ndi_source_attr) if ndi is None: self._ndi_sources.append(NDIData(dynamic_prim.ndi_source_attr, False)) def _update_bindings_from_prims(self): self._bindings.clear() for dynamic_prim in self._dynamic_prims: source_attr = dynamic_prim.ndi_source_attr source: str = source_attr if source_attr is not None else BindingsModel.NONE_DATA.source self._bindings.append(Binding(dynamic_prim.dynamic_id, source, dynamic_prim.lowbandwidth_attr)) def _ndi_sources_change_evt_callback(self, e: carb.events.IEvent): sources = e.payload["sources"] self._update_ndi_new_and_active_sources(sources) self._update_ndi_inactive_sources(sources) EventSystem.send_event(EventSystem.COMBOBOX_SOURCE_CHANGE_EVENT, payload={"sources": [x.source for x in self._ndi_sources]}) EventSystem.send_event(EventSystem.NDI_STATUS_CHANGE_EVENT) def _update_ndi_new_and_active_sources(self, sources: List[str]): for source in sources: data: NDIData = self._find_ndi_from_source(source) if data is None: data = NDIData(source, True) self._ndi_sources.append(data) else: data.active = True def _update_ndi_inactive_sources(self, sources: List[str]): for ndi in self._get_non_static_source_list(): is_active = next((x for x in sources if x == ndi.source), None) if is_active is None: ndi.active = False
4,477
Python
33.984375
115
0.635694
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/deps/NDIlib/__init__.py
import os import sys if os.name == 'nt' and sys.version_info.major >= 3 and sys.version_info.minor >= 8: os.add_dll_directory(os.path.dirname(__file__)) from .NDIlib import *
181
Python
21.749997
83
0.679558
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/tests/__init__.py
from .test_USDtools import * from .test_ui import *
52
Python
16.666661
28
0.730769
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/tests/test_ui.py
import omni.kit.test from ..window import Window, BindingPanel from ..comboboxModel import ComboboxModel from .test_utils import (make_stage, close_stage, get_window, DYNAMIC_ID1, DYNAMIC_ID2, create_dynamic_material, create_dynamic_rectlight, refresh_dynamic_list, get_dynamic_material_prim, add_proxy_source) class UITestsHeader(omni.kit.test.AsyncTestCase): def setUp(self): self._stage = make_stage() self._window = get_window() def tearDown(self): close_stage() async def test_create_material_button(self): field = self._window.find("**/StringField[*]") field.widget.model.set_value(DYNAMIC_ID1) self.assertEqual(field.widget.model.get_value_as_string(), DYNAMIC_ID1) button = self._window.find(f"**/Button[*].text=='{Window.NEW_TEXTURE_BTN_TXT}'") await button.click() prim = get_dynamic_material_prim(DYNAMIC_ID1) self.assertTrue(prim.IsValid) async def test_texture_discovery(self): create_dynamic_material() create_dynamic_rectlight() await refresh_dynamic_list(self._window) panels = self._window.find_all("**/BindingPanel[*]") self.assertEqual(len(panels), 2) panel1_found = False panel2_found = False for panel in panels: labels = panel.find_all("**/Label[*]") for label in labels: if label.widget.text == DYNAMIC_ID1: panel1_found = True elif label.widget.text == DYNAMIC_ID2: panel2_found = True self.assertTrue(panel1_found) self.assertTrue(panel2_found) class UITestsPanel(omni.kit.test.AsyncTestCase): def setUp(self): self._stage = make_stage() self._window = get_window() def tearDown(self): close_stage() async def test_no_panel_on_start(self): await refresh_dynamic_list(self._window) panel = self._window.find("**/BindingPanel[*]") self.assertIsNone(panel) label = self._window.find("**/Label[*]") self.assertEqual(label.widget.text, Window.EMPTY_TEXTURE_LIST_TXT) async def test_combobox_defaults(self): await refresh_dynamic_list(self._window) add_proxy_source(self._window.widget) button = self._window.find(f"**/Button[*].text=='{Window.NEW_TEXTURE_BTN_TXT}'") await button.click() combobox = self._window.find("**/ComboBox[*]") model = combobox.widget.model self.assertEqual(model._current_value(), ComboboxModel.NONE_VALUE) model._current_index.set_value(1) self.assertNotEquals(model._current_value(), ComboboxModel.NONE_VALUE) model._current_index.set_value(0) self.assertEqual(model._current_value(), ComboboxModel.NONE_VALUE) async def test_low_bandwidth_btn(self): await refresh_dynamic_list(self._window) button = self._window.find(f"**/Button[*].text=='{Window.NEW_TEXTURE_BTN_TXT}'") await button.click() panel = self._window.find("**/BindingPanel[*]") binding, _, _ = panel.widget._get_data() self.assertFalse(binding.lowbandwidth) button = panel.find(f"**/ToolButton[*].name=='{BindingPanel.BANDWIDTH_BTN_NAME}'") await button.click() binding, _, _ = panel.widget._get_data() self.assertTrue(binding.lowbandwidth) await button.click() binding, _, _ = panel.widget._get_data() self.assertFalse(binding.lowbandwidth) async def test_low_bandwidth_stream(self): await refresh_dynamic_list(self._window) add_proxy_source(self._window.widget) button = self._window.find(f"**/Button[*].text=='{Window.NEW_TEXTURE_BTN_TXT}'") await button.click() combobox = self._window.find("**/ComboBox[*]") combobox.widget.model._set_current_from_value(ComboboxModel.PROXY_VALUE) panel = self._window.find("**/BindingPanel[*]") button_bandwidth = panel.find(f"**/ToolButton[*].name=='{BindingPanel.BANDWIDTH_BTN_NAME}'") button_playpause = button = panel.find(f"**/Button[*].name=='{BindingPanel.PLAYPAUSE_BTN_NAME}'") self.assertTrue(panel.widget._lowbandwidth_toolbutton.enabled) await button_playpause.click() self.assertFalse(self._window.widget._model._ndi._streams[0]._lowbandwidth) self.assertFalse(panel.widget._lowbandwidth_toolbutton.enabled) await button_playpause.click() self.assertTrue(panel.widget._lowbandwidth_toolbutton.enabled) await button_bandwidth.click() await button_playpause.click() self.assertTrue(self._window.widget._model._ndi._streams[0]._lowbandwidth) await button_playpause.click() async def test_proxy_play_pause(self): await refresh_dynamic_list(self._window) add_proxy_source(self._window.widget) button_create = self._window.find(f"**/Button[*].text=='{Window.NEW_TEXTURE_BTN_TXT}'") await button_create.click() combobox = self._window.find("**/ComboBox[*]") combobox.widget.model._set_current_from_value(ComboboxModel.PROXY_VALUE) panel = self._window.find("**/BindingPanel[*]") button_playpause = panel.find(f"**/Button[*].name=='{BindingPanel.PLAYPAUSE_BTN_NAME}'") self.assertTrue(panel.widget._combobox_ui.visible) self.assertFalse(panel.widget._combobox_alt.visible) await button_playpause.click() self.assertGreater(len(self._window.widget._model._ndi._streams), 0) self.assertFalse(panel.widget._combobox_ui.visible) self.assertTrue(panel.widget._combobox_alt.visible) await button_playpause.click() self.assertEquals(len(self._window.widget._model._ndi._streams), 0) async def test_proxy_multiple(self): await refresh_dynamic_list(self._window) field = self._window.find("**/StringField[*]") button_create = self._window.find(f"**/Button[*].text=='{Window.NEW_TEXTURE_BTN_TXT}'") field.widget.model.set_value(DYNAMIC_ID1) await button_create.click() field.widget.model.set_value(DYNAMIC_ID2) await button_create.click() comboboxes = self._window.find_all("**/ComboBox[*]") for combobox in comboboxes: combobox.widget.model._set_current_from_value(ComboboxModel.PROXY_VALUE) buttons_playpause = self._window.find_all(f"**/Button[*].name=='{BindingPanel.PLAYPAUSE_BTN_NAME}'") for button_playpause in buttons_playpause: await button_playpause.click() self.assertEquals(len(self._window.widget._model._ndi._streams), 2) button_stopall = self._window.find(f"**/Button[*].text=='{Window.STOP_STREAMS_BTN_TXT}'") await button_stopall.click() self.assertEquals(len(self._window.widget._model._ndi._streams), 0) panels = self._window.find_all("**/BindingPanel[*]") for panel in panels: self.assertTrue(panel.widget._combobox_ui.visible) self.assertFalse(panel.widget._combobox_alt.visible)
7,140
Python
38.672222
117
0.640196
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/tests/test_utils.py
import omni import omni.kit.ui_test as ui_test from pxr import Usd, UsdLux, UsdShade from ..USDtools import USDtools from ..window import Window from ..eventsystem import EventSystem from ..comboboxModel import ComboboxModel SOURCE1 = "MY-PC (Test Pattern)" SOURCE2 = "MY-PC (Test Pattern 2)" DYNAMIC_ID1 = "myDynamicMaterial1" DYNAMIC_ID2 = "myDynamicMaterial2" DUMMY_PATH = "/path/to/dummy" RECTLIGHT_NAME = "MyRectLight" DEFAULT_PRIM_NAME = "World" def make_stage() -> Usd.Stage: usd_context = omni.usd.get_context() usd_context.new_stage() # self._stage = Usd.Stage.CreateInMemory() stage = usd_context.get_stage() prim = stage.DefinePrim(f"/{DEFAULT_PRIM_NAME}") stage.SetDefaultPrim(prim) return stage def get_stage() -> Usd.Stage: usd_context = omni.usd.get_context() stage = usd_context.get_stage() return stage def close_stage(): usd_context = omni.usd.get_context() assert usd_context.can_close_stage() usd_context.close_stage() def get_window(): return ui_test.find(Window.WINDOW_NAME) def create_dynamic_material() -> UsdShade.Material: USDtools.create_dynamic_material(DYNAMIC_ID1) return get_dynamic_material_prim(DYNAMIC_ID1) def create_dynamic_rectlight(): stage = get_stage() path: str = f"{stage.GetDefaultPrim().GetPath()}/{RECTLIGHT_NAME}" light = UsdLux.RectLight.Define(stage, path) light.GetPrim().GetAttribute("texture:file").Set(f"{USDtools.PREFIX}{DYNAMIC_ID2}") def get_dynamic_material_prim(name: str): usd_context = omni.usd.get_context() stage = usd_context.get_stage() return stage.GetPrimAtPath(f"{stage.GetDefaultPrim().GetPath()}/{USDtools.SCOPE_NAME}/{name}") async def refresh_dynamic_list(window): button = window.find(f"**/Button[*].text=='{Window.DISCOVER_TEX_BTN_TXT}'") await button.click() def add_proxy_source(window): EventSystem.send_event(EventSystem.NDIFINDER_NEW_SOURCES, payload={"sources": [ComboboxModel.PROXY_VALUE]})
1,995
Python
27.112676
111
0.707268
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/mf/ov/ndi/tests/test_USDtools.py
from ..USDtools import USDtools from .test_utils import make_stage, close_stage, create_dynamic_material, create_dynamic_rectlight, SOURCE1 import omni.kit.test class USDValidNameUnitTest(omni.kit.test.AsyncTestCase): async def test_name_valid(self): self.check_name_valid("myDynamicMaterial", "myDynamicMaterial") self.check_name_valid("789testing123numbers456", "_89testing123numbers456") self.check_name_valid("", "_") self.check_name_valid("àâáäãåÀÂÁÃÅÄ", "aaaaaaAAAAAA") self.check_name_valid("èêéëÈÊÉË", "eeeeEEEE") self.check_name_valid("ìîíïÌÎÍÏ", "iiiiIIII") self.check_name_valid("òôóöõøÒÔÓÕÖØ", "ooooooOOOOOO") self.check_name_valid("ùûúüÙÛÚÜ", "uuuuUUUU") self.check_name_valid("æœÆŒçǰðÐñÑýÝþÞÿß", "aeoeAEOEcCdegdDnNyYthThyss") self.check_name_valid("!¡¿@#$%?&*()-_=+/`^~.,'\\<>`;:¤{}[]|\"¦¨«»¬¯±´·¸÷", "___________________________________________________") self.check_name_valid("¢£¥§©ªº®¹²³µ¶¼½¾×", "C_PSY_SS_c_ao_r_123uP_1_4_1_2_3_4x") def check_name_valid(self, source, expected): v: str = USDtools.make_name_valid(source) self.assertEqual(v, expected, f"Expected \"{v}\", derived from \"{source}\", to equals \"{expected}\"") class USDToolsUnitTest(omni.kit.test.AsyncTestCase): def setUp(self): self._stage = make_stage() def tearDown(self): close_stage() async def test_create_dynamic_material(self): material = create_dynamic_material() prim = self._stage.GetPrimAtPath(material.GetPath()) self.assertIsNotNone(prim) async def test_find_dynamic_sources(self): create_dynamic_material() create_dynamic_rectlight() sources = USDtools.find_all_dynamic_sources() self.assertEqual(len(sources), 2) async def test_set_property_ndi(self): material = create_dynamic_material() path = material.GetPath() USDtools.set_prim_ndi_attribute(path, SOURCE1) attr = material.GetPrim().GetAttribute(USDtools.ATTR_NDI_NAME) self.assertEqual(attr.Get(), SOURCE1) async def test_set_property_bandwidth(self): material = create_dynamic_material() path = material.GetPath() USDtools.set_prim_lowbandwidth_attribute(path, True) attr = material.GetPrim().GetAttribute(USDtools.ATTR_BANDWIDTH_NAME) self.assertTrue(attr.Get()) USDtools.set_prim_lowbandwidth_attribute(path, False) self.assertFalse(attr.Get())
2,554
Python
38.921874
111
0.634299
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/config/extension.toml
[package] version = "1.0.1" title = "MF NDI® extension" description = "An extension to enable NDI® live video input in Omniverse." authors = ["Moment Factory","Frederic Lestage"] readme = "docs/README.md" changelog = "docs/CHANGELOG.md" repository = "https://github.com/MomentFactory/Omniverse-NDI-extension" category = "Services" keywords = ["NDI®", "texture", "live-feed", "video", "broadcast", "audiovisual", "realtime","streaming","voip"] preview_image = "data/preview.png" icon = "data/mf-ov-extensions-icons.png" [dependencies] "omni.kit.uiapp" = {} "omni.warp" = {} [[python.module]] name = "mf.ov.ndi" [python.pipapi] requirements = [ "unidecode" ] use_online_index = true [[test]] args = [ "--/app/window/dpiScaleOverride=1.0", "--/app/window/scaleToMonitor=false" ] dependencies = [ "omni.kit.ui_test", "omni.usd" ] timeout = 60 [package.target] kit = ["105.1"] [package.writeTarget] kit = true
936
TOML
18.93617
111
0.67094
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/docs/CHANGELOG.md
# Changelog ## [1.0.1] - 2023-12-21 ### Fixed - Stream properly shut down when closing, opening, or reopening stage ## [1.0.0] - 2023-07-18 ### Added - Compatibility with USD Composer 2023.1.1 ### Changed - Creating a texture with the same name doesn't block (will follow pattern: "name", "name_01", "name_02", ...) - Bundle pip dependency `ndi-python` with the extension - Search now look for dynamic texture in the emissive texture field ## [0.12.0] - 2023-05-18 ### Added - Display stream statistics when running (fps, dimensions, color format) - Opens as a new window when left-clicking on the status dot of a particular stream ### Changed - Improved performances when using GPU for texture copy when stream source is square ### Fixed - Streams stop when refreshing or adding a new dynamic texture to prevent ghost streams - Removed the possibility of overwriting a stream when creating a new one with the same name - Removed the double color conversion by requesting RGBA color profile from NDI® ## Removed - Proxy stream no longer available in the list of streams ## [0.11.0] - 2023-04-20 ### Changed - NDI® status now displayed as a dot with colors - red: NDI® source offline - white: NDI® source online - green: Stream playing - orange: NDI® drops - Code refactor ## [0.10.0] - 2023-04-12 ### Added - Unit and UI tests ## [0.9.0] - 2023-04-04 ### Changed - UI rework: less text, more icons - Documentation and icons Overhaul - Material are now created in a scope under the default prim instead of an Xform - Updated example.usd to reflect this change - Material identifier now keep the letter if there's an accent (i.e. é becomes e) ## [0.8.1] - 2023-03-29 ### Changed - Dedicated NDI® threads no longer daemonic ### Fixed - Stream UI did not go back to its non running state when using the button "kill all streams" - Order of calls on application shutdown that could cause a crash on hot reload (affected developers) - Status of NDI® source not properly reflected in the icons ## [0.8.0] - 2023-03-27 ### Added - Profiling in NDI® stream functions ### Changed - When a stream is running, it is no longer possible to change its source, display a running status instead ### Fixed - Selected NDI® source in combobox doesn't change when wources are updated - Make name USD safe when creating new material instead of throwing error - NDI® status icon goes back to valid if a NDI® source is started after being closed - Won't attempt to start a stream if it isn't valid (i.e. can't find the source) ## [0.7.0] - 2023-03-21 ### Fixed - Removed the parts of the extension that caused the app to freeze. Might still encounter low fps during the following: - Starting a stream - Closing a NDI® source while the stream is still running in the extension - Using Remote Connection 1 or proxy as a stream source ## [0.6.0] - 2023-03-16 ### Changed - Stream Optimization (no need to flatten the NDI® frame) - Individual streams now run in different thread - Removed refresh NDI® feed button in favor of a watcher that runs on a second thread - If a NDI® source closes while the stream is still running in the extension, it will automatically stop after a few seconds (5) ### Fixed - Extension is now know as mf.ov.ndi - Omniverse app won't crash when the NDI® source is closed and a stream is still running - The app will still freeze for a few seconds ## [0.5.0] - 2023-03-07 ### Added - Support for receiving the low bandwidth version of a NDI® stream (this is a feature of NDI® that we now support) ## [0.4.0] - 2023-03-03 ### Added - Support for dynamic rect light (works when `IsProjector` is enabled to simulate a projector) ### Changed - Now uses the [recommended logging](https://docs.omniverse.nvidia.com/kit/docs/kit-manual/latest/guide/logging.html) system ### Removed - Obsolete pip dependency to open-cv ## [0.3.1] - 2023-03-02 ### Fixed - Crash when searching for dynamic textures and finding those that aren't dynamic ## [0.3.0] - 2023-03-01 ### Added - Can use a proxy feed which simulates a solid red color 1920x1080 at 30fps ## Fixed - Filling dynamic texture with a default magenta color - Fixes frame drop when assigning a dynamic texture without pushing data to it first - Fixes for developpers to the window management targeting hot reload ### Changed - Menu element is now at "Window > NDI® Dynamic Texture" instead of "Window > NDI® > NDI® Dynamic Texture" ## [0.2.0] - 2023-02-28 ### Added - Support for managing multiple NDI® feeds ## [0.1.0] - 2023-02-22 ### Added - Initial version of extension - Supports one NDI® feed
4,632
Markdown
30.09396
128
0.722582
MomentFactory/Omniverse-NDI-extension/exts/mf.ov.ndi/docs/README.md
# NDI® extension for Omniverse [mf.ov.ndi] Copyright 2023 Moment Factory Studios Inc. An extension to enable NDI® live video input in Omniverse. - Requires Omniverse Kit >= 105 - Requires USD Composer > 2023.1.0 - Requires [NDI® 5.5.3 runtime for Windows](https://go.ndi.tv/tools-for-windows)
295
Markdown
31.888885
80
0.745763
MomentFactory/Omniverse-NDI-extension/PACKAGE-LICENSES/NDI-LICENSE.md
NewTek’s NDI® Software Development Kit (SDK) License Agreement Please read this document carefully before proceeding. You (the undersigned Licensee) hereby agree to the terms of this NDI® Software Development Kit (SDK) License Agreement (the "License") in order to use the SDK. NewTek, Inc. (“NewTek”) agrees to license you certain rights as set forth herein under these terms. 1. Definitions a. "SDK" means the entire NewTek NDI® Software Development Kit, including those portions pertaining to the Specific SDK, provided to you pursuant to this License, including any source code, compiled executables or libraries, and all documentation provided to you to assist you in building tools that use the NDI® Software for data transfer over a local network. b. "Products" means your software product(s) and/or service(s) that you develop or that are developed on your behalf through the use of the SDK and that are designed to be, and/or are, used, sold and/or distributed to work closely with other NewTek Products or Third Party Video Products. c. “NewTek Products refers to NewTek’s video line of products distributed by NewTek and any upgrades. d. “SDK Documentation” refers to the documentation included with the Software Development Kit including that portion pertaining to the Specific SDK. e. “Specific SDK” refers to the specific SDK for which you intend to use the NewTek SDK and this license (for example: NDI® Send, NDI® Receive, NDI® Find, or other SDK’s that are available from time to time. These are examples only and NewTek may add or subtract to this list at its discretion, and you agree to use them only in accordance with this Agreement), and includes the documentation relating to it. f. “Third Party Video Products” refers to products of third parties developed by or for them also using the NewTek NDI® Software Development Kit in any way. 2. License a. Pursuant to the terms, conditions and requirements of this License and the SDK Documentation, you are hereby granted a nonexclusive royalty-free license to use the sample code, object code and documentation included in the SDK for the sole purpose of developing Products using the Specific SDK, and to distribute, only in accordance with the SDK Documentation requirements, object code included in the SDK solely as used by such Products (your Product and compiled sample code referred to as the “Bundled Product”). b. If you are making a product release you must use a version of the SDK that is less than thirty (30) days old if there is one. c. This is a License only, and no employment, joint venture, partnership, or other business venture is created by this License. d. Unless otherwise stated in the SDK, no files within the SDK and the Specific SDK may be distributed. Certain files within the SDK or the Specific SDK may be distributed, said files and their respective distribution license are individually identified within the SDK documentation. This is not a license to create revisions or other derivative works of any NewTek software or technology. e. You agree to comply with the steps outlined in the SDK Documentation, including the SDK manual for the Specific SDK. Different obligations and restrictions may be imposed by NewTek with respect to different Specific SDK’s. NewTek will not agree to sponsor your Product or show affiliation; however NewTek shall have the right to test the Product, and if it does not work or operate to NewTek’s satisfaction, NewTek may terminate this license pursuant to Section 10. Notwithstanding that NewTek may test the Product, it does not warrant the test; it is for NewTek’s benefit, and you agree not to promote in your Product marketing or elsewhere any results or that NewTek has tested the Product. f. You acknowledge that information provided to NewTek to induce NewTek to enter into this license with you about your experience in the industry, sales, distribution, SDK experience or otherwise, whether such information is provided to NewTek verbally or in writing, is true. g. NewTek makes the SDK available for developers for developing Products only, under these specific conditions herein, and if any, or all, of the terms of this license are not enforceable within your legal jurisdiction in any way, or if any clause is voided or modified in any way, then you may not enter into this agreement, any license and permission granted herein is revoked and withdrawn as of the date you first downloaded and/or used the SDK, and you are then unauthorized to copy, create derivative works, or otherwise use the SDK in any way. 3. Restrictions and Confidentiality. a. “Confidential Information” includes the SDK and all specifications, source code, example code, tools and documentation provided within the SDK, and any support thereof, and any other proprietary information provided by NewTek and identified as Confidential in the course of assisting You with your NDI® implementation. Confidential Information does not include information that: 1) is or becomes generally available to the public other than as a result of a disclosure by You, or 2) becomes available to You on a non-confidential basis from a source that was not prohibited from disclosing such information. Except as authorized herein, or in the SDK Documentation, or as otherwise approved in writing by NewTek: 1) The disclosure to you of the SDK and all other Confidential Information shall not be disclosed to any third party 2)You agree not to commercialize the Confidential Information for yours or others benefit in any way; 3) You will not make or distribute copies of the SDK, or other Confidential Information or electronically transfer the SDK to any individual within your business or company who does not need to know or view the SDK, and under no circumstances shall you disclose it, or any part of it, to any company, or any other individual not employed directly by the business or company you represent, without express written permission of NewTek. b. You will not modify, sell, rent, transfer, resell for profit, distribute, or create derivative works based upon the SDK or any part thereof other than as set forth herein, and you will not allow independent contractors to create derivative works; however, you may use the SDK to create your own program for the primary purpose of making it or your Product compatible with the NDI® network APIs, a NewTek Product, or for other purposes expressly set forth by you in advance in writing and agreed to in writing by NewTek. In the case of your derivative works based upon the SDK, you may create and revise your Product using the SDK, and sell, rent, transfer, resell for profit and distribute, so long as it is for the Principal objective for which you were provided the SDK and it otherwise complies with this agreement, including the requirement that your Product or any other Third Party Product using any portion of the SDK continues to use the current SDK as required herein and functions properly using the SDK. NewTek reserves the right to determine at any time the compliance of your Product or any Third Party Product as properly using the SDK including maintaining current and complete NDI® compatability. Notwithstanding anything to the contrary herein, no intellectual property claim, whether in patent, trademark, copyright, or otherwise, is made by NewTek in or to your Product (except as to the SDK including software code and/or Libraries, and copyright rights therein, and any Confidential Information used in or with the Product). c. You will comply with applicable export control and trade sanctions laws, rules, regulations and licenses and will not export or re-export, directly or indirectly, the SDK into any country, to any organization or individual prohibited by the United States Export Administration Act and the regulations thereunder. d. Any direct or indirect distribution of your Product or any Bundled Products by you that include your Product, shall be under the terms of a license agreement containing terms that: (i) prohibit any modifications to the SDK or any part thereof, (ii) prohibit any reverse engineering, disassembly or recompilation of the the SDK or any part thereof, or any protocols used in the SDK, and further prohibit any attempt to do so; (iii) disclaim any and all warranties on behalf of NewTek and each of its licensors, (iv) disclaim, to the extent permitted by applicable law, liability of NewTek and/or its licensors for any damages, whether direct, indirect, incidental or consequential, arising from the use of the Product or Bundled Products, (v) comply fully with all relevant export laws and regulations of the United States to assure that the Bundled Products or any part thereof is not exported, directly or indirectly, in violation of United States law; (vi) include the appropriate copyright notice showing NewTek, Inc. as copyright owner; (vii) require all third party developers using your Product to develop Third Party Products to comply with the terms of the NewTek SDK license, including that such Third Party Products have current and complete NDI® compatability, and further require such third party developers to include in their End User License Agreement the terms of this paragraph 3d. e. You agree not to use the SDK for any unlawful propose or in any way to cause injury, harm or damage to NewTek, Inc., or its Products, trademarks, reputation and/or goodwill, or use information provided pursuant to the SDK, to interfere with NewTek in the commercialization of NewTek Products. f. You agree to use NewTek trademarks (NewTek trademarks include, but are not limited to NDI®, NDI|HX™, NewTek™, TriCaster®, and LightWave 3D®), only in accordance with applicable policies of NewTek for such trademark usage by software developers in effect from time to time, which policy may be amended at any time with or without notice. NewTek’s trademarks shall not be utilized within the Product itself, or on the Product packaging or promotion, or on websites, except to identify that the Product is compatible with NewTek’s pertinent Video Product, and in all cases where NewTek trademarks are utilized, special and clear notations shall be provided that the marks are NewTek trademarks. Your Product is not a product of NewTek and no promotion, packaging, or use of NewTek trademarks shall suggest sponsorship by NewTek of your Products, except where specifically authorized by NewTek in writing. Any distribution of your Product in a fraudulent manner, or in any other manner or method that violates any civil or criminal laws shall constitute a default under this agreement and result in immediate revocation of any right to utilize NewTek’s marks. g. NewTek owns or has licensed copyright rights to the SDK. To the extent any of the SDK is incorporated into your Product, you agree to include all applicable copyright notices, along with yours, indicating NewTek’s copyright rights as applicable and as requested by NewTek. h. You agree that by using the SDK, or any portion or part of the NDI® Software, in your Products, that you shall not at any time during the term create, use or distribute Products utilizing the NDI® SDK that are not interoperable with, or have significantly degraded performance of functionality when working with, NewTek Products or Third Party Video Products that are created with or utilize in whole or in part the SDK. Your Products and Third Party Products must maintain current and complete NDI® compatability at all times. i. You agree to not to reverse engineer, disassemble or recompile the SDK or any part thereof, or any protocols used in the SDK, or attempt to do so. j. You agree not to use the SDK, or cause the SDK to be used, for any purpose that it was not designed for, and in particular, you agree not to use the SDK for any purpose but for the precise purposes as expressly identified to NewTek in writing that is the basis of the SDK and this license, and you agree you will not attempt to violate any of the foregoing, or encourage third parties to do so. 4. Software Defect Reporting If you find software defects in the SDK, you agree to make reasonable effort to report them to NewTek in accordance with the SDK documentation or in such other manner as NewTek directs in writing. NewTek will evaluate and, at its sole discretion, may address them in a future revision of the SDK. NewTek does not warrant the SDK to be free of defects. 5. Updates You understand and agree that NewTek may amend, modify, change, and/or cease distribution or production of the SDK at any time. You understand that you are not entitled to receive any upgrades, updates, or future versions of the SDK under this License. NewTek does not warrant or represent that its future updates and revisions will be compatible with your Product, and NewTek does not warrant that its updates and/or revisions will allow your Product to be compatible with or without modifications to your Product. 6. Ownership Nothing herein is intended to convey to you any patent, trademark, copyright, trade secret or other Intellectual Property owned by NewTek or its Licensors in the SDK or in any NewTek software, hardware, products, trade names, or trademarks. NewTek and its suppliers or licensors shall retain all right, title, and interest to the foregoing Intellectual Property and to the SDK. All rights not expressly granted herein are reserved by NewTek. 7. Indemnity and Limitations You agree to indemnify and hold NewTek harmless from any third party claim, loss, or damage (including attorney's fees) related to your use, sale or distribution of the SDK. THE SDK IS PROVIDED TO YOU FREE OF CHARGE, AND ON AN "AS IS" BASIS AND "WITH ALL FAULTS", WITHOUT ANY TECHNICAL SUPPORT OR WARRANTY OF ANY KIND FROM NEWTEK. YOU ASSUME ALL RISKS THAT THE SDK IS SUITABLE OR ACCURATE FOR YOUR NEEDS AND YOUR USE OF THE SDK IS AT YOUR OWN DISCRETION AND RISK. NEWTEK AND ITS LICENSORS DISCLAIM ALL EXPRESS AND IMPLIED WARRANTIES FOR THE SDK INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. ALSO, THERE IS NO WARRANTY OF NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. SOME STATES DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT APPLY TO YOU. YOU MAY ALSO HAVE OTHER LEGAL RIGHTS THAT VARY FROM STATE TO STATE. 8. Limitation of Damages NEITHER NEWTEK NOR ITS SUPPLIERS OR LICENSORS SHALL BE LIABLE FOR ANY INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOSS (INCLUDING DAMAGES FOR LOSS OF BUSINESS, LOSS OF PROFITS, OR THE LIKE), ARISING OUT OF THIS LICENSE WHETHER BASED ON BREACH OF CONTRACT, TORT (INCLUDING NEGLIGENCE),STRICT LIABILITY, PRODUCT LIABILITY OR OTHERWISE, EVEN IF NEWTEK OR ITS REPRESENTATIVES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE LIMITATION OR EXCLUSION OF LIABILITY FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION OR EXCLUSION MAY NOT APPLY TO YOU. The limited warranty, exclusive remedies and limited liability set forth above are fundamental elements of the basis of the bargain between NewTek and you. You agree that NewTek would not be able to provide the Software on an economic basis without such limitations. IN NO EVENT WILL NEWTEK BE LIABLE FOR ANY AMOUNT GREATER THAN WHAT YOU ACTUALLY PAID FOR THE SDK. 9. US Government - Restricted Rights The SDK and accompanying materials are provided with Restricted Rights. Use, duplication, or disclosure by the U.S. Government is subject to restrictions as set forth in this License and as provided in Federal Regulations, as applicable. (Manufacturer: NewTek, Inc., 5131 Beckwith Blvd., San Antonio, TX 78249). 10. Termination Either party may terminate this License upon thirty (30) days written notice. Either party may also terminate if the other party materially defaults in the performance of any provision of this License, the non-defaulting party gives written notice to the other party of such default, and the defaulting party fails to cure such default within ten (10) days after receipt of such notice. Upon the termination of this License, the rights and licenses granted to you by NewTek pursuant to this License will automatically cease. Nothing herein shall prevent either party from pursuing any injunctive relief at any time if necessary, or seeking any other remedies available in equity. Each party reserves the right to pursue all legal and equitable remedies available. Upon termination, all SDK materials shall be promptly returned to NewTek, and any and all copies stored in electronic or other format shall be deleted and destroyed, and any rights to use NewTek’s trademarks are revoked. If this License is terminated for any reason, the provisions of Sections 1, 3, 6, 7, 8, 9, 10, and 11 shall survive such termination. 11. General Notices given hereunder may be sent to either party at the address below by either overnight mail or by email and are deemed effective when sent. This License shall be governed by the laws of the State of Texas, without regard to its choice of law rules and you agree to exclusive jurisdiction therein. This License contains the complete agreement between you and NewTek with respect to the subject matter (SDK) of this License, and supersedes all prior or contemporaneous agreements or understandings, whether oral or written. It does not replace any licenses accompanying NewTek Products. You may not assign this SDK License.
17,449
Markdown
95.944444
229
0.808184
MomentFactory/Omniverse-MPCDI-converter/bootstrap.py
# Copyright 2023 NVIDIA CORPORATION # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import contextlib import io import packmanapi import os import sys REPO_ROOT = os.path.dirname(os.path.realpath(__file__)) REPO_DEPS_FILE = os.path.join(REPO_ROOT, "deps", "repo-deps.packman.xml") if __name__ == "__main__": # pull all repo dependencies first # and add them to the python path with contextlib.redirect_stdout(io.StringIO()): deps = packmanapi.pull(REPO_DEPS_FILE) for dep_path in deps.values(): if dep_path not in sys.path: sys.path.append(dep_path) sys.path.append(REPO_ROOT) import omni.repo.usd omni.repo.usd.bootstrap(REPO_ROOT)
1,191
Python
31.216215
74
0.717044
MomentFactory/Omniverse-MPCDI-converter/repo.toml
# common settings for repo_usd for all USD plug-ins [repo_usd] usd_root = "${root}/_build/usd-deps/nv-usd/%{config}" # usd_root = "${root}/../../USD_INSTALLATIONS/USD_22-11" usd_python_root = "${root}/_build/usd-deps/python" generate_plugin_buildfiles = true plugin_buildfile_format = "cmake" generate_root_buildfile = true [repo_usd.plugin.mpcdiFileFormat] plugin_dir = "${root}/src/usd-plugins/fileFormat/mpcdiFileFormat" install_root = "${root}/_install/%{platform}/%{config}/mpcdiFileFormat" include_dir = "include/mpcdiFileFormat" additional_include_dirs = [ "../../../../_build/usd-deps/nv_usd/%{config}/include/tbb" ] public_headers = [ "api.h", "iMpcdiDataProvider.h", "mpcdiDataProviderFactory.h" ] private_headers = [ "mpcdiData.cpp", "mpcdiPluginManager.h", "mpcdiFileFormat.h", "tinyxml2.h" ] cpp_files = [ "mpcdiData.cpp", "mpcdiDataProviderFactory.cpp", "iMpcdiDataProvider.cpp", "mpcdiPluginManager.cpp", "mpcdiFileFormat.cpp", "tinyxml2.cpp" ] resource_files = [ "plugInfo.json" ] usd_lib_dependencies = [ "arch", "tf", "plug", "vt", "gf", "sdf", "js", "pcp", "usdGeom", "usd", "usdLux" ]
1,211
TOML
21.867924
71
0.639967
MomentFactory/Omniverse-MPCDI-converter/README.md
# mf.ov.mpcdi_converter An Omniverse extension for MPDCI files. Support MPCDI* to OpenUSD conversion as well as References to MPDCI files through a native USD FileFormat plugin. MPCDI* is a VESA interchange format for videoprojectors technical data. *Multiple Projection Common Data Interchange MPCDIv2 is under Copyright © 2013 – 2015 Video Electronics Standards Association. All rights reserved. ## Requirements - Requires Omniverse Kit >= 105.1 - Tested in USD Composer 2023.2.2 and 2023.2.0 ## Build The extension comes pre-built for Omniverse users but here are the steps if you want to build it by yourself. ### Build DLL for Omniverse Just run `build.bat`. ### Test in Omniverse 1. `Window` > `Extensions` 2. ☰ > Settings 3. ✚ Add `_install\windows-x86_64\release` folder to the Extension Search Paths 4. The user extension should appear on the left 5. `Autoload` needs to be checked for the FileFormat plugin to be correctly loaded at USD Runtime. ### Build DLL for USDview The dependency configuration is contained in the [usd-deps.packman.xml](deps/usd-deps.packman.xml) file To switch to the correct OpenUSD version for USDview compilation, it is required to edit the packman configuration file to: ``` <project toolsVersion="5.6"> <dependency name="nv-usd" linkPath="../_build/usd-deps/nv-usd/${config}"> <package name="usd.py310.${platform}.usdview.${config}" version="0.23.05-tc.47+v23.05.b53573ea" /> </dependency> <dependency name="python" linkPath="../_build/usd-deps/python"> <package name="python" version="3.10.13+nv1-${platform}" /> </dependency> </project> ``` Then build as usual with `./build.bat` To run USDview : - `source setenvwindows` - `usdview resource/scene.usda` ### Other OpenUSD compatible platforms Waiting for an improved build process, we documented how you can build for other platforms (Unreal, Blender) in [this repo](https://github.com/MomentFactory/Omniverse-MVR-GDTF-converter). ## Using the extension Enable the Extension ( `Window` > `Extensions` from USD Composer ). [A sample MPCDI file](./exts/mf.ov.mpcdi_converter/mf/ov/mpcdi_converter/sample/Cube-mapping.mpcdi.xml) is provided. ### Reference an MPCDI file To reference an MPCDI file, just drag and drop the file on your viewport or your Stage Window. ### Convert an MPCDI file Three ways to convert from USD Composer : 1. `File` > `Import`. Or from the Content window : 2. `+Import` button. 3. Right click > `Convert to USD` on an `.mpcdi.xml` file. ## Implementation note - Since they are no projectors in Omniverse, a projector will be represented as: - A camera with the frustum of the projector - A child `RectLight` with the correct frustum that represents the light emitted - A simple mesh to represent the physical projector box - Each buffer is represented as a scope in the scene tree with each projector as a child. - MPCDI \<Extensions\> are currently ignored - The frustum of each projector is currently calculated with a focus distance of 2 unit and a focal length of 10. ## Resources - Inspired by : [NVIDIA' usd-plugin-sample](https://github.com/NVIDIA-Omniverse/usd-plugin-samples) - [MPCDI Christie Digital Github](https://github.com/ChristieDigital/mpcdi/blob/master/MPCDI_explained.md) - MPCDIv2 standard can be downloaded from [the VESA website](https://vesa.org/vesa-standards/) - MPCDIv2 is under Copyright © 2013 – 2015 Video Electronics Standards Association. All rights reserved. ## Known issues - While USD Cameras support Lens shift through the `offset`, the `RectLight` used to simulate the projector light does not offer such feature yet. - Does not support yet the full MPCDI zip archive, only `.mpcdi.xml` - XML extension usage : Fileformat plugin doesn't support having multiple extenions such as .mpcdi.xml (while Omniverse allows it). Currently this extension uses the .xml extension, which is not very convenient.
3,903
Markdown
40.094736
211
0.755829
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/api.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_MPCDI_API_H_ #define OMNI_MPCDI_API_H_ #include "pxr/base/arch/export.h" #if defined(PXR_STATIC) # define MPCDI_API # define MPCDI_API_TEMPLATE_CLASS(...) # define MPCDI_API_TEMPLATE_STRUCT(...) # define MPCDI_LOCAL #else # if defined(MPCDIFILEFORMAT_EXPORTS) # define MPCDI_API ARCH_EXPORT # define MPCDI_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__) # define MPCDI_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__) # else # define MPCDI_API ARCH_IMPORT # define MPCDI_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__) # define MPCDI_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__) # endif # define MPCDI_LOCAL ARCH_HIDDEN #endif #endif
1,368
C
35.026315
87
0.707602
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/iMpcdiDataProvider.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_MPCDI_IMPCDIDATAPROVIDER_H_ #define OMNI_MPCDI_IMPCDIDATAPROVIDER_H_ #include <unordered_map> #include <functional> #include <memory> #include <pxr/pxr.h> #include <pxr/base/tf/token.h> #include <pxr/base/vt/value.h> #include <pxr/usd/sdf/fileFormat.h> #include <pxr/usd/sdf/specType.h> #include <pxr/usd/sdf/primSpec.h> #include "api.h" PXR_NAMESPACE_OPEN_SCOPE /// /// \struct EdfDataParameters /// /// Represents a class used to hold the specific metadata /// parameter values used to construct the dynamic layer. /// struct EdfDataParameters { public: std::string dataProviderId; std::unordered_map<std::string, std::string> providerArgs; // conversion functions to and from USD structures static EdfDataParameters FromFileFormatArgs(const SdfFileFormat::FileFormatArguments& args); }; /// /// \class IEdfSourceData /// /// Interface for data providers to create prim / attribute information /// and to read back attribute values as needed. /// class IEdfSourceData { public: MPCDI_API virtual ~IEdfSourceData(); /// Creates a new prim from data read from a back-end data source. /// \param parentPath The prim path that will be the parent of the newly created prim. /// \param name The name of the new prim. This must be a valid USD identifier. /// \param specifier The spec type of the new prim (e.g., def, over, etc.). /// \param typeName The name of the type of the prim. /// MPCDI_API virtual void CreatePrim(const SdfPath& parentPath, const std::string& name, const SdfSpecifier& specifier, const TfToken& typeName) = 0; /// Creates a new attribute on the specified prim. /// \param parentPrimPath The prim path of the prim that will contain the attribute. /// \param name The name of the attribute. /// \param typeName The name of the type of the attribute. /// \param variability The variability of the attribute (e.g., uniformm, varying, etc.). /// \param value The default value of the new attribute. /// MPCDI_API virtual void CreateAttribute(const SdfPath& parentPrimPath, const std::string& name, const SdfValueTypeName& typeName, const SdfVariability& variability, const VtValue& value) = 0; /// Sets the value of a field on a prim at the given path. /// If the value exists, the current value will be overwritten. /// \param primPath The full path of the prim to set the field value for. /// \param fieldName The name of the field to set. /// \param value The value to set. /// MPCDI_API virtual void SetField(const SdfPath& primPath, const TfToken& fieldName, const VtValue& value) = 0; /// Determines if the field fieldName exists on the given prim path. /// If the field exists, the current value will be returned in value if value is valid. /// \param primPath The full path of the prim to look for the field. /// \param fieldName The name of the field to look for on the prim. /// \param value A pointer to a VtValue object that will be filled with the value of /// the field if it exists. /// MPCDI_API virtual bool HasField(const SdfPath& primPath, const TfToken& fieldName, VtValue* value) = 0; /// Determines if the attribute at the given path exists and if so, returns the default value. /// \param attributePath The full path of the attribute (i.e., primPath + "." + attributeName). /// \param defaultValue A pointer to a VtValue object that will be filled with the default value /// of the attribute if it exists. /// MPCDI_API virtual bool HasAttribute(const SdfPath& attributePath, VtValue* defaultValue) = 0; }; /// /// \class IEdfDataProvider /// /// Interface for acquring data from an external data system based on a set of /// metadata parameters fed to a dynamic payload. This object is responsible for /// acquiring the data from the external system and turning it into USD representations /// that can be added to a layer. /// class IEdfDataProvider { public: MPCDI_API virtual ~IEdfDataProvider(); // disallow copies IEdfDataProvider(const IEdfDataProvider&) = delete; IEdfDataProvider& operator=(const IEdfDataProvider&) = delete; /// Asks the data provider to read whatever information they would like to read /// from the back-end system when a payload layer is first opened. /// /// \param sourceData The source data interface which the data provider /// can use to create prims / attributes as needed when /// they read data from their back-end. /// MPCDI_API virtual bool Read(std::shared_ptr<IEdfSourceData> sourceData) = 0; /// Asks the data provider to read whatever would be considered the /// children of the provided prim path. This gives the opportunity /// for the data provider to defer reading hierarhical children /// from their back-end store all at once when the data is large. /// /// \param primPath The path of the prim to create children for. /// This value is either "/Data", indicating the root /// of the hierarchy, or the full path to a prim /// that was created by the data provider previously /// on a Read / ReadChildren call. /// /// \param sourceData The source data interface which the data provider /// can use to create prims / attributes as needed when /// they read data from their back-end. /// MPCDI_API virtual bool ReadChildren(const std::string& primPath, std::shared_ptr<IEdfSourceData> sourceData) = 0; /// Asks the data provider whether all of its data was read on the initial /// Read call (i.e. the data has been cached in the source) or not. /// /// \returns True if all data was read on initial Read, false otherwise. MPCDI_API virtual bool IsDataCached() const = 0; protected: MPCDI_API IEdfDataProvider(const EdfDataParameters& parameters); MPCDI_API const EdfDataParameters& GetParameters() const; private: EdfDataParameters _parameters; }; PXR_NAMESPACE_CLOSE_SCOPE #endif
6,567
C
38.329341
129
0.716004
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/tinyxml2.h
/* Original code by Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef TINYXML2_INCLUDED #define TINYXML2_INCLUDED #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) # include <ctype.h> # include <limits.h> # include <stdio.h> # include <stdlib.h> # include <string.h> # if defined(__PS3__) # include <stddef.h> # endif #else # include <cctype> # include <climits> # include <cstdio> # include <cstdlib> # include <cstring> #endif #include <stdint.h> /* TODO: intern strings instead of allocation. */ /* gcc: g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe Formatting, Artistic Style: AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h */ #if defined( _DEBUG ) || defined (__DEBUG__) # ifndef TINYXML2_DEBUG # define TINYXML2_DEBUG # endif #endif #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4251) #endif #ifdef _WIN32 # ifdef TINYXML2_EXPORT # define TINYXML2_LIB __declspec(dllexport) # elif defined(TINYXML2_IMPORT) # define TINYXML2_LIB __declspec(dllimport) # else # define TINYXML2_LIB # endif #elif __GNUC__ >= 4 # define TINYXML2_LIB __attribute__((visibility("default"))) #else # define TINYXML2_LIB #endif #if !defined(TIXMLASSERT) #if defined(TINYXML2_DEBUG) # if defined(_MSC_VER) # // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like # define TIXMLASSERT( x ) do { if ( !((void)0,(x))) { __debugbreak(); } } while(false) # elif defined (ANDROID_NDK) # include <android/log.h> # define TIXMLASSERT( x ) do { if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } } while(false) # else # include <assert.h> # define TIXMLASSERT assert # endif #else # define TIXMLASSERT( x ) do {} while(false) #endif #endif /* Versioning, past 1.0.14: http://semver.org/ */ static const int TIXML2_MAJOR_VERSION = 9; static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_PATCH_VERSION = 0; #define TINYXML2_MAJOR_VERSION 9 #define TINYXML2_MINOR_VERSION 0 #define TINYXML2_PATCH_VERSION 0 // A fixed element depth limit is problematic. There needs to be a // limit to avoid a stack overflow. However, that limit varies per // system, and the capacity of the stack. On the other hand, it's a trivial // attack that can result from ill, malicious, or even correctly formed XML, // so there needs to be a limit in place. static const int TINYXML2_MAX_ELEMENT_DEPTH = 500; namespace tinyxml2 { class XMLDocument; class XMLElement; class XMLAttribute; class XMLComment; class XMLText; class XMLDeclaration; class XMLUnknown; class XMLPrinter; /* A class that wraps strings. Normally stores the start and end pointers into the XML file itself, and will apply normalization and entity translation if actually read. Can also store (and memory manage) a traditional char[] Isn't clear why TINYXML2_LIB is needed; but seems to fix #719 */ class TINYXML2_LIB StrPair { public: enum Mode { NEEDS_ENTITY_PROCESSING = 0x01, NEEDS_NEWLINE_NORMALIZATION = 0x02, NEEDS_WHITESPACE_COLLAPSING = 0x04, TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, ATTRIBUTE_NAME = 0, ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, COMMENT = NEEDS_NEWLINE_NORMALIZATION }; StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} ~StrPair(); void Set( char* start, char* end, int flags ) { TIXMLASSERT( start ); TIXMLASSERT( end ); Reset(); _start = start; _end = end; _flags = flags | NEEDS_FLUSH; } const char* GetStr(); bool Empty() const { return _start == _end; } void SetInternedStr( const char* str ) { Reset(); _start = const_cast<char*>(str); } void SetStr( const char* str, int flags=0 ); char* ParseText( char* in, const char* endTag, int strFlags, int* curLineNumPtr ); char* ParseName( char* in ); void TransferTo( StrPair* other ); void Reset(); private: void CollapseWhitespace(); enum { NEEDS_FLUSH = 0x100, NEEDS_DELETE = 0x200 }; int _flags; char* _start; char* _end; StrPair( const StrPair& other ); // not supported void operator=( const StrPair& other ); // not supported, use TransferTo() }; /* A dynamic array of Plain Old Data. Doesn't support constructors, etc. Has a small initial memory pool, so that low or no usage will not cause a call to new/delete */ template <class T, int INITIAL_SIZE> class DynArray { public: DynArray() : _mem( _pool ), _allocated( INITIAL_SIZE ), _size( 0 ) { } ~DynArray() { if ( _mem != _pool ) { delete [] _mem; } } void Clear() { _size = 0; } void Push( T t ) { TIXMLASSERT( _size < INT_MAX ); EnsureCapacity( _size+1 ); _mem[_size] = t; ++_size; } T* PushArr( int count ) { TIXMLASSERT( count >= 0 ); TIXMLASSERT( _size <= INT_MAX - count ); EnsureCapacity( _size+count ); T* ret = &_mem[_size]; _size += count; return ret; } T Pop() { TIXMLASSERT( _size > 0 ); --_size; return _mem[_size]; } void PopArr( int count ) { TIXMLASSERT( _size >= count ); _size -= count; } bool Empty() const { return _size == 0; } T& operator[](int i) { TIXMLASSERT( i>= 0 && i < _size ); return _mem[i]; } const T& operator[](int i) const { TIXMLASSERT( i>= 0 && i < _size ); return _mem[i]; } const T& PeekTop() const { TIXMLASSERT( _size > 0 ); return _mem[ _size - 1]; } int Size() const { TIXMLASSERT( _size >= 0 ); return _size; } int Capacity() const { TIXMLASSERT( _allocated >= INITIAL_SIZE ); return _allocated; } void SwapRemove(int i) { TIXMLASSERT(i >= 0 && i < _size); TIXMLASSERT(_size > 0); _mem[i] = _mem[_size - 1]; --_size; } const T* Mem() const { TIXMLASSERT( _mem ); return _mem; } T* Mem() { TIXMLASSERT( _mem ); return _mem; } private: DynArray( const DynArray& ); // not supported void operator=( const DynArray& ); // not supported void EnsureCapacity( int cap ) { TIXMLASSERT( cap > 0 ); if ( cap > _allocated ) { TIXMLASSERT( cap <= INT_MAX / 2 ); const int newAllocated = cap * 2; T* newMem = new T[newAllocated]; TIXMLASSERT( newAllocated >= _size ); memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs if ( _mem != _pool ) { delete [] _mem; } _mem = newMem; _allocated = newAllocated; } } T* _mem; T _pool[INITIAL_SIZE]; int _allocated; // objects allocated int _size; // number objects in use }; /* Parent virtual class of a pool for fast allocation and deallocation of objects. */ class MemPool { public: MemPool() {} virtual ~MemPool() {} virtual int ItemSize() const = 0; virtual void* Alloc() = 0; virtual void Free( void* ) = 0; virtual void SetTracked() = 0; }; /* Template child class to create pools of the correct type. */ template< int ITEM_SIZE > class MemPoolT : public MemPool { public: MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} ~MemPoolT() { MemPoolT< ITEM_SIZE >::Clear(); } void Clear() { // Delete the blocks. while( !_blockPtrs.Empty()) { Block* lastBlock = _blockPtrs.Pop(); delete lastBlock; } _root = 0; _currentAllocs = 0; _nAllocs = 0; _maxAllocs = 0; _nUntracked = 0; } virtual int ItemSize() const { return ITEM_SIZE; } int CurrentAllocs() const { return _currentAllocs; } virtual void* Alloc() { if ( !_root ) { // Need a new block. Block* block = new Block; _blockPtrs.Push( block ); Item* blockItems = block->items; for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) { blockItems[i].next = &(blockItems[i + 1]); } blockItems[ITEMS_PER_BLOCK - 1].next = 0; _root = blockItems; } Item* const result = _root; TIXMLASSERT( result != 0 ); _root = _root->next; ++_currentAllocs; if ( _currentAllocs > _maxAllocs ) { _maxAllocs = _currentAllocs; } ++_nAllocs; ++_nUntracked; return result; } virtual void Free( void* mem ) { if ( !mem ) { return; } --_currentAllocs; Item* item = static_cast<Item*>( mem ); #ifdef TINYXML2_DEBUG memset( item, 0xfe, sizeof( *item ) ); #endif item->next = _root; _root = item; } void Trace( const char* name ) { printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", name, _maxAllocs, _maxAllocs * ITEM_SIZE / 1024, _currentAllocs, ITEM_SIZE, _nAllocs, _blockPtrs.Size() ); } void SetTracked() { --_nUntracked; } int Untracked() const { return _nUntracked; } // This number is perf sensitive. 4k seems like a good tradeoff on my machine. // The test file is large, 170k. // Release: VS2010 gcc(no opt) // 1k: 4000 // 2k: 4000 // 4k: 3900 21000 // 16k: 5200 // 32k: 4300 // 64k: 4000 21000 // Declared public because some compilers do not accept to use ITEMS_PER_BLOCK // in private part if ITEMS_PER_BLOCK is private enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE }; private: MemPoolT( const MemPoolT& ); // not supported void operator=( const MemPoolT& ); // not supported union Item { Item* next; char itemData[ITEM_SIZE]; }; struct Block { Item items[ITEMS_PER_BLOCK]; }; DynArray< Block*, 10 > _blockPtrs; Item* _root; int _currentAllocs; int _nAllocs; int _maxAllocs; int _nUntracked; }; /** Implements the interface to the "Visitor pattern" (see the Accept() method.) If you call the Accept() method, it requires being passed a XMLVisitor class to handle callbacks. For nodes that contain other nodes (Document, Element) you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs are simply called with Visit(). If you return 'true' from a Visit method, recursive parsing will continue. If you return false, <b>no children of this node or its siblings</b> will be visited. All flavors of Visit methods have a default implementation that returns 'true' (continue visiting). You need to only override methods that are interesting to you. Generally Accept() is called on the XMLDocument, although all nodes support visiting. You should never change the document from a callback. @sa XMLNode::Accept() */ class TINYXML2_LIB XMLVisitor { public: virtual ~XMLVisitor() {} /// Visit a document. virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { return true; } /// Visit a document. virtual bool VisitExit( const XMLDocument& /*doc*/ ) { return true; } /// Visit an element. virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) { return true; } /// Visit an element. virtual bool VisitExit( const XMLElement& /*element*/ ) { return true; } /// Visit a declaration. virtual bool Visit( const XMLDeclaration& /*declaration*/ ) { return true; } /// Visit a text node. virtual bool Visit( const XMLText& /*text*/ ) { return true; } /// Visit a comment node. virtual bool Visit( const XMLComment& /*comment*/ ) { return true; } /// Visit an unknown node. virtual bool Visit( const XMLUnknown& /*unknown*/ ) { return true; } }; // WARNING: must match XMLDocument::_errorNames[] enum XMLError { XML_SUCCESS = 0, XML_NO_ATTRIBUTE, XML_WRONG_ATTRIBUTE_TYPE, XML_ERROR_FILE_NOT_FOUND, XML_ERROR_FILE_COULD_NOT_BE_OPENED, XML_ERROR_FILE_READ_ERROR, XML_ERROR_PARSING_ELEMENT, XML_ERROR_PARSING_ATTRIBUTE, XML_ERROR_PARSING_TEXT, XML_ERROR_PARSING_CDATA, XML_ERROR_PARSING_COMMENT, XML_ERROR_PARSING_DECLARATION, XML_ERROR_PARSING_UNKNOWN, XML_ERROR_EMPTY_DOCUMENT, XML_ERROR_MISMATCHED_ELEMENT, XML_ERROR_PARSING, XML_CAN_NOT_CONVERT_TEXT, XML_NO_TEXT_NODE, XML_ELEMENT_DEPTH_EXCEEDED, XML_ERROR_COUNT }; /* Utility functionality. */ class TINYXML2_LIB XMLUtil { public: static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) { TIXMLASSERT( p ); while( IsWhiteSpace(*p) ) { if (curLineNumPtr && *p == '\n') { ++(*curLineNumPtr); } ++p; } TIXMLASSERT( p ); return p; } static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) { return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) ); } // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't // correct, but simple, and usually works. static bool IsWhiteSpace( char p ) { return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) ); } inline static bool IsNameStartChar( unsigned char ch ) { if ( ch >= 128 ) { // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() return true; } if ( isalpha( ch ) ) { return true; } return ch == ':' || ch == '_'; } inline static bool IsNameChar( unsigned char ch ) { return IsNameStartChar( ch ) || isdigit( ch ) || ch == '.' || ch == '-'; } inline static bool IsPrefixHex( const char* p) { p = SkipWhiteSpace(p, 0); return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X'); } inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { if ( p == q ) { return true; } TIXMLASSERT( p ); TIXMLASSERT( q ); TIXMLASSERT( nChar >= 0 ); return strncmp( p, q, nChar ) == 0; } inline static bool IsUTF8Continuation( const char p ) { return ( p & 0x80 ) != 0; } static const char* ReadBOM( const char* p, bool* hasBOM ); // p is the starting location, // the UTF-8 value of the entity will be placed in value, and length filled in. static const char* GetCharacterRef( const char* p, char* value, int* length ); static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); // converts primitive types to strings static void ToStr( int v, char* buffer, int bufferSize ); static void ToStr( unsigned v, char* buffer, int bufferSize ); static void ToStr( bool v, char* buffer, int bufferSize ); static void ToStr( float v, char* buffer, int bufferSize ); static void ToStr( double v, char* buffer, int bufferSize ); static void ToStr(int64_t v, char* buffer, int bufferSize); static void ToStr(uint64_t v, char* buffer, int bufferSize); // converts strings to primitive types static bool ToInt( const char* str, int* value ); static bool ToUnsigned( const char* str, unsigned* value ); static bool ToBool( const char* str, bool* value ); static bool ToFloat( const char* str, float* value ); static bool ToDouble( const char* str, double* value ); static bool ToInt64(const char* str, int64_t* value); static bool ToUnsigned64(const char* str, uint64_t* value); // Changes what is serialized for a boolean value. // Default to "true" and "false". Shouldn't be changed // unless you have a special testing or compatibility need. // Be careful: static, global, & not thread safe. // Be sure to set static const memory as parameters. static void SetBoolSerialization(const char* writeTrue, const char* writeFalse); private: static const char* writeBoolTrue; static const char* writeBoolFalse; }; /** XMLNode is a base class for every object that is in the XML Document Object Model (DOM), except XMLAttributes. Nodes have siblings, a parent, and children which can be navigated. A node is always in a XMLDocument. The type of a XMLNode can be queried, and it can be cast to its more defined type. A XMLDocument allocates memory for all its Nodes. When the XMLDocument gets deleted, all its Nodes will also be deleted. @verbatim A Document can contain: Element (container or leaf) Comment (leaf) Unknown (leaf) Declaration( leaf ) An Element can contain: Element (container or leaf) Text (leaf) Attributes (not on tree) Comment (leaf) Unknown (leaf) @endverbatim */ class TINYXML2_LIB XMLNode { friend class XMLDocument; friend class XMLElement; public: /// Get the XMLDocument that owns this XMLNode. const XMLDocument* GetDocument() const { TIXMLASSERT( _document ); return _document; } /// Get the XMLDocument that owns this XMLNode. XMLDocument* GetDocument() { TIXMLASSERT( _document ); return _document; } /// Safely cast to an Element, or null. virtual XMLElement* ToElement() { return 0; } /// Safely cast to Text, or null. virtual XMLText* ToText() { return 0; } /// Safely cast to a Comment, or null. virtual XMLComment* ToComment() { return 0; } /// Safely cast to a Document, or null. virtual XMLDocument* ToDocument() { return 0; } /// Safely cast to a Declaration, or null. virtual XMLDeclaration* ToDeclaration() { return 0; } /// Safely cast to an Unknown, or null. virtual XMLUnknown* ToUnknown() { return 0; } virtual const XMLElement* ToElement() const { return 0; } virtual const XMLText* ToText() const { return 0; } virtual const XMLComment* ToComment() const { return 0; } virtual const XMLDocument* ToDocument() const { return 0; } virtual const XMLDeclaration* ToDeclaration() const { return 0; } virtual const XMLUnknown* ToUnknown() const { return 0; } /** The meaning of 'value' changes for the specific type. @verbatim Document: empty (NULL is returned, not an empty string) Element: name of the element Comment: the comment text Unknown: the tag contents Text: the text string @endverbatim */ const char* Value() const; /** Set the Value of an XML node. @sa Value() */ void SetValue( const char* val, bool staticMem=false ); /// Gets the line number the node is in, if the document was parsed from a file. int GetLineNum() const { return _parseLineNum; } /// Get the parent of this node on the DOM. const XMLNode* Parent() const { return _parent; } XMLNode* Parent() { return _parent; } /// Returns true if this node has no children. bool NoChildren() const { return !_firstChild; } /// Get the first child node, or null if none exists. const XMLNode* FirstChild() const { return _firstChild; } XMLNode* FirstChild() { return _firstChild; } /** Get the first child element, or optionally the first child element with the specified name. */ const XMLElement* FirstChildElement( const char* name = 0 ) const; XMLElement* FirstChildElement( const char* name = 0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name )); } /// Get the last child node, or null if none exists. const XMLNode* LastChild() const { return _lastChild; } XMLNode* LastChild() { return _lastChild; } /** Get the last child element or optionally the last child element with the specified name. */ const XMLElement* LastChildElement( const char* name = 0 ) const; XMLElement* LastChildElement( const char* name = 0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) ); } /// Get the previous (left) sibling node of this node. const XMLNode* PreviousSibling() const { return _prev; } XMLNode* PreviousSibling() { return _prev; } /// Get the previous (left) sibling element of this node, with an optionally supplied name. const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ; XMLElement* PreviousSiblingElement( const char* name = 0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) ); } /// Get the next (right) sibling node of this node. const XMLNode* NextSibling() const { return _next; } XMLNode* NextSibling() { return _next; } /// Get the next (right) sibling element of this node, with an optionally supplied name. const XMLElement* NextSiblingElement( const char* name = 0 ) const; XMLElement* NextSiblingElement( const char* name = 0 ) { return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) ); } /** Add a child node as the last (right) child. If the child node is already part of the document, it is moved from its old location to the new location. Returns the addThis argument or 0 if the node does not belong to the same document. */ XMLNode* InsertEndChild( XMLNode* addThis ); XMLNode* LinkEndChild( XMLNode* addThis ) { return InsertEndChild( addThis ); } /** Add a child node as the first (left) child. If the child node is already part of the document, it is moved from its old location to the new location. Returns the addThis argument or 0 if the node does not belong to the same document. */ XMLNode* InsertFirstChild( XMLNode* addThis ); /** Add a node after the specified child node. If the child node is already part of the document, it is moved from its old location to the new location. Returns the addThis argument or 0 if the afterThis node is not a child of this node, or if the node does not belong to the same document. */ XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ); /** Delete all the children of this node. */ void DeleteChildren(); /** Delete a child of this node. */ void DeleteChild( XMLNode* node ); /** Make a copy of this node, but not its children. You may pass in a Document pointer that will be the owner of the new Node. If the 'document' is null, then the node returned will be allocated from the current Document. (this->GetDocument()) Note: if called on a XMLDocument, this will return null. */ virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0; /** Make a copy of this node and all its children. If the 'target' is null, then the nodes will be allocated in the current document. If 'target' is specified, the memory will be allocated is the specified XMLDocument. NOTE: This is probably not the correct tool to copy a document, since XMLDocuments can have multiple top level XMLNodes. You probably want to use XMLDocument::DeepCopy() */ XMLNode* DeepClone( XMLDocument* target ) const; /** Test if 2 nodes are the same, but don't test children. The 2 nodes do not need to be in the same Document. Note: if called on a XMLDocument, this will return false. */ virtual bool ShallowEqual( const XMLNode* compare ) const = 0; /** Accept a hierarchical visit of the nodes in the TinyXML-2 DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the XMLVisitor interface. This is essentially a SAX interface for TinyXML-2. (Note however it doesn't re-parse the XML for the callbacks, so the performance of TinyXML-2 is unchanged by using this interface versus any other.) The interface has been based on ideas from: - http://www.saxproject.org/ - http://c2.com/cgi/wiki?HierarchicalVisitorPattern Which are both good references for "visiting". An example of using Accept(): @verbatim XMLPrinter printer; tinyxmlDoc.Accept( &printer ); const char* xmlcstr = printer.CStr(); @endverbatim */ virtual bool Accept( XMLVisitor* visitor ) const = 0; /** Set user data into the XMLNode. TinyXML-2 in no way processes or interprets user data. It is initially 0. */ void SetUserData(void* userData) { _userData = userData; } /** Get user data set into the XMLNode. TinyXML-2 in no way processes or interprets user data. It is initially 0. */ void* GetUserData() const { return _userData; } protected: explicit XMLNode( XMLDocument* ); virtual ~XMLNode(); virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); XMLDocument* _document; XMLNode* _parent; mutable StrPair _value; int _parseLineNum; XMLNode* _firstChild; XMLNode* _lastChild; XMLNode* _prev; XMLNode* _next; void* _userData; private: MemPool* _memPool; void Unlink( XMLNode* child ); static void DeleteNode( XMLNode* node ); void InsertChildPreamble( XMLNode* insertThis ) const; const XMLElement* ToElementWithName( const char* name ) const; XMLNode( const XMLNode& ); // not supported XMLNode& operator=( const XMLNode& ); // not supported }; /** XML text. Note that a text node can have child element nodes, for example: @verbatim <root>This is <b>bold</b></root> @endverbatim A text node can have 2 ways to output the next. "normal" output and CDATA. It will default to the mode it was parsed from the XML file and you generally want to leave it alone, but you can change the output mode with SetCData() and query it with CData(). */ class TINYXML2_LIB XMLText : public XMLNode { friend class XMLDocument; public: virtual bool Accept( XMLVisitor* visitor ) const; virtual XMLText* ToText() { return this; } virtual const XMLText* ToText() const { return this; } /// Declare whether this should be CDATA or standard text. void SetCData( bool isCData ) { _isCData = isCData; } /// Returns true if this is a CDATA text element. bool CData() const { return _isCData; } virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual bool ShallowEqual( const XMLNode* compare ) const; protected: explicit XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} virtual ~XMLText() {} char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: bool _isCData; XMLText( const XMLText& ); // not supported XMLText& operator=( const XMLText& ); // not supported }; /** An XML Comment. */ class TINYXML2_LIB XMLComment : public XMLNode { friend class XMLDocument; public: virtual XMLComment* ToComment() { return this; } virtual const XMLComment* ToComment() const { return this; } virtual bool Accept( XMLVisitor* visitor ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual bool ShallowEqual( const XMLNode* compare ) const; protected: explicit XMLComment( XMLDocument* doc ); virtual ~XMLComment(); char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); private: XMLComment( const XMLComment& ); // not supported XMLComment& operator=( const XMLComment& ); // not supported }; /** In correct XML the declaration is the first entry in the file. @verbatim <?xml version="1.0" standalone="yes"?> @endverbatim TinyXML-2 will happily read or write files without a declaration, however. The text of the declaration isn't interpreted. It is parsed and written as a string. */ class TINYXML2_LIB XMLDeclaration : public XMLNode { friend class XMLDocument; public: virtual XMLDeclaration* ToDeclaration() { return this; } virtual const XMLDeclaration* ToDeclaration() const { return this; } virtual bool Accept( XMLVisitor* visitor ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual bool ShallowEqual( const XMLNode* compare ) const; protected: explicit XMLDeclaration( XMLDocument* doc ); virtual ~XMLDeclaration(); char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLDeclaration( const XMLDeclaration& ); // not supported XMLDeclaration& operator=( const XMLDeclaration& ); // not supported }; /** Any tag that TinyXML-2 doesn't recognize is saved as an unknown. It is a tag of text, but should not be modified. It will be written back to the XML, unchanged, when the file is saved. DTD tags get thrown into XMLUnknowns. */ class TINYXML2_LIB XMLUnknown : public XMLNode { friend class XMLDocument; public: virtual XMLUnknown* ToUnknown() { return this; } virtual const XMLUnknown* ToUnknown() const { return this; } virtual bool Accept( XMLVisitor* visitor ) const; virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual bool ShallowEqual( const XMLNode* compare ) const; protected: explicit XMLUnknown( XMLDocument* doc ); virtual ~XMLUnknown(); char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLUnknown( const XMLUnknown& ); // not supported XMLUnknown& operator=( const XMLUnknown& ); // not supported }; /** An attribute is a name-value pair. Elements have an arbitrary number of attributes, each with a unique name. @note The attributes are not XMLNodes. You may only query the Next() attribute in a list. */ class TINYXML2_LIB XMLAttribute { friend class XMLElement; public: /// The name of the attribute. const char* Name() const; /// The value of the attribute. const char* Value() const; /// Gets the line number the attribute is in, if the document was parsed from a file. int GetLineNum() const { return _parseLineNum; } /// The next attribute in the list. const XMLAttribute* Next() const { return _next; } /** IntValue interprets the attribute as an integer, and returns the value. If the value isn't an integer, 0 will be returned. There is no error checking; use QueryIntValue() if you need error checking. */ int IntValue() const { int i = 0; QueryIntValue(&i); return i; } int64_t Int64Value() const { int64_t i = 0; QueryInt64Value(&i); return i; } uint64_t Unsigned64Value() const { uint64_t i = 0; QueryUnsigned64Value(&i); return i; } /// Query as an unsigned integer. See IntValue() unsigned UnsignedValue() const { unsigned i=0; QueryUnsignedValue( &i ); return i; } /// Query as a boolean. See IntValue() bool BoolValue() const { bool b=false; QueryBoolValue( &b ); return b; } /// Query as a double. See IntValue() double DoubleValue() const { double d=0; QueryDoubleValue( &d ); return d; } /// Query as a float. See IntValue() float FloatValue() const { float f=0; QueryFloatValue( &f ); return f; } /** QueryIntValue interprets the attribute as an integer, and returns the value in the provided parameter. The function will return XML_SUCCESS on success, and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. */ XMLError QueryIntValue( int* value ) const; /// See QueryIntValue XMLError QueryUnsignedValue( unsigned int* value ) const; /// See QueryIntValue XMLError QueryInt64Value(int64_t* value) const; /// See QueryIntValue XMLError QueryUnsigned64Value(uint64_t* value) const; /// See QueryIntValue XMLError QueryBoolValue( bool* value ) const; /// See QueryIntValue XMLError QueryDoubleValue( double* value ) const; /// See QueryIntValue XMLError QueryFloatValue( float* value ) const; /// Set the attribute to a string value. void SetAttribute( const char* value ); /// Set the attribute to value. void SetAttribute( int value ); /// Set the attribute to value. void SetAttribute( unsigned value ); /// Set the attribute to value. void SetAttribute(int64_t value); /// Set the attribute to value. void SetAttribute(uint64_t value); /// Set the attribute to value. void SetAttribute( bool value ); /// Set the attribute to value. void SetAttribute( double value ); /// Set the attribute to value. void SetAttribute( float value ); private: enum { BUF_SIZE = 200 }; XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} virtual ~XMLAttribute() {} XMLAttribute( const XMLAttribute& ); // not supported void operator=( const XMLAttribute& ); // not supported void SetName( const char* name ); char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr ); mutable StrPair _name; mutable StrPair _value; int _parseLineNum; XMLAttribute* _next; MemPool* _memPool; }; /** The element is a container class. It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes. */ class TINYXML2_LIB XMLElement : public XMLNode { friend class XMLDocument; public: /// Get the name of an element (which is the Value() of the node.) const char* Name() const { return Value(); } /// Set the name of the element. void SetName( const char* str, bool staticMem=false ) { SetValue( str, staticMem ); } virtual XMLElement* ToElement() { return this; } virtual const XMLElement* ToElement() const { return this; } virtual bool Accept( XMLVisitor* visitor ) const; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. For example: @verbatim const char* value = ele->Attribute( "foo" ); @endverbatim The 'value' parameter is normally null. However, if specified, the attribute will only be returned if the 'name' and 'value' match. This allow you to write code: @verbatim if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar(); @endverbatim rather than: @verbatim if ( ele->Attribute( "foo" ) ) { if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar(); } @endverbatim */ const char* Attribute( const char* name, const char* value=0 ) const; /** Given an attribute name, IntAttribute() returns the value of the attribute interpreted as an integer. The default value will be returned if the attribute isn't present, or if there is an error. (For a method with error checking, see QueryIntAttribute()). */ int IntAttribute(const char* name, int defaultValue = 0) const; /// See IntAttribute() unsigned UnsignedAttribute(const char* name, unsigned defaultValue = 0) const; /// See IntAttribute() int64_t Int64Attribute(const char* name, int64_t defaultValue = 0) const; /// See IntAttribute() uint64_t Unsigned64Attribute(const char* name, uint64_t defaultValue = 0) const; /// See IntAttribute() bool BoolAttribute(const char* name, bool defaultValue = false) const; /// See IntAttribute() double DoubleAttribute(const char* name, double defaultValue = 0) const; /// See IntAttribute() float FloatAttribute(const char* name, float defaultValue = 0) const; /** Given an attribute name, QueryIntAttribute() returns XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. If successful, the result of the conversion will be written to 'value'. If not successful, nothing will be written to 'value'. This allows you to provide default value: @verbatim int value = 10; QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 @endverbatim */ XMLError QueryIntAttribute( const char* name, int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } return a->QueryIntValue( value ); } /// See QueryIntAttribute() XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } return a->QueryUnsignedValue( value ); } /// See QueryIntAttribute() XMLError QueryInt64Attribute(const char* name, int64_t* value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } return a->QueryInt64Value(value); } /// See QueryIntAttribute() XMLError QueryUnsigned64Attribute(const char* name, uint64_t* value) const { const XMLAttribute* a = FindAttribute(name); if(!a) { return XML_NO_ATTRIBUTE; } return a->QueryUnsigned64Value(value); } /// See QueryIntAttribute() XMLError QueryBoolAttribute( const char* name, bool* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } return a->QueryBoolValue( value ); } /// See QueryIntAttribute() XMLError QueryDoubleAttribute( const char* name, double* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } return a->QueryDoubleValue( value ); } /// See QueryIntAttribute() XMLError QueryFloatAttribute( const char* name, float* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return XML_NO_ATTRIBUTE; } return a->QueryFloatValue( value ); } /// See QueryIntAttribute() XMLError QueryStringAttribute(const char* name, const char** value) const { const XMLAttribute* a = FindAttribute(name); if (!a) { return XML_NO_ATTRIBUTE; } *value = a->Value(); return XML_SUCCESS; } /** Given an attribute name, QueryAttribute() returns XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. It is overloaded for the primitive types, and is a generally more convenient replacement of QueryIntAttribute() and related functions. If successful, the result of the conversion will be written to 'value'. If not successful, nothing will be written to 'value'. This allows you to provide default value: @verbatim int value = 10; QueryAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 @endverbatim */ XMLError QueryAttribute( const char* name, int* value ) const { return QueryIntAttribute( name, value ); } XMLError QueryAttribute( const char* name, unsigned int* value ) const { return QueryUnsignedAttribute( name, value ); } XMLError QueryAttribute(const char* name, int64_t* value) const { return QueryInt64Attribute(name, value); } XMLError QueryAttribute(const char* name, uint64_t* value) const { return QueryUnsigned64Attribute(name, value); } XMLError QueryAttribute( const char* name, bool* value ) const { return QueryBoolAttribute( name, value ); } XMLError QueryAttribute( const char* name, double* value ) const { return QueryDoubleAttribute( name, value ); } XMLError QueryAttribute( const char* name, float* value ) const { return QueryFloatAttribute( name, value ); } XMLError QueryAttribute(const char* name, const char** value) const { return QueryStringAttribute(name, value); } /// Sets the named attribute to value. void SetAttribute( const char* name, const char* value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. void SetAttribute( const char* name, int value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. void SetAttribute( const char* name, unsigned value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. void SetAttribute(const char* name, int64_t value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. void SetAttribute(const char* name, uint64_t value) { XMLAttribute* a = FindOrCreateAttribute(name); a->SetAttribute(value); } /// Sets the named attribute to value. void SetAttribute( const char* name, bool value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. void SetAttribute( const char* name, double value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /// Sets the named attribute to value. void SetAttribute( const char* name, float value ) { XMLAttribute* a = FindOrCreateAttribute( name ); a->SetAttribute( value ); } /** Delete an attribute. */ void DeleteAttribute( const char* name ); /// Return the first attribute in the list. const XMLAttribute* FirstAttribute() const { return _rootAttribute; } /// Query a specific attribute in the list. const XMLAttribute* FindAttribute( const char* name ) const; /** Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the XMLText child and accessing it directly. If the first child of 'this' is a XMLText, the GetText() returns the character string of the Text node, else null is returned. This is a convenient method for getting the text of simple contained text: @verbatim <foo>This is text</foo> const char* str = fooElement->GetText(); @endverbatim 'str' will be a pointer to "This is text". Note that this function can be misleading. If the element foo was created from this XML: @verbatim <foo><b>This is text</b></foo> @endverbatim then the value of str would be null. The first child node isn't a text node, it is another element. From this XML: @verbatim <foo>This is <b>text</b></foo> @endverbatim GetText() will return "This is ". */ const char* GetText() const; /** Convenience function for easy access to the text inside an element. Although easy and concise, SetText() is limited compared to creating an XMLText child and mutating it directly. If the first child of 'this' is a XMLText, SetText() sets its value to the given string, otherwise it will create a first child that is an XMLText. This is a convenient method for setting the text of simple contained text: @verbatim <foo>This is text</foo> fooElement->SetText( "Hullaballoo!" ); <foo>Hullaballoo!</foo> @endverbatim Note that this function can be misleading. If the element foo was created from this XML: @verbatim <foo><b>This is text</b></foo> @endverbatim then it will not change "This is text", but rather prefix it with a text element: @verbatim <foo>Hullaballoo!<b>This is text</b></foo> @endverbatim For this XML: @verbatim <foo /> @endverbatim SetText() will generate @verbatim <foo>Hullaballoo!</foo> @endverbatim */ void SetText( const char* inText ); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( int value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( unsigned value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText(int64_t value); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText(uint64_t value); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( bool value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( double value ); /// Convenience method for setting text inside an element. See SetText() for important limitations. void SetText( float value ); /** Convenience method to query the value of a child text node. This is probably best shown by example. Given you have a document is this form: @verbatim <point> <x>1</x> <y>1.4</y> </point> @endverbatim The QueryIntText() and similar functions provide a safe and easier way to get to the "value" of x and y. @verbatim int x = 0; float y = 0; // types of x and y are contrived for example const XMLElement* xElement = pointElement->FirstChildElement( "x" ); const XMLElement* yElement = pointElement->FirstChildElement( "y" ); xElement->QueryIntText( &x ); yElement->QueryFloatText( &y ); @endverbatim @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted to the requested type, and XML_NO_TEXT_NODE if there is no child text to query. */ XMLError QueryIntText( int* ival ) const; /// See QueryIntText() XMLError QueryUnsignedText( unsigned* uval ) const; /// See QueryIntText() XMLError QueryInt64Text(int64_t* uval) const; /// See QueryIntText() XMLError QueryUnsigned64Text(uint64_t* uval) const; /// See QueryIntText() XMLError QueryBoolText( bool* bval ) const; /// See QueryIntText() XMLError QueryDoubleText( double* dval ) const; /// See QueryIntText() XMLError QueryFloatText( float* fval ) const; int IntText(int defaultValue = 0) const; /// See QueryIntText() unsigned UnsignedText(unsigned defaultValue = 0) const; /// See QueryIntText() int64_t Int64Text(int64_t defaultValue = 0) const; /// See QueryIntText() uint64_t Unsigned64Text(uint64_t defaultValue = 0) const; /// See QueryIntText() bool BoolText(bool defaultValue = false) const; /// See QueryIntText() double DoubleText(double defaultValue = 0) const; /// See QueryIntText() float FloatText(float defaultValue = 0) const; /** Convenience method to create a new XMLElement and add it as last (right) child of this node. Returns the created and inserted element. */ XMLElement* InsertNewChildElement(const char* name); /// See InsertNewChildElement() XMLComment* InsertNewComment(const char* comment); /// See InsertNewChildElement() XMLText* InsertNewText(const char* text); /// See InsertNewChildElement() XMLDeclaration* InsertNewDeclaration(const char* text); /// See InsertNewChildElement() XMLUnknown* InsertNewUnknown(const char* text); // internal: enum ElementClosingType { OPEN, // <foo> CLOSED, // <foo/> CLOSING // </foo> }; ElementClosingType ClosingType() const { return _closingType; } virtual XMLNode* ShallowClone( XMLDocument* document ) const; virtual bool ShallowEqual( const XMLNode* compare ) const; protected: char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLElement( XMLDocument* doc ); virtual ~XMLElement(); XMLElement( const XMLElement& ); // not supported void operator=( const XMLElement& ); // not supported XMLAttribute* FindOrCreateAttribute( const char* name ); char* ParseAttributes( char* p, int* curLineNumPtr ); static void DeleteAttribute( XMLAttribute* attribute ); XMLAttribute* CreateAttribute(); enum { BUF_SIZE = 200 }; ElementClosingType _closingType; // The attribute list is ordered; there is no 'lastAttribute' // because the list needs to be scanned for dupes before adding // a new attribute. XMLAttribute* _rootAttribute; }; enum Whitespace { PRESERVE_WHITESPACE, COLLAPSE_WHITESPACE }; /** A Document binds together all the functionality. It can be saved, loaded, and printed to the screen. All Nodes are connected and allocated to a Document. If the Document is deleted, all its Nodes are also deleted. */ class TINYXML2_LIB XMLDocument : public XMLNode { friend class XMLElement; // Gives access to SetError and Push/PopDepth, but over-access for everything else. // Wishing C++ had "internal" scope. friend class XMLNode; friend class XMLText; friend class XMLComment; friend class XMLDeclaration; friend class XMLUnknown; public: /// constructor XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE ); ~XMLDocument(); virtual XMLDocument* ToDocument() { TIXMLASSERT( this == _document ); return this; } virtual const XMLDocument* ToDocument() const { TIXMLASSERT( this == _document ); return this; } /** Parse an XML file from a character string. Returns XML_SUCCESS (0) on success, or an errorID. You may optionally pass in the 'nBytes', which is the number of bytes which will be parsed. If not specified, TinyXML-2 will assume 'xml' points to a null terminated string. */ XMLError Parse( const char* xml, size_t nBytes=static_cast<size_t>(-1) ); /** Load an XML file from disk. Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError LoadFile( const char* filename ); /** Load an XML file from disk. You are responsible for providing and closing the FILE*. NOTE: The file should be opened as binary ("rb") not text in order for TinyXML-2 to correctly do newline normalization. Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError LoadFile( FILE* ); /** Save the XML file to disk. Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError SaveFile( const char* filename, bool compact = false ); /** Save the XML file to disk. You are responsible for providing and closing the FILE*. Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError SaveFile( FILE* fp, bool compact = false ); bool ProcessEntities() const { return _processEntities; } Whitespace WhitespaceMode() const { return _whitespaceMode; } /** Returns true if this document has a leading Byte Order Mark of UTF8. */ bool HasBOM() const { return _writeBOM; } /** Sets whether to write the BOM when writing the file. */ void SetBOM( bool useBOM ) { _writeBOM = useBOM; } /** Return the root element of DOM. Equivalent to FirstChildElement(). To get the first node, use FirstChild(). */ XMLElement* RootElement() { return FirstChildElement(); } const XMLElement* RootElement() const { return FirstChildElement(); } /** Print the Document. If the Printer is not provided, it will print to stdout. If you provide Printer, this can print to a file: @verbatim XMLPrinter printer( fp ); doc.Print( &printer ); @endverbatim Or you can use a printer to print to memory: @verbatim XMLPrinter printer; doc.Print( &printer ); // printer.CStr() has a const char* to the XML @endverbatim */ void Print( XMLPrinter* streamer=0 ) const; virtual bool Accept( XMLVisitor* visitor ) const; /** Create a new Element associated with this Document. The memory for the Element is managed by the Document. */ XMLElement* NewElement( const char* name ); /** Create a new Comment associated with this Document. The memory for the Comment is managed by the Document. */ XMLComment* NewComment( const char* comment ); /** Create a new Text associated with this Document. The memory for the Text is managed by the Document. */ XMLText* NewText( const char* text ); /** Create a new Declaration associated with this Document. The memory for the object is managed by the Document. If the 'text' param is null, the standard declaration is used.: @verbatim <?xml version="1.0" encoding="UTF-8"?> @endverbatim */ XMLDeclaration* NewDeclaration( const char* text=0 ); /** Create a new Unknown associated with this Document. The memory for the object is managed by the Document. */ XMLUnknown* NewUnknown( const char* text ); /** Delete a node associated with this document. It will be unlinked from the DOM. */ void DeleteNode( XMLNode* node ); /// Clears the error flags. void ClearError(); /// Return true if there was an error parsing the document. bool Error() const { return _errorID != XML_SUCCESS; } /// Return the errorID. XMLError ErrorID() const { return _errorID; } const char* ErrorName() const; static const char* ErrorIDToName(XMLError errorID); /** Returns a "long form" error description. A hopefully helpful diagnostic with location, line number, and/or additional info. */ const char* ErrorStr() const; /// A (trivial) utility function that prints the ErrorStr() to stdout. void PrintError() const; /// Return the line where the error occurred, or zero if unknown. int ErrorLineNum() const { return _errorLineNum; } /// Clear the document, resetting it to the initial state. void Clear(); /** Copies this document to a target document. The target will be completely cleared before the copy. If you want to copy a sub-tree, see XMLNode::DeepClone(). NOTE: that the 'target' must be non-null. */ void DeepCopy(XMLDocument* target) const; // internal char* Identify( char* p, XMLNode** node ); // internal void MarkInUse(const XMLNode* const); virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { return 0; } virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const { return false; } private: XMLDocument( const XMLDocument& ); // not supported void operator=( const XMLDocument& ); // not supported bool _writeBOM; bool _processEntities; XMLError _errorID; Whitespace _whitespaceMode; mutable StrPair _errorStr; int _errorLineNum; char* _charBuffer; int _parseCurLineNum; int _parsingDepth; // Memory tracking does add some overhead. // However, the code assumes that you don't // have a bunch of unlinked nodes around. // Therefore it takes less memory to track // in the document vs. a linked list in the XMLNode, // and the performance is the same. DynArray<XMLNode*, 10> _unlinked; MemPoolT< sizeof(XMLElement) > _elementPool; MemPoolT< sizeof(XMLAttribute) > _attributePool; MemPoolT< sizeof(XMLText) > _textPool; MemPoolT< sizeof(XMLComment) > _commentPool; static const char* _errorNames[XML_ERROR_COUNT]; void Parse(); void SetError( XMLError error, int lineNum, const char* format, ... ); // Something of an obvious security hole, once it was discovered. // Either an ill-formed XML or an excessively deep one can overflow // the stack. Track stack depth, and error out if needed. class DepthTracker { public: explicit DepthTracker(XMLDocument * document) { this->_document = document; document->PushDepth(); } ~DepthTracker() { _document->PopDepth(); } private: XMLDocument * _document; }; void PushDepth(); void PopDepth(); template<class NodeType, int PoolElementSize> NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool ); }; template<class NodeType, int PoolElementSize> inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool ) { TIXMLASSERT( sizeof( NodeType ) == PoolElementSize ); TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() ); NodeType* returnNode = new (pool.Alloc()) NodeType( this ); TIXMLASSERT( returnNode ); returnNode->_memPool = &pool; _unlinked.Push(returnNode); return returnNode; } /** A XMLHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thing. Note that XMLHandle is not part of the TinyXML-2 DOM structure. It is a separate utility class. Take an example: @verbatim <Document> <Element attributeA = "valueA"> <Child attributeB = "value1" /> <Child attributeB = "value2" /> </Element> </Document> @endverbatim Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very easy to write a *lot* of code that looks like: @verbatim XMLElement* root = document.FirstChildElement( "Document" ); if ( root ) { XMLElement* element = root->FirstChildElement( "Element" ); if ( element ) { XMLElement* child = element->FirstChildElement( "Child" ); if ( child ) { XMLElement* child2 = child->NextSiblingElement( "Child" ); if ( child2 ) { // Finally do something useful. @endverbatim And that doesn't even cover "else" cases. XMLHandle addresses the verbosity of such code. A XMLHandle checks for null pointers so it is perfectly safe and correct to use: @verbatim XMLHandle docHandle( &document ); XMLElement* child2 = docHandle.FirstChildElement( "Document" ).FirstChildElement( "Element" ).FirstChildElement().NextSiblingElement(); if ( child2 ) { // do something useful @endverbatim Which is MUCH more concise and useful. It is also safe to copy handles - internally they are nothing more than node pointers. @verbatim XMLHandle handleCopy = handle; @endverbatim See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects. */ class TINYXML2_LIB XMLHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. explicit XMLHandle( XMLNode* node ) : _node( node ) { } /// Create a handle from a node. explicit XMLHandle( XMLNode& node ) : _node( &node ) { } /// Copy constructor XMLHandle( const XMLHandle& ref ) : _node( ref._node ) { } /// Assignment XMLHandle& operator=( const XMLHandle& ref ) { _node = ref._node; return *this; } /// Get the first child of this handle. XMLHandle FirstChild() { return XMLHandle( _node ? _node->FirstChild() : 0 ); } /// Get the first child element of this handle. XMLHandle FirstChildElement( const char* name = 0 ) { return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 ); } /// Get the last child of this handle. XMLHandle LastChild() { return XMLHandle( _node ? _node->LastChild() : 0 ); } /// Get the last child element of this handle. XMLHandle LastChildElement( const char* name = 0 ) { return XMLHandle( _node ? _node->LastChildElement( name ) : 0 ); } /// Get the previous sibling of this handle. XMLHandle PreviousSibling() { return XMLHandle( _node ? _node->PreviousSibling() : 0 ); } /// Get the previous sibling element of this handle. XMLHandle PreviousSiblingElement( const char* name = 0 ) { return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 ); } /// Get the next sibling of this handle. XMLHandle NextSibling() { return XMLHandle( _node ? _node->NextSibling() : 0 ); } /// Get the next sibling element of this handle. XMLHandle NextSiblingElement( const char* name = 0 ) { return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 ); } /// Safe cast to XMLNode. This can return null. XMLNode* ToNode() { return _node; } /// Safe cast to XMLElement. This can return null. XMLElement* ToElement() { return ( _node ? _node->ToElement() : 0 ); } /// Safe cast to XMLText. This can return null. XMLText* ToText() { return ( _node ? _node->ToText() : 0 ); } /// Safe cast to XMLUnknown. This can return null. XMLUnknown* ToUnknown() { return ( _node ? _node->ToUnknown() : 0 ); } /// Safe cast to XMLDeclaration. This can return null. XMLDeclaration* ToDeclaration() { return ( _node ? _node->ToDeclaration() : 0 ); } private: XMLNode* _node; }; /** A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the same in all regards, except for the 'const' qualifiers. See XMLHandle for API. */ class TINYXML2_LIB XMLConstHandle { public: explicit XMLConstHandle( const XMLNode* node ) : _node( node ) { } explicit XMLConstHandle( const XMLNode& node ) : _node( &node ) { } XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) { } XMLConstHandle& operator=( const XMLConstHandle& ref ) { _node = ref._node; return *this; } const XMLConstHandle FirstChild() const { return XMLConstHandle( _node ? _node->FirstChild() : 0 ); } const XMLConstHandle FirstChildElement( const char* name = 0 ) const { return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 ); } const XMLConstHandle LastChild() const { return XMLConstHandle( _node ? _node->LastChild() : 0 ); } const XMLConstHandle LastChildElement( const char* name = 0 ) const { return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 ); } const XMLConstHandle PreviousSibling() const { return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); } const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const { return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 ); } const XMLConstHandle NextSibling() const { return XMLConstHandle( _node ? _node->NextSibling() : 0 ); } const XMLConstHandle NextSiblingElement( const char* name = 0 ) const { return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 ); } const XMLNode* ToNode() const { return _node; } const XMLElement* ToElement() const { return ( _node ? _node->ToElement() : 0 ); } const XMLText* ToText() const { return ( _node ? _node->ToText() : 0 ); } const XMLUnknown* ToUnknown() const { return ( _node ? _node->ToUnknown() : 0 ); } const XMLDeclaration* ToDeclaration() const { return ( _node ? _node->ToDeclaration() : 0 ); } private: const XMLNode* _node; }; /** Printing functionality. The XMLPrinter gives you more options than the XMLDocument::Print() method. It can: -# Print to memory. -# Print to a file you provide. -# Print XML without a XMLDocument. Print to Memory @verbatim XMLPrinter printer; doc.Print( &printer ); SomeFunction( printer.CStr() ); @endverbatim Print to a File You provide the file pointer. @verbatim XMLPrinter printer( fp ); doc.Print( &printer ); @endverbatim Print without a XMLDocument When loading, an XML parser is very useful. However, sometimes when saving, it just gets in the way. The code is often set up for streaming, and constructing the DOM is just overhead. The Printer supports the streaming case. The following code prints out a trivially simple XML file without ever creating an XML document. @verbatim XMLPrinter printer( fp ); printer.OpenElement( "foo" ); printer.PushAttribute( "foo", "bar" ); printer.CloseElement(); @endverbatim */ class TINYXML2_LIB XMLPrinter : public XMLVisitor { public: /** Construct the printer. If the FILE* is specified, this will print to the FILE. Else it will print to memory, and the result is available in CStr(). If 'compact' is set to true, then output is created with only required whitespace and newlines. */ XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 ); virtual ~XMLPrinter() {} /** If streaming, write the BOM and declaration. */ void PushHeader( bool writeBOM, bool writeDeclaration ); /** If streaming, start writing an element. The element must be closed with CloseElement() */ void OpenElement( const char* name, bool compactMode=false ); /// If streaming, add an attribute to an open element. void PushAttribute( const char* name, const char* value ); void PushAttribute( const char* name, int value ); void PushAttribute( const char* name, unsigned value ); void PushAttribute( const char* name, int64_t value ); void PushAttribute( const char* name, uint64_t value ); void PushAttribute( const char* name, bool value ); void PushAttribute( const char* name, double value ); /// If streaming, close the Element. virtual void CloseElement( bool compactMode=false ); /// Add a text node. void PushText( const char* text, bool cdata=false ); /// Add a text node from an integer. void PushText( int value ); /// Add a text node from an unsigned. void PushText( unsigned value ); /// Add a text node from a signed 64bit integer. void PushText( int64_t value ); /// Add a text node from an unsigned 64bit integer. void PushText( uint64_t value ); /// Add a text node from a bool. void PushText( bool value ); /// Add a text node from a float. void PushText( float value ); /// Add a text node from a double. void PushText( double value ); /// Add a comment void PushComment( const char* comment ); void PushDeclaration( const char* value ); void PushUnknown( const char* value ); virtual bool VisitEnter( const XMLDocument& /*doc*/ ); virtual bool VisitExit( const XMLDocument& /*doc*/ ) { return true; } virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ); virtual bool VisitExit( const XMLElement& element ); virtual bool Visit( const XMLText& text ); virtual bool Visit( const XMLComment& comment ); virtual bool Visit( const XMLDeclaration& declaration ); virtual bool Visit( const XMLUnknown& unknown ); /** If in print to memory mode, return a pointer to the XML file in memory. */ const char* CStr() const { return _buffer.Mem(); } /** If in print to memory mode, return the size of the XML file in memory. (Note the size returned includes the terminating null.) */ int CStrSize() const { return _buffer.Size(); } /** If in print to memory mode, reset the buffer to the beginning. */ void ClearBuffer( bool resetToFirstElement = true ) { _buffer.Clear(); _buffer.Push(0); _firstElement = resetToFirstElement; } protected: virtual bool CompactMode( const XMLElement& ) { return _compactMode; } /** Prints out the space before an element. You may override to change the space and tabs used. A PrintSpace() override should call Print(). */ virtual void PrintSpace( int depth ); virtual void Print( const char* format, ... ); virtual void Write( const char* data, size_t size ); virtual void Putc( char ch ); inline void Write(const char* data) { Write(data, strlen(data)); } void SealElementIfJustOpened(); bool _elementJustOpened; DynArray< const char*, 10 > _stack; private: /** Prepares to write a new node. This includes sealing an element that was just opened, and writing any whitespace necessary if not in compact mode. */ void PrepareForNewNode( bool compactMode ); void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. bool _firstElement; FILE* _fp; int _depth; int _textDepth; bool _processEntities; bool _compactMode; enum { ENTITY_RANGE = 64, BUF_SIZE = 200 }; bool _entityFlag[ENTITY_RANGE]; bool _restrictedEntityFlag[ENTITY_RANGE]; DynArray< char, 20 > _buffer; // Prohibit cloning, intentionally not implemented XMLPrinter( const XMLPrinter& ); XMLPrinter& operator=( const XMLPrinter& ); }; } // tinyxml2 #if defined(_MSC_VER) # pragma warning(pop) #endif #endif // TINYXML2_INCLUDED
71,400
C
29.00042
166
0.641106
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/iMpcdiDataProvider.cpp
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <pxr/pxr.h> #include <pxr/base/tf/token.h> #include <pxr/base/tf/type.h> #include "iMpcdiDataProvider.h" PXR_NAMESPACE_OPEN_SCOPE IEdfDataProvider::IEdfDataProvider(const EdfDataParameters& parameters) : _parameters(parameters) { } IEdfDataProvider::~IEdfDataProvider() = default; IEdfSourceData::~IEdfSourceData() = default; const EdfDataParameters& IEdfDataProvider::GetParameters() const { return this->_parameters; } TF_REGISTRY_FUNCTION(TfType) { TfType::Define<IEdfDataProvider>(); } PXR_NAMESPACE_CLOSE_SCOPE
1,127
C++
26.512194
97
0.761313
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiDataProviderFactory.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_EDF_EDFDATAPROVIDERFACTORY_H_ #define OMNI_EDF_EDFDATAPROVIDERFACTORY_H_ #include <pxr/pxr.h> #include <pxr/base/tf/registryManager.h> #include <pxr/base/tf/type.h> #include "api.h" #include "iMpcdiDataProvider.h" PXR_NAMESPACE_OPEN_SCOPE #ifdef doxygen #define EDF_DEFINE_DATAPROVIDER(ProviderClass, BaseClass1, ...) #else #define EDF_DEFINE_DATAPROVIDER(...) \ TF_REGISTRY_FUNCTION(TfType) { \ EdfDefineDataProvider<__VA_ARGS__>(); \ } #endif class EdfDataProviderFactoryBase : public TfType::FactoryBase { public: MPCDI_API virtual ~EdfDataProviderFactoryBase(); MPCDI_API virtual IEdfDataProvider* New(const EdfDataParameters& parameters) const = 0; }; template <class T> class EdfDataProviderFactory : public EdfDataProviderFactoryBase { public: virtual IEdfDataProvider* New(const EdfDataParameters& parameters) const override { return new T(parameters); } }; template <class DataProvider, class ...Bases> void EdfDefineDataProvider() { TfType::Define<DataProvider, TfType::Bases<Bases...>>().template SetFactory<EdfDataProviderFactory<DataProvider> >(); } PXR_NAMESPACE_CLOSE_SCOPE #endif
1,735
C
27.459016
118
0.757349
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/tinyxml2.cpp
/* Original code by Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "tinyxml2.h" #include <new> // yes, this one new style header, is in the Android SDK. #if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__) # include <stddef.h> # include <stdarg.h> #else # include <cstddef> # include <cstdarg> #endif #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) // Microsoft Visual Studio, version 2005 and higher. Not WinCE. /*int _snprintf_s( char *buffer, size_t sizeOfBuffer, size_t count, const char *format [, argument] ... );*/ static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) { va_list va; va_start( va, format ); const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); va_end( va ); return result; } static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va ) { const int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); return result; } #define TIXML_VSCPRINTF _vscprintf #define TIXML_SSCANF sscanf_s #elif defined _MSC_VER // Microsoft Visual Studio 2003 and earlier or WinCE #define TIXML_SNPRINTF _snprintf #define TIXML_VSNPRINTF _vsnprintf #define TIXML_SSCANF sscanf #if (_MSC_VER < 1400 ) && (!defined WINCE) // Microsoft Visual Studio 2003 and not WinCE. #define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have. #else // Microsoft Visual Studio 2003 and earlier or WinCE. static inline int TIXML_VSCPRINTF( const char* format, va_list va ) { int len = 512; for (;;) { len = len*2; char* str = new char[len](); const int required = _vsnprintf(str, len, format, va); delete[] str; if ( required != -1 ) { TIXMLASSERT( required >= 0 ); len = required; break; } } TIXMLASSERT( len >= 0 ); return len; } #endif #else // GCC version 3 and higher //#warning( "Using sn* functions." ) #define TIXML_SNPRINTF snprintf #define TIXML_VSNPRINTF vsnprintf static inline int TIXML_VSCPRINTF( const char* format, va_list va ) { int len = vsnprintf( 0, 0, format, va ); TIXMLASSERT( len >= 0 ); return len; } #define TIXML_SSCANF sscanf #endif #if defined(_WIN64) #define TIXML_FSEEK _fseeki64 #define TIXML_FTELL _ftelli64 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || (__CYGWIN__) #define TIXML_FSEEK fseeko #define TIXML_FTELL ftello #elif defined(__ANDROID__) #if __ANDROID_API__ > 24 #define TIXML_FSEEK fseeko64 #define TIXML_FTELL ftello64 #else #define TIXML_FSEEK fseeko #define TIXML_FTELL ftello #endif #elif defined(__unix__) && defined(__x86_64__) #define TIXML_FSEEK fseeko64 #define TIXML_FTELL ftello64 #else #define TIXML_FSEEK fseek #define TIXML_FTELL ftell #endif static const char LINE_FEED = static_cast<char>(0x0a); // all line endings are normalized to LF static const char LF = LINE_FEED; static const char CARRIAGE_RETURN = static_cast<char>(0x0d); // CR gets filtered out static const char CR = CARRIAGE_RETURN; static const char SINGLE_QUOTE = '\''; static const char DOUBLE_QUOTE = '\"'; // Bunch of unicode info at: // http://www.unicode.org/faq/utf_bom.html // ef bb bf (Microsoft "lead bytes") - designates UTF-8 static const unsigned char TIXML_UTF_LEAD_0 = 0xefU; static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; namespace tinyxml2 { struct Entity { const char* pattern; int length; char value; }; static const int NUM_ENTITIES = 5; static const Entity entities[NUM_ENTITIES] = { { "quot", 4, DOUBLE_QUOTE }, { "amp", 3, '&' }, { "apos", 4, SINGLE_QUOTE }, { "lt", 2, '<' }, { "gt", 2, '>' } }; StrPair::~StrPair() { Reset(); } void StrPair::TransferTo( StrPair* other ) { if ( this == other ) { return; } // This in effect implements the assignment operator by "moving" // ownership (as in auto_ptr). TIXMLASSERT( other != 0 ); TIXMLASSERT( other->_flags == 0 ); TIXMLASSERT( other->_start == 0 ); TIXMLASSERT( other->_end == 0 ); other->Reset(); other->_flags = _flags; other->_start = _start; other->_end = _end; _flags = 0; _start = 0; _end = 0; } void StrPair::Reset() { if ( _flags & NEEDS_DELETE ) { delete [] _start; } _flags = 0; _start = 0; _end = 0; } void StrPair::SetStr( const char* str, int flags ) { TIXMLASSERT( str ); Reset(); size_t len = strlen( str ); TIXMLASSERT( _start == 0 ); _start = new char[ len+1 ]; memcpy( _start, str, len+1 ); _end = _start + len; _flags = flags | NEEDS_DELETE; } char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLineNumPtr ) { TIXMLASSERT( p ); TIXMLASSERT( endTag && *endTag ); TIXMLASSERT(curLineNumPtr); char* start = p; const char endChar = *endTag; size_t length = strlen( endTag ); // Inner loop of text parsing. while ( *p ) { if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { Set( start, p, strFlags ); return p + length; } else if (*p == '\n') { ++(*curLineNumPtr); } ++p; TIXMLASSERT( p ); } return 0; } char* StrPair::ParseName( char* p ) { if ( !p || !(*p) ) { return 0; } if ( !XMLUtil::IsNameStartChar( (unsigned char) *p ) ) { return 0; } char* const start = p; ++p; while ( *p && XMLUtil::IsNameChar( (unsigned char) *p ) ) { ++p; } Set( start, p, 0 ); return p; } void StrPair::CollapseWhitespace() { // Adjusting _start would cause undefined behavior on delete[] TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 ); // Trim leading space. _start = XMLUtil::SkipWhiteSpace( _start, 0 ); if ( *_start ) { const char* p = _start; // the read pointer char* q = _start; // the write pointer while( *p ) { if ( XMLUtil::IsWhiteSpace( *p )) { p = XMLUtil::SkipWhiteSpace( p, 0 ); if ( *p == 0 ) { break; // don't write to q; this trims the trailing space. } *q = ' '; ++q; } *q = *p; ++q; ++p; } *q = 0; } } const char* StrPair::GetStr() { TIXMLASSERT( _start ); TIXMLASSERT( _end ); if ( _flags & NEEDS_FLUSH ) { *_end = 0; _flags ^= NEEDS_FLUSH; if ( _flags ) { const char* p = _start; // the read pointer char* q = _start; // the write pointer while( p < _end ) { if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) { // CR-LF pair becomes LF // CR alone becomes LF // LF-CR becomes LF if ( *(p+1) == LF ) { p += 2; } else { ++p; } *q = LF; ++q; } else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { if ( *(p+1) == CR ) { p += 2; } else { ++p; } *q = LF; ++q; } else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { // Entities handled by tinyXML2: // - special entities in the entity table [in/out] // - numeric character reference [in] // &#20013; or &#x4e2d; if ( *(p+1) == '#' ) { const int buflen = 10; char buf[buflen] = { 0 }; int len = 0; const char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) ); if ( adjusted == 0 ) { *q = *p; ++p; ++q; } else { TIXMLASSERT( 0 <= len && len <= buflen ); TIXMLASSERT( q + len <= adjusted ); p = adjusted; memcpy( q, buf, len ); q += len; } } else { bool entityFound = false; for( int i = 0; i < NUM_ENTITIES; ++i ) { const Entity& entity = entities[i]; if ( strncmp( p + 1, entity.pattern, entity.length ) == 0 && *( p + entity.length + 1 ) == ';' ) { // Found an entity - convert. *q = entity.value; ++q; p += entity.length + 2; entityFound = true; break; } } if ( !entityFound ) { // fixme: treat as error? ++p; ++q; } } } else { *q = *p; ++p; ++q; } } *q = 0; } // The loop below has plenty going on, and this // is a less useful mode. Break it out. if ( _flags & NEEDS_WHITESPACE_COLLAPSING ) { CollapseWhitespace(); } _flags = (_flags & NEEDS_DELETE); } TIXMLASSERT( _start ); return _start; } // --------- XMLUtil ----------- // const char* XMLUtil::writeBoolTrue = "true"; const char* XMLUtil::writeBoolFalse = "false"; void XMLUtil::SetBoolSerialization(const char* writeTrue, const char* writeFalse) { static const char* defTrue = "true"; static const char* defFalse = "false"; writeBoolTrue = (writeTrue) ? writeTrue : defTrue; writeBoolFalse = (writeFalse) ? writeFalse : defFalse; } const char* XMLUtil::ReadBOM( const char* p, bool* bom ) { TIXMLASSERT( p ); TIXMLASSERT( bom ); *bom = false; const unsigned char* pu = reinterpret_cast<const unsigned char*>(p); // Check for BOM: if ( *(pu+0) == TIXML_UTF_LEAD_0 && *(pu+1) == TIXML_UTF_LEAD_1 && *(pu+2) == TIXML_UTF_LEAD_2 ) { *bom = true; p += 3; } TIXMLASSERT( p ); return p; } void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) { const unsigned long BYTE_MASK = 0xBF; const unsigned long BYTE_MARK = 0x80; const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; if (input < 0x80) { *length = 1; } else if ( input < 0x800 ) { *length = 2; } else if ( input < 0x10000 ) { *length = 3; } else if ( input < 0x200000 ) { *length = 4; } else { *length = 0; // This code won't convert this correctly anyway. return; } output += *length; // Scary scary fall throughs are annotated with carefully designed comments // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc switch (*length) { case 4: --output; *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK); input >>= 6; //fall through case 3: --output; *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK); input >>= 6; //fall through case 2: --output; *output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK); input >>= 6; //fall through case 1: --output; *output = static_cast<char>(input | FIRST_BYTE_MARK[*length]); break; default: TIXMLASSERT( false ); } } const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) { // Presume an entity, and pull it out. *length = 0; if ( *(p+1) == '#' && *(p+2) ) { unsigned long ucs = 0; TIXMLASSERT( sizeof( ucs ) >= 4 ); ptrdiff_t delta = 0; unsigned mult = 1; static const char SEMICOLON = ';'; if ( *(p+2) == 'x' ) { // Hexadecimal. const char* q = p+3; if ( !(*q) ) { return 0; } q = strchr( q, SEMICOLON ); if ( !q ) { return 0; } TIXMLASSERT( *q == SEMICOLON ); delta = q-p; --q; while ( *q != 'x' ) { unsigned int digit = 0; if ( *q >= '0' && *q <= '9' ) { digit = *q - '0'; } else if ( *q >= 'a' && *q <= 'f' ) { digit = *q - 'a' + 10; } else if ( *q >= 'A' && *q <= 'F' ) { digit = *q - 'A' + 10; } else { return 0; } TIXMLASSERT( digit < 16 ); TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit ); const unsigned int digitScaled = mult * digit; TIXMLASSERT( ucs <= ULONG_MAX - digitScaled ); ucs += digitScaled; TIXMLASSERT( mult <= UINT_MAX / 16 ); mult *= 16; --q; } } else { // Decimal. const char* q = p+2; if ( !(*q) ) { return 0; } q = strchr( q, SEMICOLON ); if ( !q ) { return 0; } TIXMLASSERT( *q == SEMICOLON ); delta = q-p; --q; while ( *q != '#' ) { if ( *q >= '0' && *q <= '9' ) { const unsigned int digit = *q - '0'; TIXMLASSERT( digit < 10 ); TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit ); const unsigned int digitScaled = mult * digit; TIXMLASSERT( ucs <= ULONG_MAX - digitScaled ); ucs += digitScaled; } else { return 0; } TIXMLASSERT( mult <= UINT_MAX / 10 ); mult *= 10; --q; } } // convert the UCS to UTF-8 ConvertUTF32ToUTF8( ucs, value, length ); return p + delta + 1; } return p+1; } void XMLUtil::ToStr( int v, char* buffer, int bufferSize ) { TIXML_SNPRINTF( buffer, bufferSize, "%d", v ); } void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize ) { TIXML_SNPRINTF( buffer, bufferSize, "%u", v ); } void XMLUtil::ToStr( bool v, char* buffer, int bufferSize ) { TIXML_SNPRINTF( buffer, bufferSize, "%s", v ? writeBoolTrue : writeBoolFalse); } /* ToStr() of a number is a very tricky topic. https://github.com/leethomason/tinyxml2/issues/106 */ void XMLUtil::ToStr( float v, char* buffer, int bufferSize ) { TIXML_SNPRINTF( buffer, bufferSize, "%.8g", v ); } void XMLUtil::ToStr( double v, char* buffer, int bufferSize ) { TIXML_SNPRINTF( buffer, bufferSize, "%.17g", v ); } void XMLUtil::ToStr( int64_t v, char* buffer, int bufferSize ) { // horrible syntax trick to make the compiler happy about %lld TIXML_SNPRINTF(buffer, bufferSize, "%lld", static_cast<long long>(v)); } void XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize ) { // horrible syntax trick to make the compiler happy about %llu TIXML_SNPRINTF(buffer, bufferSize, "%llu", (long long)v); } bool XMLUtil::ToInt(const char* str, int* value) { if (IsPrefixHex(str)) { unsigned v; if (TIXML_SSCANF(str, "%x", &v) == 1) { *value = static_cast<int>(v); return true; } } else { if (TIXML_SSCANF(str, "%d", value) == 1) { return true; } } return false; } bool XMLUtil::ToUnsigned(const char* str, unsigned* value) { if (TIXML_SSCANF(str, IsPrefixHex(str) ? "%x" : "%u", value) == 1) { return true; } return false; } bool XMLUtil::ToBool( const char* str, bool* value ) { int ival = 0; if ( ToInt( str, &ival )) { *value = (ival==0) ? false : true; return true; } static const char* TRUE_VALS[] = { "true", "True", "TRUE", 0 }; static const char* FALSE_VALS[] = { "false", "False", "FALSE", 0 }; for (int i = 0; TRUE_VALS[i]; ++i) { if (StringEqual(str, TRUE_VALS[i])) { *value = true; return true; } } for (int i = 0; FALSE_VALS[i]; ++i) { if (StringEqual(str, FALSE_VALS[i])) { *value = false; return true; } } return false; } bool XMLUtil::ToFloat( const char* str, float* value ) { if ( TIXML_SSCANF( str, "%f", value ) == 1 ) { return true; } return false; } bool XMLUtil::ToDouble( const char* str, double* value ) { if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) { return true; } return false; } bool XMLUtil::ToInt64(const char* str, int64_t* value) { if (IsPrefixHex(str)) { unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llx if (TIXML_SSCANF(str, "%llx", &v) == 1) { *value = static_cast<int64_t>(v); return true; } } else { long long v = 0; // horrible syntax trick to make the compiler happy about %lld if (TIXML_SSCANF(str, "%lld", &v) == 1) { *value = static_cast<int64_t>(v); return true; } } return false; } bool XMLUtil::ToUnsigned64(const char* str, uint64_t* value) { unsigned long long v = 0; // horrible syntax trick to make the compiler happy about %llu if(TIXML_SSCANF(str, IsPrefixHex(str) ? "%llx" : "%llu", &v) == 1) { *value = (uint64_t)v; return true; } return false; } char* XMLDocument::Identify( char* p, XMLNode** node ) { TIXMLASSERT( node ); TIXMLASSERT( p ); char* const start = p; int const startLine = _parseCurLineNum; p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); if( !*p ) { *node = 0; TIXMLASSERT( p ); return p; } // These strings define the matching patterns: static const char* xmlHeader = { "<?" }; static const char* commentHeader = { "<!--" }; static const char* cdataHeader = { "<![CDATA[" }; static const char* dtdHeader = { "<!" }; static const char* elementHeader = { "<" }; // and a header for everything else; check last. static const int xmlHeaderLen = 2; static const int commentHeaderLen = 4; static const int cdataHeaderLen = 9; static const int dtdHeaderLen = 2; static const int elementHeaderLen = 1; TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool XMLNode* returnNode = 0; if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { returnNode = CreateUnlinkedNode<XMLDeclaration>( _commentPool ); returnNode->_parseLineNum = _parseCurLineNum; p += xmlHeaderLen; } else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { returnNode = CreateUnlinkedNode<XMLComment>( _commentPool ); returnNode->_parseLineNum = _parseCurLineNum; p += commentHeaderLen; } else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { XMLText* text = CreateUnlinkedNode<XMLText>( _textPool ); returnNode = text; returnNode->_parseLineNum = _parseCurLineNum; p += cdataHeaderLen; text->SetCData( true ); } else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { returnNode = CreateUnlinkedNode<XMLUnknown>( _commentPool ); returnNode->_parseLineNum = _parseCurLineNum; p += dtdHeaderLen; } else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { returnNode = CreateUnlinkedNode<XMLElement>( _elementPool ); returnNode->_parseLineNum = _parseCurLineNum; p += elementHeaderLen; } else { returnNode = CreateUnlinkedNode<XMLText>( _textPool ); returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character p = start; // Back it up, all the text counts. _parseCurLineNum = startLine; } TIXMLASSERT( returnNode ); TIXMLASSERT( p ); *node = returnNode; return p; } bool XMLDocument::Accept( XMLVisitor* visitor ) const { TIXMLASSERT( visitor ); if ( visitor->VisitEnter( *this ) ) { for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { if ( !node->Accept( visitor ) ) { break; } } } return visitor->VisitExit( *this ); } // --------- XMLNode ----------- // XMLNode::XMLNode( XMLDocument* doc ) : _document( doc ), _parent( 0 ), _value(), _parseLineNum( 0 ), _firstChild( 0 ), _lastChild( 0 ), _prev( 0 ), _next( 0 ), _userData( 0 ), _memPool( 0 ) { } XMLNode::~XMLNode() { DeleteChildren(); if ( _parent ) { _parent->Unlink( this ); } } const char* XMLNode::Value() const { // Edge case: XMLDocuments don't have a Value. Return null. if ( this->ToDocument() ) return 0; return _value.GetStr(); } void XMLNode::SetValue( const char* str, bool staticMem ) { if ( staticMem ) { _value.SetInternedStr( str ); } else { _value.SetStr( str ); } } XMLNode* XMLNode::DeepClone(XMLDocument* target) const { XMLNode* clone = this->ShallowClone(target); if (!clone) return 0; for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) { XMLNode* childClone = child->DeepClone(target); TIXMLASSERT(childClone); clone->InsertEndChild(childClone); } return clone; } void XMLNode::DeleteChildren() { while( _firstChild ) { TIXMLASSERT( _lastChild ); DeleteChild( _firstChild ); } _firstChild = _lastChild = 0; } void XMLNode::Unlink( XMLNode* child ) { TIXMLASSERT( child ); TIXMLASSERT( child->_document == _document ); TIXMLASSERT( child->_parent == this ); if ( child == _firstChild ) { _firstChild = _firstChild->_next; } if ( child == _lastChild ) { _lastChild = _lastChild->_prev; } if ( child->_prev ) { child->_prev->_next = child->_next; } if ( child->_next ) { child->_next->_prev = child->_prev; } child->_next = 0; child->_prev = 0; child->_parent = 0; } void XMLNode::DeleteChild( XMLNode* node ) { TIXMLASSERT( node ); TIXMLASSERT( node->_document == _document ); TIXMLASSERT( node->_parent == this ); Unlink( node ); TIXMLASSERT(node->_prev == 0); TIXMLASSERT(node->_next == 0); TIXMLASSERT(node->_parent == 0); DeleteNode( node ); } XMLNode* XMLNode::InsertEndChild( XMLNode* addThis ) { TIXMLASSERT( addThis ); if ( addThis->_document != _document ) { TIXMLASSERT( false ); return 0; } InsertChildPreamble( addThis ); if ( _lastChild ) { TIXMLASSERT( _firstChild ); TIXMLASSERT( _lastChild->_next == 0 ); _lastChild->_next = addThis; addThis->_prev = _lastChild; _lastChild = addThis; addThis->_next = 0; } else { TIXMLASSERT( _firstChild == 0 ); _firstChild = _lastChild = addThis; addThis->_prev = 0; addThis->_next = 0; } addThis->_parent = this; return addThis; } XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) { TIXMLASSERT( addThis ); if ( addThis->_document != _document ) { TIXMLASSERT( false ); return 0; } InsertChildPreamble( addThis ); if ( _firstChild ) { TIXMLASSERT( _lastChild ); TIXMLASSERT( _firstChild->_prev == 0 ); _firstChild->_prev = addThis; addThis->_next = _firstChild; _firstChild = addThis; addThis->_prev = 0; } else { TIXMLASSERT( _lastChild == 0 ); _firstChild = _lastChild = addThis; addThis->_prev = 0; addThis->_next = 0; } addThis->_parent = this; return addThis; } XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) { TIXMLASSERT( addThis ); if ( addThis->_document != _document ) { TIXMLASSERT( false ); return 0; } TIXMLASSERT( afterThis ); if ( afterThis->_parent != this ) { TIXMLASSERT( false ); return 0; } if ( afterThis == addThis ) { // Current state: BeforeThis -> AddThis -> OneAfterAddThis // Now AddThis must disappear from it's location and then // reappear between BeforeThis and OneAfterAddThis. // So just leave it where it is. return addThis; } if ( afterThis->_next == 0 ) { // The last node or the only node. return InsertEndChild( addThis ); } InsertChildPreamble( addThis ); addThis->_prev = afterThis; addThis->_next = afterThis->_next; afterThis->_next->_prev = addThis; afterThis->_next = addThis; addThis->_parent = this; return addThis; } const XMLElement* XMLNode::FirstChildElement( const char* name ) const { for( const XMLNode* node = _firstChild; node; node = node->_next ) { const XMLElement* element = node->ToElementWithName( name ); if ( element ) { return element; } } return 0; } const XMLElement* XMLNode::LastChildElement( const char* name ) const { for( const XMLNode* node = _lastChild; node; node = node->_prev ) { const XMLElement* element = node->ToElementWithName( name ); if ( element ) { return element; } } return 0; } const XMLElement* XMLNode::NextSiblingElement( const char* name ) const { for( const XMLNode* node = _next; node; node = node->_next ) { const XMLElement* element = node->ToElementWithName( name ); if ( element ) { return element; } } return 0; } const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const { for( const XMLNode* node = _prev; node; node = node->_prev ) { const XMLElement* element = node->ToElementWithName( name ); if ( element ) { return element; } } return 0; } char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) { // This is a recursive method, but thinking about it "at the current level" // it is a pretty simple flat list: // <foo/> // <!-- comment --> // // With a special case: // <foo> // </foo> // <!-- comment --> // // Where the closing element (/foo) *must* be the next thing after the opening // element, and the names must match. BUT the tricky bit is that the closing // element will be read by the child. // // 'endTag' is the end tag for this node, it is returned by a call to a child. // 'parentEnd' is the end tag for the parent, which is filled in and returned. XMLDocument::DepthTracker tracker(_document); if (_document->Error()) return 0; while( p && *p ) { XMLNode* node = 0; p = _document->Identify( p, &node ); TIXMLASSERT( p ); if ( node == 0 ) { break; } const int initialLineNum = node->_parseLineNum; StrPair endTag; p = node->ParseDeep( p, &endTag, curLineNumPtr ); if ( !p ) { _document->DeleteNode( node ); if ( !_document->Error() ) { _document->SetError( XML_ERROR_PARSING, initialLineNum, 0); } break; } const XMLDeclaration* const decl = node->ToDeclaration(); if ( decl ) { // Declarations are only allowed at document level // // Multiple declarations are allowed but all declarations // must occur before anything else. // // Optimized due to a security test case. If the first node is // a declaration, and the last node is a declaration, then only // declarations have so far been added. bool wellLocated = false; if (ToDocument()) { if (FirstChild()) { wellLocated = FirstChild() && FirstChild()->ToDeclaration() && LastChild() && LastChild()->ToDeclaration(); } else { wellLocated = true; } } if ( !wellLocated ) { _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value()); _document->DeleteNode( node ); break; } } XMLElement* ele = node->ToElement(); if ( ele ) { // We read the end tag. Return it to the parent. if ( ele->ClosingType() == XMLElement::CLOSING ) { if ( parentEndTag ) { ele->_value.TransferTo( parentEndTag ); } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode( node ); return p; } // Handle an end tag returned to this level. // And handle a bunch of annoying errors. bool mismatch = false; if ( endTag.Empty() ) { if ( ele->ClosingType() == XMLElement::OPEN ) { mismatch = true; } } else { if ( ele->ClosingType() != XMLElement::OPEN ) { mismatch = true; } else if ( !XMLUtil::StringEqual( endTag.GetStr(), ele->Name() ) ) { mismatch = true; } } if ( mismatch ) { _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name()); _document->DeleteNode( node ); break; } } InsertEndChild( node ); } return 0; } /*static*/ void XMLNode::DeleteNode( XMLNode* node ) { if ( node == 0 ) { return; } TIXMLASSERT(node->_document); if (!node->ToDocument()) { node->_document->MarkInUse(node); } MemPool* pool = node->_memPool; node->~XMLNode(); pool->Free( node ); } void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const { TIXMLASSERT( insertThis ); TIXMLASSERT( insertThis->_document == _document ); if (insertThis->_parent) { insertThis->_parent->Unlink( insertThis ); } else { insertThis->_document->MarkInUse(insertThis); insertThis->_memPool->SetTracked(); } } const XMLElement* XMLNode::ToElementWithName( const char* name ) const { const XMLElement* element = this->ToElement(); if ( element == 0 ) { return 0; } if ( name == 0 ) { return element; } if ( XMLUtil::StringEqual( element->Name(), name ) ) { return element; } return 0; } // --------- XMLText ---------- // char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { if ( this->CData() ) { p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { _document->SetError( XML_ERROR_PARSING_CDATA, _parseLineNum, 0 ); } return p; } else { int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) { flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING; } p = _value.ParseText( p, "<", flags, curLineNumPtr ); if ( p && *p ) { return p-1; } if ( !p ) { _document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, 0 ); } } return 0; } XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { doc = _document; } XMLText* text = doc->NewText( Value() ); // fixme: this will always allocate memory. Intern? text->SetCData( this->CData() ); return text; } bool XMLText::ShallowEqual( const XMLNode* compare ) const { TIXMLASSERT( compare ); const XMLText* text = compare->ToText(); return ( text && XMLUtil::StringEqual( text->Value(), Value() ) ); } bool XMLText::Accept( XMLVisitor* visitor ) const { TIXMLASSERT( visitor ); return visitor->Visit( *this ); } // --------- XMLComment ---------- // XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc ) { } XMLComment::~XMLComment() { } char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Comment parses as text. p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr ); if ( p == 0 ) { _document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 ); } return p; } XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { doc = _document; } XMLComment* comment = doc->NewComment( Value() ); // fixme: this will always allocate memory. Intern? return comment; } bool XMLComment::ShallowEqual( const XMLNode* compare ) const { TIXMLASSERT( compare ); const XMLComment* comment = compare->ToComment(); return ( comment && XMLUtil::StringEqual( comment->Value(), Value() )); } bool XMLComment::Accept( XMLVisitor* visitor ) const { TIXMLASSERT( visitor ); return visitor->Visit( *this ); } // --------- XMLDeclaration ---------- // XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode( doc ) { } XMLDeclaration::~XMLDeclaration() { //printf( "~XMLDeclaration\n" ); } char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Declaration parses as text. p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( p == 0 ) { _document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 ); } return p; } XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { doc = _document; } XMLDeclaration* dec = doc->NewDeclaration( Value() ); // fixme: this will always allocate memory. Intern? return dec; } bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const { TIXMLASSERT( compare ); const XMLDeclaration* declaration = compare->ToDeclaration(); return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() )); } bool XMLDeclaration::Accept( XMLVisitor* visitor ) const { TIXMLASSERT( visitor ); return visitor->Visit( *this ); } // --------- XMLUnknown ---------- // XMLUnknown::XMLUnknown( XMLDocument* doc ) : XMLNode( doc ) { } XMLUnknown::~XMLUnknown() { } char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Unknown parses as text. p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { _document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 ); } return p; } XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { doc = _document; } XMLUnknown* text = doc->NewUnknown( Value() ); // fixme: this will always allocate memory. Intern? return text; } bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const { TIXMLASSERT( compare ); const XMLUnknown* unknown = compare->ToUnknown(); return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() )); } bool XMLUnknown::Accept( XMLVisitor* visitor ) const { TIXMLASSERT( visitor ); return visitor->Visit( *this ); } // --------- XMLAttribute ---------- // const char* XMLAttribute::Name() const { return _name.GetStr(); } const char* XMLAttribute::Value() const { return _value.GetStr(); } char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr ) { // Parse using the name rules: bug fix, was using ParseText before p = _name.ParseName( p ); if ( !p || !*p ) { return 0; } // Skip white space before = p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( *p != '=' ) { return 0; } ++p; // move up to opening quote p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( *p != '\"' && *p != '\'' ) { return 0; } const char endTag[2] = { *p, 0 }; ++p; // move past opening quote p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES, curLineNumPtr ); return p; } void XMLAttribute::SetName( const char* n ) { _name.SetStr( n ); } XMLError XMLAttribute::QueryIntValue( int* value ) const { if ( XMLUtil::ToInt( Value(), value )) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const { if ( XMLUtil::ToUnsigned( Value(), value )) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } XMLError XMLAttribute::QueryInt64Value(int64_t* value) const { if (XMLUtil::ToInt64(Value(), value)) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } XMLError XMLAttribute::QueryUnsigned64Value(uint64_t* value) const { if(XMLUtil::ToUnsigned64(Value(), value)) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } XMLError XMLAttribute::QueryBoolValue( bool* value ) const { if ( XMLUtil::ToBool( Value(), value )) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } XMLError XMLAttribute::QueryFloatValue( float* value ) const { if ( XMLUtil::ToFloat( Value(), value )) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } XMLError XMLAttribute::QueryDoubleValue( double* value ) const { if ( XMLUtil::ToDouble( Value(), value )) { return XML_SUCCESS; } return XML_WRONG_ATTRIBUTE_TYPE; } void XMLAttribute::SetAttribute( const char* v ) { _value.SetStr( v ); } void XMLAttribute::SetAttribute( int v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } void XMLAttribute::SetAttribute( unsigned v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } void XMLAttribute::SetAttribute(int64_t v) { char buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } void XMLAttribute::SetAttribute(uint64_t v) { char buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); _value.SetStr(buf); } void XMLAttribute::SetAttribute( bool v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } void XMLAttribute::SetAttribute( double v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } void XMLAttribute::SetAttribute( float v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); _value.SetStr( buf ); } // --------- XMLElement ---------- // XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), _closingType( OPEN ), _rootAttribute( 0 ) { } XMLElement::~XMLElement() { while( _rootAttribute ) { XMLAttribute* next = _rootAttribute->_next; DeleteAttribute( _rootAttribute ); _rootAttribute = next; } } const XMLAttribute* XMLElement::FindAttribute( const char* name ) const { for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) { if ( XMLUtil::StringEqual( a->Name(), name ) ) { return a; } } return 0; } const char* XMLElement::Attribute( const char* name, const char* value ) const { const XMLAttribute* a = FindAttribute( name ); if ( !a ) { return 0; } if ( !value || XMLUtil::StringEqual( a->Value(), value )) { return a->Value(); } return 0; } int XMLElement::IntAttribute(const char* name, int defaultValue) const { int i = defaultValue; QueryIntAttribute(name, &i); return i; } unsigned XMLElement::UnsignedAttribute(const char* name, unsigned defaultValue) const { unsigned i = defaultValue; QueryUnsignedAttribute(name, &i); return i; } int64_t XMLElement::Int64Attribute(const char* name, int64_t defaultValue) const { int64_t i = defaultValue; QueryInt64Attribute(name, &i); return i; } uint64_t XMLElement::Unsigned64Attribute(const char* name, uint64_t defaultValue) const { uint64_t i = defaultValue; QueryUnsigned64Attribute(name, &i); return i; } bool XMLElement::BoolAttribute(const char* name, bool defaultValue) const { bool b = defaultValue; QueryBoolAttribute(name, &b); return b; } double XMLElement::DoubleAttribute(const char* name, double defaultValue) const { double d = defaultValue; QueryDoubleAttribute(name, &d); return d; } float XMLElement::FloatAttribute(const char* name, float defaultValue) const { float f = defaultValue; QueryFloatAttribute(name, &f); return f; } const char* XMLElement::GetText() const { /* skip comment node */ const XMLNode* node = FirstChild(); while (node) { if (node->ToComment()) { node = node->NextSibling(); continue; } break; } if ( node && node->ToText() ) { return node->Value(); } return 0; } void XMLElement::SetText( const char* inText ) { if ( FirstChild() && FirstChild()->ToText() ) FirstChild()->SetValue( inText ); else { XMLText* theText = GetDocument()->NewText( inText ); InsertFirstChild( theText ); } } void XMLElement::SetText( int v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } void XMLElement::SetText( unsigned v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } void XMLElement::SetText(int64_t v) { char buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } void XMLElement::SetText(uint64_t v) { char buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); SetText(buf); } void XMLElement::SetText( bool v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } void XMLElement::SetText( float v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } void XMLElement::SetText( double v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); SetText( buf ); } XMLError XMLElement::QueryIntText( int* ival ) const { if ( FirstChild() && FirstChild()->ToText() ) { const char* t = FirstChild()->Value(); if ( XMLUtil::ToInt( t, ival ) ) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const { if ( FirstChild() && FirstChild()->ToText() ) { const char* t = FirstChild()->Value(); if ( XMLUtil::ToUnsigned( t, uval ) ) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } XMLError XMLElement::QueryInt64Text(int64_t* ival) const { if (FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if (XMLUtil::ToInt64(t, ival)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } XMLError XMLElement::QueryUnsigned64Text(uint64_t* uval) const { if(FirstChild() && FirstChild()->ToText()) { const char* t = FirstChild()->Value(); if(XMLUtil::ToUnsigned64(t, uval)) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } XMLError XMLElement::QueryBoolText( bool* bval ) const { if ( FirstChild() && FirstChild()->ToText() ) { const char* t = FirstChild()->Value(); if ( XMLUtil::ToBool( t, bval ) ) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } XMLError XMLElement::QueryDoubleText( double* dval ) const { if ( FirstChild() && FirstChild()->ToText() ) { const char* t = FirstChild()->Value(); if ( XMLUtil::ToDouble( t, dval ) ) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } XMLError XMLElement::QueryFloatText( float* fval ) const { if ( FirstChild() && FirstChild()->ToText() ) { const char* t = FirstChild()->Value(); if ( XMLUtil::ToFloat( t, fval ) ) { return XML_SUCCESS; } return XML_CAN_NOT_CONVERT_TEXT; } return XML_NO_TEXT_NODE; } int XMLElement::IntText(int defaultValue) const { int i = defaultValue; QueryIntText(&i); return i; } unsigned XMLElement::UnsignedText(unsigned defaultValue) const { unsigned i = defaultValue; QueryUnsignedText(&i); return i; } int64_t XMLElement::Int64Text(int64_t defaultValue) const { int64_t i = defaultValue; QueryInt64Text(&i); return i; } uint64_t XMLElement::Unsigned64Text(uint64_t defaultValue) const { uint64_t i = defaultValue; QueryUnsigned64Text(&i); return i; } bool XMLElement::BoolText(bool defaultValue) const { bool b = defaultValue; QueryBoolText(&b); return b; } double XMLElement::DoubleText(double defaultValue) const { double d = defaultValue; QueryDoubleText(&d); return d; } float XMLElement::FloatText(float defaultValue) const { float f = defaultValue; QueryFloatText(&f); return f; } XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) { XMLAttribute* last = 0; XMLAttribute* attrib = 0; for( attrib = _rootAttribute; attrib; last = attrib, attrib = attrib->_next ) { if ( XMLUtil::StringEqual( attrib->Name(), name ) ) { break; } } if ( !attrib ) { attrib = CreateAttribute(); TIXMLASSERT( attrib ); if ( last ) { TIXMLASSERT( last->_next == 0 ); last->_next = attrib; } else { TIXMLASSERT( _rootAttribute == 0 ); _rootAttribute = attrib; } attrib->SetName( name ); } return attrib; } void XMLElement::DeleteAttribute( const char* name ) { XMLAttribute* prev = 0; for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) { if ( XMLUtil::StringEqual( name, a->Name() ) ) { if ( prev ) { prev->_next = a->_next; } else { _rootAttribute = a->_next; } DeleteAttribute( a ); break; } prev = a; } } char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) { XMLAttribute* prevAttribute = 0; // Read the attributes. while( p ) { p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( !(*p) ) { _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() ); return 0; } // attribute. if (XMLUtil::IsNameStartChar( (unsigned char) *p ) ) { XMLAttribute* attrib = CreateAttribute(); TIXMLASSERT( attrib ); attrib->_parseLineNum = _document->_parseCurLineNum; const int attrLineNum = attrib->_parseLineNum; p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr ); if ( !p || Attribute( attrib->Name() ) ) { DeleteAttribute( attrib ); _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() ); return 0; } // There is a minor bug here: if the attribute in the source xml // document is duplicated, it will not be detected and the // attribute will be doubly added. However, tracking the 'prevAttribute' // avoids re-scanning the attribute list. Preferring performance for // now, may reconsider in the future. if ( prevAttribute ) { TIXMLASSERT( prevAttribute->_next == 0 ); prevAttribute->_next = attrib; } else { TIXMLASSERT( _rootAttribute == 0 ); _rootAttribute = attrib; } prevAttribute = attrib; } // end of the tag else if ( *p == '>' ) { ++p; break; } // end of the tag else if ( *p == '/' && *(p+1) == '>' ) { _closingType = CLOSED; return p+2; // done; sealed element. } else { _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0 ); return 0; } } return p; } void XMLElement::DeleteAttribute( XMLAttribute* attribute ) { if ( attribute == 0 ) { return; } MemPool* pool = attribute->_memPool; attribute->~XMLAttribute(); pool->Free( attribute ); } XMLAttribute* XMLElement::CreateAttribute() { TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); TIXMLASSERT( attrib ); attrib->_memPool = &_document->_attributePool; attrib->_memPool->SetTracked(); return attrib; } XMLElement* XMLElement::InsertNewChildElement(const char* name) { XMLElement* node = _document->NewElement(name); return InsertEndChild(node) ? node : 0; } XMLComment* XMLElement::InsertNewComment(const char* comment) { XMLComment* node = _document->NewComment(comment); return InsertEndChild(node) ? node : 0; } XMLText* XMLElement::InsertNewText(const char* text) { XMLText* node = _document->NewText(text); return InsertEndChild(node) ? node : 0; } XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text) { XMLDeclaration* node = _document->NewDeclaration(text); return InsertEndChild(node) ? node : 0; } XMLUnknown* XMLElement::InsertNewUnknown(const char* text) { XMLUnknown* node = _document->NewUnknown(text); return InsertEndChild(node) ? node : 0; } // // <ele></ele> // <ele>foo<b>bar</b></ele> // char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) { // Read the element name. p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); // The closing element is the </element> form. It is // parsed just like a regular element then deleted from // the DOM. if ( *p == '/' ) { _closingType = CLOSING; ++p; } p = _value.ParseName( p ); if ( _value.Empty() ) { return 0; } p = ParseAttributes( p, curLineNumPtr ); if ( !p || !*p || _closingType != OPEN ) { return p; } p = XMLNode::ParseDeep( p, parentEndTag, curLineNumPtr ); return p; } XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const { if ( !doc ) { doc = _document; } XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern? for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) { element->SetAttribute( a->Name(), a->Value() ); // fixme: this will always allocate memory. Intern? } return element; } bool XMLElement::ShallowEqual( const XMLNode* compare ) const { TIXMLASSERT( compare ); const XMLElement* other = compare->ToElement(); if ( other && XMLUtil::StringEqual( other->Name(), Name() )) { const XMLAttribute* a=FirstAttribute(); const XMLAttribute* b=other->FirstAttribute(); while ( a && b ) { if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) { return false; } a = a->Next(); b = b->Next(); } if ( a || b ) { // different count return false; } return true; } return false; } bool XMLElement::Accept( XMLVisitor* visitor ) const { TIXMLASSERT( visitor ); if ( visitor->VisitEnter( *this, _rootAttribute ) ) { for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { if ( !node->Accept( visitor ) ) { break; } } } return visitor->VisitExit( *this ); } // --------- XMLDocument ----------- // // Warning: List must match 'enum XMLError' const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { "XML_SUCCESS", "XML_NO_ATTRIBUTE", "XML_WRONG_ATTRIBUTE_TYPE", "XML_ERROR_FILE_NOT_FOUND", "XML_ERROR_FILE_COULD_NOT_BE_OPENED", "XML_ERROR_FILE_READ_ERROR", "XML_ERROR_PARSING_ELEMENT", "XML_ERROR_PARSING_ATTRIBUTE", "XML_ERROR_PARSING_TEXT", "XML_ERROR_PARSING_CDATA", "XML_ERROR_PARSING_COMMENT", "XML_ERROR_PARSING_DECLARATION", "XML_ERROR_PARSING_UNKNOWN", "XML_ERROR_EMPTY_DOCUMENT", "XML_ERROR_MISMATCHED_ELEMENT", "XML_ERROR_PARSING", "XML_CAN_NOT_CONVERT_TEXT", "XML_NO_TEXT_NODE", "XML_ELEMENT_DEPTH_EXCEEDED" }; XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : XMLNode( 0 ), _writeBOM( false ), _processEntities( processEntities ), _errorID(XML_SUCCESS), _whitespaceMode( whitespaceMode ), _errorStr(), _errorLineNum( 0 ), _charBuffer( 0 ), _parseCurLineNum( 0 ), _parsingDepth(0), _unlinked(), _elementPool(), _attributePool(), _textPool(), _commentPool() { // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) _document = this; } XMLDocument::~XMLDocument() { Clear(); } void XMLDocument::MarkInUse(const XMLNode* const node) { TIXMLASSERT(node); TIXMLASSERT(node->_parent == 0); for (int i = 0; i < _unlinked.Size(); ++i) { if (node == _unlinked[i]) { _unlinked.SwapRemove(i); break; } } } void XMLDocument::Clear() { DeleteChildren(); while( _unlinked.Size()) { DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete. } #ifdef TINYXML2_DEBUG const bool hadError = Error(); #endif ClearError(); delete [] _charBuffer; _charBuffer = 0; _parsingDepth = 0; #if 0 _textPool.Trace( "text" ); _elementPool.Trace( "element" ); _commentPool.Trace( "comment" ); _attributePool.Trace( "attribute" ); #endif #ifdef TINYXML2_DEBUG if ( !hadError ) { TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() ); TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() ); TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() ); } #endif } void XMLDocument::DeepCopy(XMLDocument* target) const { TIXMLASSERT(target); if (target == this) { return; // technically success - a no-op. } target->Clear(); for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) { target->InsertEndChild(node->DeepClone(target)); } } XMLElement* XMLDocument::NewElement( const char* name ) { XMLElement* ele = CreateUnlinkedNode<XMLElement>( _elementPool ); ele->SetName( name ); return ele; } XMLComment* XMLDocument::NewComment( const char* str ) { XMLComment* comment = CreateUnlinkedNode<XMLComment>( _commentPool ); comment->SetValue( str ); return comment; } XMLText* XMLDocument::NewText( const char* str ) { XMLText* text = CreateUnlinkedNode<XMLText>( _textPool ); text->SetValue( str ); return text; } XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) { XMLDeclaration* dec = CreateUnlinkedNode<XMLDeclaration>( _commentPool ); dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); return dec; } XMLUnknown* XMLDocument::NewUnknown( const char* str ) { XMLUnknown* unk = CreateUnlinkedNode<XMLUnknown>( _commentPool ); unk->SetValue( str ); return unk; } static FILE* callfopen( const char* filepath, const char* mode ) { TIXMLASSERT( filepath ); TIXMLASSERT( mode ); #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE) FILE* fp = 0; const errno_t err = fopen_s( &fp, filepath, mode ); if ( err ) { return 0; } #else FILE* fp = fopen( filepath, mode ); #endif return fp; } void XMLDocument::DeleteNode( XMLNode* node ) { TIXMLASSERT( node ); TIXMLASSERT(node->_document == this ); if (node->_parent) { node->_parent->DeleteChild( node ); } else { // Isn't in the tree. // Use the parent delete. // Also, we need to mark it tracked: we 'know' // it was never used. node->_memPool->SetTracked(); // Call the static XMLNode version: XMLNode::DeleteNode(node); } } XMLError XMLDocument::LoadFile( const char* filename ) { if ( !filename ) { TIXMLASSERT( false ); SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=<null>" ); return _errorID; } Clear(); FILE* fp = callfopen( filename, "rb" ); if ( !fp ) { SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ); return _errorID; } LoadFile( fp ); fclose( fp ); return _errorID; } XMLError XMLDocument::LoadFile( FILE* fp ) { Clear(); TIXML_FSEEK( fp, 0, SEEK_SET ); if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } TIXML_FSEEK( fp, 0, SEEK_END ); unsigned long long filelength; { const long long fileLengthSigned = TIXML_FTELL( fp ); TIXML_FSEEK( fp, 0, SEEK_SET ); if ( fileLengthSigned == -1L ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } TIXMLASSERT( fileLengthSigned >= 0 ); filelength = static_cast<unsigned long long>(fileLengthSigned); } const size_t maxSizeT = static_cast<size_t>(-1); // We'll do the comparison as an unsigned long long, because that's guaranteed to be at // least 8 bytes, even on a 32-bit platform. if ( filelength >= static_cast<unsigned long long>(maxSizeT) ) { // Cannot handle files which won't fit in buffer together with null terminator SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } if ( filelength == 0 ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } const size_t size = static_cast<size_t>(filelength); TIXMLASSERT( _charBuffer == 0 ); _charBuffer = new char[size+1]; const size_t read = fread( _charBuffer, 1, size, fp ); if ( read != size ) { SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } _charBuffer[size] = 0; Parse(); return _errorID; } XMLError XMLDocument::SaveFile( const char* filename, bool compact ) { if ( !filename ) { TIXMLASSERT( false ); SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=<null>" ); return _errorID; } FILE* fp = callfopen( filename, "w" ); if ( !fp ) { SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ); return _errorID; } SaveFile(fp, compact); fclose( fp ); return _errorID; } XMLError XMLDocument::SaveFile( FILE* fp, bool compact ) { // Clear any error from the last save, otherwise it will get reported // for *this* call. ClearError(); XMLPrinter stream( fp, compact ); Print( &stream ); return _errorID; } XMLError XMLDocument::Parse( const char* xml, size_t nBytes ) { Clear(); if ( nBytes == 0 || !xml || !*xml ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } if ( nBytes == static_cast<size_t>(-1) ) { nBytes = strlen( xml ); } TIXMLASSERT( _charBuffer == 0 ); _charBuffer = new char[ nBytes+1 ]; memcpy( _charBuffer, xml, nBytes ); _charBuffer[nBytes] = 0; Parse(); if ( Error() ) { // clean up now essentially dangling memory. // and the parse fail can put objects in the // pools that are dead and inaccessible. DeleteChildren(); _elementPool.Clear(); _attributePool.Clear(); _textPool.Clear(); _commentPool.Clear(); } return _errorID; } void XMLDocument::Print( XMLPrinter* streamer ) const { if ( streamer ) { Accept( streamer ); } else { XMLPrinter stdoutStreamer( stdout ); Accept( &stdoutStreamer ); } } void XMLDocument::ClearError() { _errorID = XML_SUCCESS; _errorLineNum = 0; _errorStr.Reset(); } void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... ) { TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT ); _errorID = error; _errorLineNum = lineNum; _errorStr.Reset(); const size_t BUFFER_SIZE = 1000; char* buffer = new char[BUFFER_SIZE]; TIXMLASSERT(sizeof(error) <= sizeof(int)); TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum); if (format) { size_t len = strlen(buffer); TIXML_SNPRINTF(buffer + len, BUFFER_SIZE - len, ": "); len = strlen(buffer); va_list va; va_start(va, format); TIXML_VSNPRINTF(buffer + len, BUFFER_SIZE - len, format, va); va_end(va); } _errorStr.SetStr(buffer); delete[] buffer; } /*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID) { TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT ); const char* errorName = _errorNames[errorID]; TIXMLASSERT( errorName && errorName[0] ); return errorName; } const char* XMLDocument::ErrorStr() const { return _errorStr.Empty() ? "" : _errorStr.GetStr(); } void XMLDocument::PrintError() const { printf("%s\n", ErrorStr()); } const char* XMLDocument::ErrorName() const { return ErrorIDToName(_errorID); } void XMLDocument::Parse() { TIXMLASSERT( NoChildren() ); // Clear() must have been called previously TIXMLASSERT( _charBuffer ); _parseCurLineNum = 1; _parseLineNum = 1; char* p = _charBuffer; p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); p = const_cast<char*>( XMLUtil::ReadBOM( p, &_writeBOM ) ); if ( !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return; } ParseDeep(p, 0, &_parseCurLineNum ); } void XMLDocument::PushDepth() { _parsingDepth++; if (_parsingDepth == TINYXML2_MAX_ELEMENT_DEPTH) { SetError(XML_ELEMENT_DEPTH_EXCEEDED, _parseCurLineNum, "Element nesting is too deep." ); } } void XMLDocument::PopDepth() { TIXMLASSERT(_parsingDepth > 0); --_parsingDepth; } XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : _elementJustOpened( false ), _stack(), _firstElement( true ), _fp( file ), _depth( depth ), _textDepth( -1 ), _processEntities( true ), _compactMode( compact ), _buffer() { for( int i=0; i<ENTITY_RANGE; ++i ) { _entityFlag[i] = false; _restrictedEntityFlag[i] = false; } for( int i=0; i<NUM_ENTITIES; ++i ) { const char entityValue = entities[i].value; const unsigned char flagIndex = static_cast<unsigned char>(entityValue); TIXMLASSERT( flagIndex < ENTITY_RANGE ); _entityFlag[flagIndex] = true; } _restrictedEntityFlag[static_cast<unsigned char>('&')] = true; _restrictedEntityFlag[static_cast<unsigned char>('<')] = true; _restrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice _buffer.Push( 0 ); } void XMLPrinter::Print( const char* format, ... ) { va_list va; va_start( va, format ); if ( _fp ) { vfprintf( _fp, format, va ); } else { const int len = TIXML_VSCPRINTF( format, va ); // Close out and re-start the va-args va_end( va ); TIXMLASSERT( len >= 0 ); va_start( va, format ); TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 ); char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator. TIXML_VSNPRINTF( p, len+1, format, va ); } va_end( va ); } void XMLPrinter::Write( const char* data, size_t size ) { if ( _fp ) { fwrite ( data , sizeof(char), size, _fp); } else { char* p = _buffer.PushArr( static_cast<int>(size) ) - 1; // back up over the null terminator. memcpy( p, data, size ); p[size] = 0; } } void XMLPrinter::Putc( char ch ) { if ( _fp ) { fputc ( ch, _fp); } else { char* p = _buffer.PushArr( sizeof(char) ) - 1; // back up over the null terminator. p[0] = ch; p[1] = 0; } } void XMLPrinter::PrintSpace( int depth ) { for( int i=0; i<depth; ++i ) { Write( " " ); } } void XMLPrinter::PrintString( const char* p, bool restricted ) { // Look for runs of bytes between entities to print. const char* q = p; if ( _processEntities ) { const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag; while ( *q ) { TIXMLASSERT( p <= q ); // Remember, char is sometimes signed. (How many times has that bitten me?) if ( *q > 0 && *q < ENTITY_RANGE ) { // Check for entities. If one is found, flush // the stream up until the entity, write the // entity, and keep looking. if ( flag[static_cast<unsigned char>(*q)] ) { while ( p < q ) { const size_t delta = q - p; const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta); Write( p, toPrint ); p += toPrint; } bool entityPatternPrinted = false; for( int i=0; i<NUM_ENTITIES; ++i ) { if ( entities[i].value == *q ) { Putc( '&' ); Write( entities[i].pattern, entities[i].length ); Putc( ';' ); entityPatternPrinted = true; break; } } if ( !entityPatternPrinted ) { // TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release TIXMLASSERT( false ); } ++p; } } ++q; TIXMLASSERT( p <= q ); } // Flush the remaining string. This will be the entire // string if an entity wasn't found. if ( p < q ) { const size_t delta = q - p; const int toPrint = ( INT_MAX < delta ) ? INT_MAX : static_cast<int>(delta); Write( p, toPrint ); } } else { Write( p ); } } void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) { if ( writeBOM ) { static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 }; Write( reinterpret_cast< const char* >( bom ) ); } if ( writeDec ) { PushDeclaration( "xml version=\"1.0\"" ); } } void XMLPrinter::PrepareForNewNode( bool compactMode ) { SealElementIfJustOpened(); if ( compactMode ) { return; } if ( _firstElement ) { PrintSpace (_depth); } else if ( _textDepth < 0) { Putc( '\n' ); PrintSpace( _depth ); } _firstElement = false; } void XMLPrinter::OpenElement( const char* name, bool compactMode ) { PrepareForNewNode( compactMode ); _stack.Push( name ); Write ( "<" ); Write ( name ); _elementJustOpened = true; ++_depth; } void XMLPrinter::PushAttribute( const char* name, const char* value ) { TIXMLASSERT( _elementJustOpened ); Putc ( ' ' ); Write( name ); Write( "=\"" ); PrintString( value, false ); Putc ( '\"' ); } void XMLPrinter::PushAttribute( const char* name, int v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } void XMLPrinter::PushAttribute( const char* name, unsigned v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } void XMLPrinter::PushAttribute(const char* name, int64_t v) { char buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } void XMLPrinter::PushAttribute(const char* name, uint64_t v) { char buf[BUF_SIZE]; XMLUtil::ToStr(v, buf, BUF_SIZE); PushAttribute(name, buf); } void XMLPrinter::PushAttribute( const char* name, bool v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } void XMLPrinter::PushAttribute( const char* name, double v ) { char buf[BUF_SIZE]; XMLUtil::ToStr( v, buf, BUF_SIZE ); PushAttribute( name, buf ); } void XMLPrinter::CloseElement( bool compactMode ) { --_depth; const char* name = _stack.Pop(); if ( _elementJustOpened ) { Write( "/>" ); } else { if ( _textDepth < 0 && !compactMode) { Putc( '\n' ); PrintSpace( _depth ); } Write ( "</" ); Write ( name ); Write ( ">" ); } if ( _textDepth == _depth ) { _textDepth = -1; } if ( _depth == 0 && !compactMode) { Putc( '\n' ); } _elementJustOpened = false; } void XMLPrinter::SealElementIfJustOpened() { if ( !_elementJustOpened ) { return; } _elementJustOpened = false; Putc( '>' ); } void XMLPrinter::PushText( const char* text, bool cdata ) { _textDepth = _depth-1; SealElementIfJustOpened(); if ( cdata ) { Write( "<![CDATA[" ); Write( text ); Write( "]]>" ); } else { PrintString( text, true ); } } void XMLPrinter::PushText( int64_t value ) { char buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushText( uint64_t value ) { char buf[BUF_SIZE]; XMLUtil::ToStr(value, buf, BUF_SIZE); PushText(buf, false); } void XMLPrinter::PushText( int value ) { char buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushText( unsigned value ) { char buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushText( bool value ) { char buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushText( float value ) { char buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushText( double value ) { char buf[BUF_SIZE]; XMLUtil::ToStr( value, buf, BUF_SIZE ); PushText( buf, false ); } void XMLPrinter::PushComment( const char* comment ) { PrepareForNewNode( _compactMode ); Write( "<!--" ); Write( comment ); Write( "-->" ); } void XMLPrinter::PushDeclaration( const char* value ) { PrepareForNewNode( _compactMode ); Write( "<?" ); Write( value ); Write( "?>" ); } void XMLPrinter::PushUnknown( const char* value ) { PrepareForNewNode( _compactMode ); Write( "<!" ); Write( value ); Putc( '>' ); } bool XMLPrinter::VisitEnter( const XMLDocument& doc ) { _processEntities = doc.ProcessEntities(); if ( doc.HasBOM() ) { PushHeader( true, false ); } return true; } bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) { const XMLElement* parentElem = 0; if ( element.Parent() ) { parentElem = element.Parent()->ToElement(); } const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode; OpenElement( element.Name(), compactMode ); while ( attribute ) { PushAttribute( attribute->Name(), attribute->Value() ); attribute = attribute->Next(); } return true; } bool XMLPrinter::VisitExit( const XMLElement& element ) { CloseElement( CompactMode(element) ); return true; } bool XMLPrinter::Visit( const XMLText& text ) { PushText( text.Value(), text.CData() ); return true; } bool XMLPrinter::Visit( const XMLComment& comment ) { PushComment( comment.Value() ); return true; } bool XMLPrinter::Visit( const XMLDeclaration& declaration ) { PushDeclaration( declaration.Value() ); return true; } bool XMLPrinter::Visit( const XMLUnknown& unknown ) { PushUnknown( unknown.Value() ); return true; } } // namespace tinyxml2
75,034
C++
24.06179
140
0.559013
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiData.cpp
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <pxr/base/plug/plugin.h> #include <pxr/base/plug/registry.h> #include <pxr/base/tf/token.h> #include <pxr/usd/sdf/schema.h> #include "mpcdiData.h" #include "mpcdiDataProviderFactory.h" #include "mpcdiPluginManager.h" #include <iostream> PXR_NAMESPACE_OPEN_SCOPE static const SdfPath ROOT_PATH("/"); static const SdfPath DATA_ROOT_PATH("/Data"); TF_DEFINE_PUBLIC_TOKENS( EdfDataParametersTokens, // plugin metadata to specify an id for a specific data provider (dataProviderId) // plugin metadata describing the arguments for the provider to use // to load the layer (providerArgs) ); EdfDataParameters EdfDataParameters::FromFileFormatArgs(const SdfFileFormat::FileFormatArguments& args) { EdfDataParameters parameters; parameters.dataProviderId = *(TfMapLookupPtr(args, EdfDataParametersTokens->dataProviderId)); // unpack the file format argument representation of the provider arguments std::string prefix = EdfDataParametersTokens->providerArgs.GetString() + ":"; size_t prefixLength = prefix.length(); for (SdfFileFormat::FileFormatArguments::const_iterator it = args.begin(); it != args.end(); it++) { size_t index = it->first.find(prefix); if (index == 0) { // this is an unpacked prefixed provider argument parameters.providerArgs[it->first.substr(prefixLength)] = it->second; } } return parameters; } EdfSourceData::EdfSourceData(EdfData* data) { this->_data = data; } EdfSourceData::~EdfSourceData() { this->_data = nullptr; } void EdfSourceData::CreatePrim(const SdfPath& parentPath, const std::string& name, const SdfSpecifier& specifier, const TfToken& typeName) { if (this->_data != nullptr) { this->_data->_CreatePrim(parentPath, name, specifier, typeName); } } void EdfSourceData::CreateAttribute(const SdfPath& parentPrimPath, const std::string& name, const SdfValueTypeName& typeName, const SdfVariability& variability, const VtValue& value) { if (this->_data != nullptr) { this->_data->_CreateAttribute(parentPrimPath, name, typeName, variability, value); } } void EdfSourceData::SetField(const SdfPath& primPath, const TfToken& fieldName, const VtValue& value) { if (this->_data != nullptr) { this->_data->_SetFieldValue(primPath, fieldName, value); } } bool EdfSourceData::HasField(const SdfPath& primPath, const TfToken& fieldName, VtValue* value) { if (this ->_data != nullptr) { return this->_data->Has(primPath, fieldName, value); } return false; } bool EdfSourceData::HasAttribute(const SdfPath& attributePath, VtValue* defaultValue) { if (this->_data != nullptr) { return this->_data->Has(attributePath, SdfFieldKeys->Default, defaultValue); } return false; } EdfData::EdfData(std::unique_ptr<IEdfDataProvider> dataProvider) { this->_dataProvider = std::move(dataProvider); this->_sourceData = std::make_shared<EdfSourceData>(this); } EdfDataRefPtr EdfData::CreateFromParameters(const EdfDataParameters& parameters) { std::unique_ptr<IEdfDataProvider> dataProvider = MPCDIPluginManager::GetInstance().CreateDataProvider(parameters.dataProviderId, parameters); if (dataProvider == nullptr) { // there was no provider responsible for this data or it didn't load properly, // so the best we can do is provide an empty EdfData object with no backing provider // this will load nothing except an empty default Root prim return TfCreateRefPtr(new EdfData(nullptr)); } return TfCreateRefPtr(new EdfData(std::move(dataProvider))); } void EdfData::CreateSpec(const SdfPath& path, SdfSpecType specType) { // not supported in this PoC // the data provider can create new prim / property specs // via the callbacks, but the external public API cannot // but if it were, here's how it would be // done concurrently /* this->_CreateSpec(path, specType); */ } void EdfData::Erase(const SdfPath& path, const TfToken& fieldName) { // not supported in this PoC // but if it were, here's how it would be // done concurrently /* SpecData::accessor accessor; if (_specData.find(accessor, path)) { _SpecData& spec = accessor->second; size_t fieldSize = spec.fields.size(); for (size_t i = 0; i < fieldSize; i++) { if (spec.fields[i].first == fieldName) { spec.fields.erase(spec.fields.begin() + i); accessor.release(); return; } } } accessor.release(); */ } void EdfData::EraseSpec(const SdfPath& path) { // not supported in this PoC // but it it were, here's how we'd do it // with the concurrent hash /* SpecData::const_accessor accessor; if (_specData.find(accessor, path)) { _specData.erase(accessor); } accessor.release(); */ } VtValue EdfData::Get(const SdfPath& path, const TfToken& fieldName) const { VtValue val; this->Has(path, fieldName, &val); return val; } SdfSpecType EdfData::GetSpecType(const SdfPath& path) const { // in all cases we either have the spec data available // because we created e.g. the root on Read // or because the data provider created // prims / properties when it performed its Read // or we don't know SpecData::const_accessor accessor; if (_specData.find(accessor, path)) { return accessor->second.specType; } accessor.release(); return SdfSpecType::SdfSpecTypeUnknown; } bool EdfData::Has(const SdfPath& path, const TfToken& fieldName, SdfAbstractDataValue* value) const { if (value != nullptr) { VtValue val; if (this->Has(path, fieldName, &val)) { return value->StoreValue(val); } } else { VtValue val; return this->Has(path, fieldName, &val); } return false; } bool EdfData::Has(const SdfPath& path, const TfToken& fieldName, VtValue* value) const { // in general, we can just get the value for whatever is being asked for // from the hash (and know whether it was there or not) // children are a special case, because those we want to ask the back-end // provider to load - one tricky bit is understanding when we want the data provider // to load and when we want to use the cached value // as a general rule, if SdfChildrenKeys isn't present in the list of fields // for the prim, but we have the prim, we need to ask the data provider to load // for simplicity sake, this is a one-time load -> the data provider will use // the callbacks to insert the children prims / attributes // if we asked the data provider to load the children, and after that the field // still isn't present, then we insert the field with an empty list since // the provider never created any children (maybe the back-end query returned nothing) std::cout << path.GetAsString() << " " << fieldName.GetString() << std::endl; bool hasValue = this->_GetFieldValue(path, fieldName, value); if (!hasValue && fieldName == SdfChildrenKeys->PrimChildren && this->_dataProvider != nullptr) { // give the data provider an opportunity to load their children this->_dataProvider->ReadChildren(path.GetAsString(), this->_sourceData); // after the read call, we check again to see if it's present hasValue = this->_GetFieldValue(path, fieldName, value); if (!hasValue) { // if it still doesn't exist, we assume that there were no children // and we cache that fact now TfTokenVector primChildren; VtValue primChildrenValue(primChildren); this->_SetFieldValue(path, SdfChildrenKeys->PrimChildren, primChildrenValue); if(value != nullptr) { *value = primChildrenValue; } hasValue = true; } } return hasValue; } bool EdfData::HasSpec(const SdfPath& path) const { return this->GetSpecType(path) != SdfSpecType::SdfSpecTypeUnknown; } bool EdfData::IsEmpty() const { return false; } std::vector<TfToken> EdfData::List(const SdfPath& path) const { TfTokenVector names; SpecData::const_accessor accessor; if (_specData.find(accessor, path)) { size_t numFields = accessor->second.fields.size(); names.resize(numFields); for (size_t i = 0; i < numFields; i++) { names[i] = accessor->second.fields[i].first; } } accessor.release(); return names; } void EdfData::MoveSpec(const SdfPath& oldPath, const SdfPath& newPath) { // not supported in this PoC // but it it were, here's how we'd do it // with the concurrent hash /* SpecData::accessor accessor; if (_specData.find(accessor, path)) { SpecData::accessor writeAccessor; _specData.insert(writeAccessor, newPath); writeAccessor->second = accessor->second; writeAccessor.release(); _specData.erase(accessor); } accessor.release(); */ } void EdfData::Set(const SdfPath& path, const TfToken& fieldName, const VtValue& value) { // not supported in this PoC // but it it were, here's how we'd do it // with the concurrent hash /* this->_SetFieldValue(path, fieldName, value); */ } void EdfData::Set(const SdfPath& path, const TfToken& fieldName, const SdfAbstractDataConstValue& value) { // not supported in this PoC // but it it were, here's how we'd do it // with the concurrent hash /* VtValue wrappedValue; value.GetValue(&wrappedValue); this->_SetFieldValue(path, fieldName, wrappedValue); */ } bool EdfData::StreamsData() const { // by default, we assume the backing provider will stream data // but it will tell us whether it has cached that data or not later return true; } bool EdfData::IsDetached() const { if (this->_dataProvider != nullptr) { return this->_dataProvider->IsDataCached(); } else { return SdfAbstractData::IsDetached(); } } std::set<double> EdfData::ListAllTimeSamples() const { // not supported in this POC return std::set<double>(); } std::set<double> EdfData::ListTimeSamplesForPath(const SdfPath& path) const { // not supported in this POC return std::set<double>(); } bool EdfData::GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const { // not supported in this POC return false; } size_t EdfData::GetNumTimeSamplesForPath(const SdfPath& path) const { // not supported in this POC return 0; } bool EdfData::GetBracketingTimeSamplesForPath(const SdfPath& path, double time, double* tLower, double* tUpper) const { // not supported in this POC return false; } bool EdfData::QueryTimeSample(const SdfPath& path, double time, VtValue* optionalValue) const { // not supported in this POC return false; } bool EdfData::QueryTimeSample(const SdfPath& path, double time, SdfAbstractDataValue* optionalValue) const { // not supported in this POC return false; } void EdfData::SetTimeSample(const SdfPath& path, double time, const VtValue& value) { // not supported in this POC } void EdfData::EraseTimeSample(const SdfPath& path, double time) { // not supported in this POC } void EdfData::_VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const { // not supported in this POC } bool EdfData::Read() { // on first read, create the specs for the absolute root path and // for the /Data path where the provider will root their data SpecData::accessor accessor; _specData.insert(accessor, SdfPath::AbsoluteRootPath()); accessor->second.specType = SdfSpecType::SdfSpecTypePseudoRoot; accessor.release(); // insert known field names for the root path // this includes at minimum: // SdfFieldKeys->DefaultPrim // SdfChildrenKeys->PrimChildren TfTokenVector rootChildren({DATA_ROOT_PATH.GetNameToken()}); VtValue primChildrenValue(rootChildren); VtValue defaultPrimValue(DATA_ROOT_PATH.GetNameToken()); this->_SetFieldValue(ROOT_PATH, SdfChildrenKeys->PrimChildren, primChildrenValue); this->_SetFieldValue(ROOT_PATH, SdfFieldKeys->DefaultPrim, defaultPrimValue); // insert the data root path _specData.insert(accessor, DATA_ROOT_PATH); accessor->second.specType = SdfSpecType::SdfSpecTypePrim; accessor.release(); // insert known field names for the data root path // this includes at minimum: // SdfFieldKeys->Specifier // SdfFieldKeys->TypeName // SdfFieldKeys->PrimChildren // SdfFieldKeys->PropertyChildren // prim children is loaded on demand during both deferred // and non-deferred reads, so we don't set it here TfTokenVector dataRootPropertyChildren; VtValue specifierValue(SdfSpecifier::SdfSpecifierDef); VtValue typeNameValue; VtValue dataRootPropertyChildrenValue(dataRootPropertyChildren); this->_SetFieldValue(DATA_ROOT_PATH, SdfFieldKeys->Specifier, specifierValue); this->_SetFieldValue(DATA_ROOT_PATH, SdfFieldKeys->TypeName, typeNameValue); this->_SetFieldValue(DATA_ROOT_PATH, SdfChildrenKeys->PropertyChildren, dataRootPropertyChildrenValue); // if we have a valid provider, ask it to read it's data based on what parameters // it was initialized with, otherwise just return true because we only have an empty // root in the default implementation bool readResult = true; if (this->_dataProvider != nullptr) { readResult = this->_dataProvider->Read(this->_sourceData); } return readResult; } void EdfData::_CreatePrim(const SdfPath& parentPath, const std::string& name, const SdfSpecifier& specifier, const TfToken& typeName) { SdfPath primPath = SdfPath(parentPath.GetAsString() + "/" + name); this->_CreateSpec(primPath, SdfSpecType::SdfSpecTypePrim); this->_SetFieldValue(primPath, SdfFieldKeys->TypeName, VtValue(typeName)); this->_SetFieldValue(primPath, SdfFieldKeys->Specifier, VtValue(specifier)); // add this prim to the PrimChildren property of parentPath VtValue existingPrimChildrenValue; if (this->_GetFieldValue(parentPath, SdfChildrenKeys->PrimChildren, &existingPrimChildrenValue)) { // there are already children present, so append to the list TfTokenVector existingChildren = existingPrimChildrenValue.UncheckedGet<TfTokenVector>(); existingChildren.push_back(TfToken(name)); // set the value back this->_SetFieldValue(parentPath, SdfChildrenKeys->PrimChildren, VtValue(existingChildren)); } else { // no children present yet TfTokenVector children; children.push_back(TfToken(name)); this->_SetFieldValue(parentPath, SdfChildrenKeys->PrimChildren, VtValue(children)); } } void EdfData::_CreateAttribute(const SdfPath& primPath, const std::string& name, const SdfValueTypeName& typeName, const SdfVariability& variability, const VtValue& value) { // creating an attribute means setting the attribute path // which is a combination of the prim path and the attribute name // the type name field key of the attribute // the variability field key of the attribute // and a default field key holding its value SdfPath attributePath = SdfPath(primPath.GetAsString() + "." + name); this->_CreateSpec(attributePath, SdfSpecType::SdfSpecTypeAttribute); this->_SetFieldValue(attributePath, SdfFieldKeys->TypeName, VtValue(typeName)); this->_SetFieldValue(attributePath, SdfFieldKeys->Variability, VtValue(variability)); this->_SetFieldValue(attributePath, SdfFieldKeys->Default, value); // add this attribute to PropertyChildren of primPath VtValue existingPropertyChildrenValue; if (this->_GetFieldValue(primPath, SdfChildrenKeys->PropertyChildren, &existingPropertyChildrenValue)) { // there are already children present, so append to the list TfTokenVector existingChildren = existingPropertyChildrenValue.UncheckedGet<TfTokenVector>(); existingChildren.push_back(TfToken(name)); // set the value back this->_SetFieldValue(primPath, SdfChildrenKeys->PropertyChildren, VtValue(existingChildren)); } else { // no children present yet TfTokenVector children; children.push_back(TfToken(name)); this->_SetFieldValue(primPath, SdfChildrenKeys->PropertyChildren, VtValue(children)); } } void EdfData::_CreateSpec(const SdfPath& path, const SdfSpecType& specType) { SpecData::accessor accessor; if (_specData.find(accessor, path)) { accessor->second.specType = specType; } else { _specData.insert(accessor, path); accessor->second.specType = specType; } accessor.release(); } bool EdfData::_GetSpecTypeAndFieldValue(const SdfPath& path, const TfToken& fieldName, SdfSpecType* specType, VtValue* value) const { // specType and value can be nullptrs here - this just means // we want to know if we have the field at all for a possible // subsequent call in the future if (specType != nullptr) { *specType = SdfSpecTypeUnknown; } SpecData::const_accessor accessor; if (_specData.find(accessor, path)) { const _SpecData &spec = accessor->second; if (specType != nullptr) { *specType = spec.specType; } for (auto const& f: spec.fields) { if (f.first == fieldName) { // copy so that we don't give // back a direct pointer to a released // accessor if (value != nullptr) { *value = value; } accessor.release(); return true; } } } accessor.release(); return false; } bool EdfData::_GetFieldValue(const SdfPath& path, const TfToken& fieldName, VtValue* value) const { // value can be a nullptr here - this just means // we want to know if we have the field at all for a // possible subsequent call in the future SpecData::const_accessor accessor; if (_specData.find(accessor, path)) { const _SpecData &spec = accessor->second; for (auto const& f: spec.fields) { if (f.first == fieldName) { // copy so that we don't give // back a direct pointer to a released // accessor if (value != nullptr) { *value = f.second; } accessor.release(); return true; } } } accessor.release(); return false; } void EdfData::_SetFieldValue(const SdfPath& path, const TfToken& fieldName, const VtValue& value) { // NOTE: if we ever wanted to add support for querying whether // the backend data provider could support writes, we should // query that here and ask them to write to their backing data store SpecData::accessor accessor; if (_specData.find(accessor, path)) { _SpecData& spec = accessor->second; for (auto &f: spec.fields) { if (f.first == fieldName) { f.second = value; accessor.release(); return; } } // if we get here, we didn't have the field yet so create it spec.fields.emplace_back(std::piecewise_construct, std::forward_as_tuple(fieldName), std::forward_as_tuple()); spec.fields.back().second = value; accessor.release(); return; } accessor.release(); } void EdfData::_SetFieldValue(const SdfPath& path, const TfToken& fieldName, const VtValue& value) const { // NOTE: if we ever wanted to add support for querying whether // the backend data provider could support writes, we should // query that here and ask them to write to their backing data store SpecData::accessor accessor; if (_specData.find(accessor, path)) { _SpecData& spec = accessor->second; for (auto& f : spec.fields) { if (f.first == fieldName) { f.second = value; accessor.release(); return; } } // if we get here, we didn't have the field yet so create it spec.fields.emplace_back(std::piecewise_construct, std::forward_as_tuple(fieldName), std::forward_as_tuple()); spec.fields.back().second = value; accessor.release(); return; } accessor.release(); } PXR_NAMESPACE_CLOSE_SCOPE
20,789
C++
28.240506
142
0.68416
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiFileFormat.cpp
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "mpcdiFileFormat.h" #include "tinyxml2.h" #include <pxr/pxr.h> #include <pxr/base/tf/diagnostic.h> #include <pxr/base/tf/stringUtils.h> #include <pxr/base/tf/token.h> #include <pxr/usd/usd/prim.h> #include <pxr/usd/usd/stage.h> #include <pxr/usd/usd/usdaFileFormat.h> #include <pxr/usd/usdGeom/mesh.h> #include <pxr/usd/usdGeom/scope.h> #include <pxr/usd/usdGeom/camera.h> #include <pxr/usd/usdGeom/cube.h> #include <pxr/usd/usdGeom/xformable.h> #include <pxr/usd/usdGeom/xform.h> #include <pxr/usd/usdLux/rectLight.h> #include <pxr/base/gf/matrix3f.h> #include <pxr/base/gf/vec3f.h> #include <fstream> #include <cmath> PXR_NAMESPACE_OPEN_SCOPE MpcdiFileFormat::MpcdiFileFormat() : SdfFileFormat( MpcdiFileFormatTokens->Id, MpcdiFileFormatTokens->Version, MpcdiFileFormatTokens->Target, MpcdiFileFormatTokens->Extension) { } MpcdiFileFormat::~MpcdiFileFormat() { } static const double defaultSideLengthValue = 1.0; static double _ExtractSideLengthFromContext(const PcpDynamicFileFormatContext& context) { // Default sideLength. double sideLength = defaultSideLengthValue; VtValue value; if (!context.ComposeValue(MpcdiFileFormatTokens->SideLength, &value) || value.IsEmpty()) { return sideLength; } if (!value.IsHolding<double>()) { return sideLength; } return value.UncheckedGet<double>(); } static double _ExtractSideLengthFromArgs(const SdfFileFormat::FileFormatArguments& args) { // Default sideLength. double sideLength = defaultSideLengthValue; // Find "sideLength" file format argument. auto it = args.find(MpcdiFileFormatTokens->SideLength); if (it == args.end()) { return sideLength; } // Try to convert the string value to the actual output value type. double extractVal; bool success = true; extractVal = TfUnstringify<double>(it->second, &success); if (!success) { return sideLength; } sideLength = extractVal; return sideLength; } bool MpcdiFileFormat::CanRead(const std::string& filePath) const { return true; } static float GetXMLFloat(tinyxml2::XMLElement* node, const std::string key) { return std::stof(node->FirstChildElement(key.c_str())->GetText()); } static std::string CleanNameForUSD(const std::string& name) { std::string cleanedName = name; if(cleanedName.size() == 0) { return "Default"; } if(cleanedName.size() == 1 && !TfIsValidIdentifier(cleanedName)) { // If we have an index as a name, we only need to add _ beforehand. return CleanNameForUSD("_" + cleanedName); } return TfMakeValidIdentifier(cleanedName); } bool MpcdiFileFormat::Read(SdfLayer* layer, const std::string& resolvedPath, bool metadataOnly) const { // these macros emit methods defined in the Pixar namespace // but not properly scoped, so we have to use the namespace // locally here - note this isn't strictly true since we had to open // the namespace scope anyway because the macros won't allow non-Pixar namespaces // to be used because of some auto-generated content // Read file, file exists? const std::ifstream filePath(resolvedPath); if(!filePath.good()) { TF_CODING_ERROR("File doesn't exist with resolved path: " + resolvedPath); return false; } // Read XML file tinyxml2::XMLDocument doc; const tinyxml2::XMLError xmlReadSuccess = doc.LoadFile(resolvedPath.c_str()); if(xmlReadSuccess != 0) { TF_CODING_ERROR("Failed to load xml file: " + resolvedPath); return false; } // Parsing of MPCDI data tinyxml2::XMLElement* rootNode = doc.RootElement(); if(rootNode == nullptr) { TF_CODING_ERROR("XML Root node is null: " + resolvedPath); return false; } // Create a new anonymous layer and wrap a stage around it. SdfLayerRefPtr newLayer = SdfLayer::CreateAnonymous(".usd"); UsdStageRefPtr stage = UsdStage::Open(newLayer); const auto& xformPath = SdfPath("/mpcdi_payload"); auto mpdiScope = UsdGeomXform::Define(stage, xformPath); stage->SetDefaultPrim(mpdiScope.GetPrim()); auto displayNode = rootNode->FirstChildElement("display"); for(auto* buffer = displayNode->FirstChildElement("buffer"); buffer != nullptr; buffer = buffer->NextSiblingElement("buffer")) { const std::string bufferId = std::string(buffer->Attribute("id")); std::string bufferIdentifier = CleanNameForUSD(bufferId); SdfPath bufferPath = xformPath.AppendChild(TfToken(bufferIdentifier)); auto bufferScope = UsdGeomScope::Define(stage, bufferPath); // Get region for(auto* regionNode = buffer->FirstChildElement("region"); regionNode != nullptr; regionNode = regionNode->NextSiblingElement("region")) { const std::string regionId = std::string(regionNode->Attribute("id")); const std::string cleanedRegionId = CleanNameForUSD(regionId); SdfPath regionPath = bufferPath.AppendChild(TfToken(cleanedRegionId)); // Get Frustum auto frustumNode = regionNode->FirstChildElement("frustum"); const auto frustumYaw = GetXMLFloat(frustumNode, "yaw") * -1.0f; const auto frustumPitch = GetXMLFloat(frustumNode, "pitch"); const auto frustumRoll = GetXMLFloat(frustumNode, "roll"); const auto frustumRightAngle = GetXMLFloat(frustumNode, "rightAngle"); const auto frustumLeftAngle = GetXMLFloat(frustumNode, "leftAngle"); const auto frustumUpAngle = GetXMLFloat(frustumNode, "upAngle"); const auto frustumDownAngle = GetXMLFloat(frustumNode, "downAngle"); constexpr const float toRad = 3.14159265358979323846 / 180.0; constexpr const float focalLength = 10.0f; constexpr const float focusDistance = 2000.0f; const float tanRight = std::tan(frustumRightAngle * toRad); const float tanLeft = std::tan(frustumLeftAngle * toRad); const float tanUp = std::tan(frustumUpAngle * toRad); const float tanDown = std::tan(frustumDownAngle * toRad); const float apertureH = (std::abs(tanRight) + std::abs(tanLeft)) * focalLength; const float apertureV = (std::abs(tanUp) + std::abs(tanDown)) * focalLength; const float lightWidth = std::abs(tanRight) + std::abs(tanLeft); const float lightHeight = std::abs(tanUp) + std::abs(tanDown); const float lensShiftH = (tanLeft + tanRight) / (tanLeft - tanRight); const float lensShiftV = (tanUp + tanDown) / (tanUp - tanDown); const float apertureOffsetH = lensShiftH * apertureH / 2.0; const float apertureOffsetV = lensShiftV * apertureV / 2.0; // Coordinate frame const float posScaling = 10.0f; auto coordFrameNode = regionNode->FirstChildElement("coordinateFrame"); const auto posX = GetXMLFloat(coordFrameNode, "posx") * posScaling; const auto posY = GetXMLFloat(coordFrameNode, "posy") * posScaling; const auto posZ = GetXMLFloat(coordFrameNode, "posz") * posScaling; const auto yawX = GetXMLFloat(coordFrameNode, "yawx"); const auto yawY = GetXMLFloat(coordFrameNode, "yawy"); const auto yawZ = GetXMLFloat(coordFrameNode, "yawz"); const auto pitchX = GetXMLFloat(coordFrameNode, "pitchx"); const auto pitchY = GetXMLFloat(coordFrameNode, "pitchy"); const auto pitchZ = GetXMLFloat(coordFrameNode, "pitchz"); const auto rollX = GetXMLFloat(coordFrameNode, "rollx"); const auto rollY = GetXMLFloat(coordFrameNode, "rolly"); const auto rollZ = GetXMLFloat(coordFrameNode, "rollz"); GfMatrix3f sourceToStandard = GfMatrix3f(pitchX, pitchY, pitchZ, yawX, yawY, yawZ, rollX, rollY, rollZ); auto newPosition = sourceToStandard * GfVec3f(posX, posY, posZ); newPosition[1] = -newPosition[1]; newPosition[2] = -newPosition[2]; // Camera UsdGeomCamera camera = UsdGeomCamera::Define(stage, regionPath); // Camera transform auto cameraXform = UsdGeomXformable(camera); auto translateOperation = cameraXform.AddTranslateOp(UsdGeomXformOp::PrecisionFloat); translateOperation.Set<GfVec3f>(newPosition * 10.0); cameraXform.AddRotateYOp().Set(frustumYaw); cameraXform.AddRotateXOp().Set(frustumPitch); cameraXform.AddRotateZOp().Set(frustumRoll); // Set camera attributes camera.GetFocalLengthAttr().Set(focalLength); camera.GetFocusDistanceAttr().Set(focusDistance); camera.GetHorizontalApertureAttr().Set(apertureH); camera.GetHorizontalApertureOffsetAttr().Set(apertureOffsetH); camera.GetVerticalApertureAttr().Set(apertureV); camera.GetVerticalApertureOffsetAttr().Set(apertureOffsetV); // Light SdfPath lightPath = regionPath.AppendChild(TfToken("RectLight")); auto rectLight = UsdLuxRectLight::Define(stage, lightPath); auto lightXform = UsdGeomXformable(rectLight); auto lightTranslateOperation = lightXform.AddTranslateOp(UsdGeomXformOp::PrecisionFloat); rectLight.GetPrim().CreateAttribute( TfToken("isProjector"), SdfValueTypeNames->Bool ).Set(true); rectLight.GetPrim().CreateAttribute( TfToken("exposure"), SdfValueTypeNames->Float ).Set(5.0f); rectLight.GetPrim().CreateAttribute( TfToken("intensity"), SdfValueTypeNames->Float ).Set(15000.0f); rectLight.GetWidthAttr().Set(lightWidth); rectLight.GetHeightAttr().Set(lightHeight); // Projector box SdfPath cubePath = regionPath.AppendChild(TfToken("ProjectorBox")); UsdGeomCube projectorBoxMesh = UsdGeomCube::Define(stage, cubePath); const auto projectorBoxSize = GfVec3f(50, 15, 40); const auto projectorBoxOffset = GfVec3f(0, 0, 42); auto projectorBoxXform = UsdGeomXformable(projectorBoxMesh); projectorBoxXform.AddTranslateOp(UsdGeomXformOp::PrecisionFloat).Set<GfVec3f>(projectorBoxOffset); projectorBoxXform.AddScaleOp(UsdGeomXformOp::PrecisionFloat).Set<GfVec3f>(projectorBoxSize); } } // Copy contents into output layer. layer->TransferContent(newLayer); return true; } bool MpcdiFileFormat::WriteToString(const SdfLayer& layer, std::string* str, const std::string& comment) const { // this POC doesn't support writing return false; } bool MpcdiFileFormat::WriteToStream(const SdfSpecHandle& spec, std::ostream& out, size_t indent) const { // this POC doesn't support writing return false; } /* void MpcdiFileFormat::ComposeFieldsForFileFormatArguments(const std::string& assetPath, const PcpDynamicFileFormatContext& context, FileFormatArguments* args, VtValue* contextDependencyData) const { // Default sideLength. double sideLength = 1.0; VtValue value; if (!context.ComposeValue(MpcdiFileFormatTokens->SideLength, &value) || value.IsEmpty()) { } if (!value.IsHolding<double>()) { // error; } double length; (*args)[MpcdiFileFormatTokens->SideLength] = TfStringify(sideLength); } bool MpcdiFileFormat::CanFieldChangeAffectFileFormatArguments(const TfToken& field, const VtValue& oldValue, const VtValue& newValue, const VtValue& contextDependencyData) const { // Check if the "sideLength" argument changed. double oldLength = oldValue.IsHolding<double>() ? oldValue.UncheckedGet<double>() : 1.0; double newLength = newValue.IsHolding<double>() ? newValue.UncheckedGet<double>() : 1.0; return oldLength != newLength; } */ // these macros emit methods defined in the Pixar namespace // but not properly scoped, so we have to use the namespace // locally here TF_DEFINE_PUBLIC_TOKENS( MpcdiFileFormatTokens, ((Id, "mpcdiFileFormat")) ((Version, "1.0")) ((Target, "usd")) ((Extension, "xml")) ((SideLength, "Usd_Triangle_SideLength")) ); TF_REGISTRY_FUNCTION(TfType) { SDF_DEFINE_FILE_FORMAT(MpcdiFileFormat, SdfFileFormat); } PXR_NAMESPACE_CLOSE_SCOPE
12,291
C++
32.493188
196
0.717842
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiFileFormat.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_MPCDI_MPCDIFILEFORMAT_H_ #define OMNI_MPCDI_MPCDIFILEFORMAT_H_ #define NOMINMAX #include <pxr/base/tf/staticTokens.h> #include <pxr/pxr.h> #include <pxr/base/tf/token.h> #include <pxr/usd/sdf/fileFormat.h> #include <pxr/usd/sdf/layer.h> #include <pxr/usd/pcp/dynamicFileFormatInterface.h> #include <pxr/usd/pcp/dynamicFileFormatContext.h> #include "api.h" PXR_NAMESPACE_OPEN_SCOPE /// \class EdfFileFormat /// /// Represents a generic dynamic file format for external data. /// Actual acquisition of the external data is done via a set /// of plug-ins to various back-end external data systems. /// class MPCDI_API MpcdiFileFormat : public SdfFileFormat { public: // SdfFileFormat overrides bool CanRead(const std::string& filePath) const override; bool Read(SdfLayer* layer, const std::string& resolvedPath, bool metadataOnly) const override; bool WriteToString(const SdfLayer& layer, std::string* str, const std::string& comment = std::string()) const override; bool WriteToStream(const SdfSpecHandle& spec, std::ostream& out, size_t indent) const override; // PcpDynamicFileFormatInterface overrides //void ComposeFieldsForFileFormatArguments(const std::string& assetPath, const PcpDynamicFileFormatContext& context, FileFormatArguments* args, VtValue* contextDependencyData) const override; //bool CanFieldChangeAffectFileFormatArguments(const TfToken& field, const VtValue& oldValue, const VtValue& newValue, const VtValue& contextDependencyData) const override; protected: SDF_FILE_FORMAT_FACTORY_ACCESS; virtual ~MpcdiFileFormat(); MpcdiFileFormat(); }; TF_DECLARE_PUBLIC_TOKENS( MpcdiFileFormatTokens, ((Id, "mpcdiFileFormat")) ((Version, "1.0")) ((Target, "usd")) ((Extension, "xml")) ((SideLength, "Usd_Triangle_SideLength")) ); TF_DECLARE_WEAK_AND_REF_PTRS(MpcdiFileFormat); PXR_NAMESPACE_CLOSE_SCOPE #endif
2,459
C
32.69863
192
0.764538
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiPluginManager.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_MPCDI_MPCDIPLUGINMANAGER_H_ #define OMNI_MPCDI_MPCDIPLUGINMANAGER_H_ #include <string> #include <unordered_map> #include <pxr/pxr.h> #include <pxr/base/tf/singleton.h> #include <pxr/base/tf/type.h> #include <pxr/base/plug/plugin.h> #include "iMpcdiDataProvider.h" PXR_NAMESPACE_OPEN_SCOPE struct _DataProviderInfo { public: PlugPluginPtr plugin; TfType dataProviderType; }; /// \class EdfPluginmanager /// /// Singleton object responsible for managing the different data provider /// plugins registered for use by the EDF file format provider. /// class MPCDIPluginManager { public: static MPCDIPluginManager& GetInstance() { return TfSingleton<MPCDIPluginManager>::GetInstance(); } // prevent copying and assignment MPCDIPluginManager(const MPCDIPluginManager&) = delete; MPCDIPluginManager& operator=(const MPCDIPluginManager&) = delete; std::unique_ptr<IEdfDataProvider> CreateDataProvider(const std::string& dataProviderId, const EdfDataParameters& parameters); private: MPCDIPluginManager(); ~MPCDIPluginManager(); void _GetDataProviders(); friend class TfSingleton<MPCDIPluginManager>; private: bool _pluginsLoaded; std::unordered_map<std::string, _DataProviderInfo> _dataProviderPlugins; }; PXR_NAMESPACE_CLOSE_SCOPE #endif
1,869
C
24.616438
126
0.76886
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiPluginManager.cpp
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <pxr/base/tf/instantiateSingleton.h> #include <pxr/base/plug/registry.h> #include <pxr/base/js/value.h> #include <pxr/base/js/utils.h> #include "mpcdiPluginManager.h" #include "mpcdiDataProviderFactory.h" PXR_NAMESPACE_OPEN_SCOPE TF_INSTANTIATE_SINGLETON(MPCDIPluginManager); TF_DEFINE_PRIVATE_TOKENS( MPCDIDataProviderPlugInTokens, // metadata describing a unique id for the data provider plugin (dataProviderId) ); MPCDIPluginManager::MPCDIPluginManager() { this->_pluginsLoaded = false; } MPCDIPluginManager::~MPCDIPluginManager() { } std::unique_ptr<IEdfDataProvider> MPCDIPluginManager::CreateDataProvider(const std::string& dataProviderId, const EdfDataParameters& parameters) { // load the plugins if not already loaded this->_GetDataProviders(); // attempt to find the plugin responsible for the data provider id const std::unordered_map<std::string, _DataProviderInfo>::iterator it = this->_dataProviderPlugins.find(dataProviderId); if (it == this->_dataProviderPlugins.end()) { TF_CODING_ERROR("Failed to find plugin for %s", dataProviderId.c_str()); return nullptr; } // load the corresponding plugin if not already loaded if (!it->second.plugin->Load()) { TF_CODING_ERROR("Failed to load plugin %s for %s", it->second.plugin->GetName().c_str(), it->second.dataProviderType.GetTypeName().c_str()); return nullptr; } std::unique_ptr<IEdfDataProvider> dataProvider; EdfDataProviderFactoryBase* factory = it->second.dataProviderType.GetFactory<EdfDataProviderFactoryBase>(); if (factory != nullptr) { dataProvider.reset(factory->New(parameters)); } if (dataProvider == nullptr) { TF_CODING_ERROR("Failed to create data provider %s from plugin %s", it->second.dataProviderType.GetTypeName().c_str(), it->second.plugin->GetName().c_str()); } return dataProvider; } void MPCDIPluginManager::_GetDataProviders() { // this uses the standard Pixar plug-in mechansim to load and discover // plug-ins of a certain type if (!this->_pluginsLoaded) { std::set<TfType> dataProviderTypes; PlugRegistry::GetAllDerivedTypes(TfType::Find<IEdfDataProvider>(), &dataProviderTypes); for (const TfType dataProviderType : dataProviderTypes) { // get the plugin for the specified type from the plugin registry const PlugPluginPtr plugin = PlugRegistry::GetInstance().GetPluginForType(dataProviderType); if (plugin == nullptr) { TF_CODING_ERROR("Failed to find plugin for %s", dataProviderType.GetTypeName().c_str()); continue; } std::string dataProviderId; const JsOptionalValue dataProviderIdVal = JsFindValue(plugin->GetMetadataForType(dataProviderType), MPCDIDataProviderPlugInTokens->dataProviderId.GetString()); if (!dataProviderIdVal.has_value() || !dataProviderIdVal->Is<std::string>()) { TF_CODING_ERROR("'%s' metadata for '%s' must be specified!", MPCDIDataProviderPlugInTokens->dataProviderId.GetText(), dataProviderType.GetTypeName().c_str()); continue; } dataProviderId = dataProviderIdVal->GetString(); // store the map between the data provider id and the plugin _DataProviderInfo providerInfo; providerInfo.plugin = plugin; providerInfo.dataProviderType = dataProviderType; this->_dataProviderPlugins[dataProviderId] = providerInfo; } this->_pluginsLoaded = true; } } PXR_NAMESPACE_CLOSE_SCOPE
3,936
C++
32.084033
162
0.748476
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiData.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_EDF_EDFDATA_H_ #define OMNI_EDF_EDFDATA_H_ #include <string> #include <set> #include <pxr/pxr.h> #include <pxr/base/tf/declarePtrs.h> #include <pxr/usd/sdf/abstractData.h> #include <pxr/usd/sdf/fileFormat.h> #include <tbb/concurrent_hash_map.h> #include "iMpcdiDataProvider.h" PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_PUBLIC_TOKENS( EdfDataParametersTokens, (dataProviderId) (providerArgs) ); TF_DECLARE_WEAK_AND_REF_PTRS(EdfData); /// \class EdfSourceData /// /// Serves as a wrapper around EdfData for data providers to populate /// information into. /// class EdfSourceData : public IEdfSourceData { public: EdfSourceData(EdfData* data); virtual ~EdfSourceData(); virtual void CreatePrim(const SdfPath& parentPath, const std::string& name, const SdfSpecifier& specifier, const TfToken& typeName) override; virtual void CreateAttribute(const SdfPath& parentPrimPath, const std::string& name, const SdfValueTypeName& typeName, const SdfVariability& variability, const VtValue& value) override; virtual void SetField(const SdfPath& primPath, const TfToken& fieldName, const VtValue& value) override; virtual bool HasField(const SdfPath& primPath, const TfToken& fieldName, VtValue* value) override; virtual bool HasAttribute(const SdfPath& attributePath, VtValue* defaultValue) override; private: EdfData* _data; }; /// \class EdfData /// /// This class is used to hold the data required to open /// a layer from files of "edf" format. This data is initialized /// by metadata unique to the prim the payload is attached to /// and turned into file format args to create the appropriate /// layer identifier for USD. /// class EdfData : public SdfAbstractData { public: static EdfDataRefPtr CreateFromParameters(const EdfDataParameters& parameters); // SdfAbstractData overrides void CreateSpec(const SdfPath& path, SdfSpecType specType) override; void Erase(const SdfPath& path, const TfToken& fieldName) override; void EraseSpec(const SdfPath& path) override; VtValue Get(const SdfPath& path, const TfToken& fieldName) const override; SdfSpecType GetSpecType(const SdfPath& path) const override; bool Has(const SdfPath& path, const TfToken& fieldName, SdfAbstractDataValue* value) const override; bool Has(const SdfPath& path, const TfToken& fieldName, VtValue* value = nullptr) const override; bool HasSpec(const SdfPath& path) const override; bool IsEmpty() const override; std::vector<TfToken> List(const SdfPath& path) const override; void MoveSpec(const SdfPath& oldPath, const SdfPath& newPath) override; void Set(const SdfPath& path, const TfToken& fieldName, const VtValue& value) override; void Set(const SdfPath& path, const TfToken& fieldName, const SdfAbstractDataConstValue& value) override; bool StreamsData() const override; bool IsDetached() const override; std::set<double> ListAllTimeSamples() const override; std::set<double> ListTimeSamplesForPath(const SdfPath& path) const override; bool GetBracketingTimeSamples(double time, double* tLower, double* tUpper) const override; size_t GetNumTimeSamplesForPath(const SdfPath& path) const override; bool GetBracketingTimeSamplesForPath(const SdfPath& path, double time, double* tLower, double* tUpper) const override; bool QueryTimeSample(const SdfPath& path, double time, VtValue* optionalValue = nullptr) const override; bool QueryTimeSample(const SdfPath& path, double time, SdfAbstractDataValue* optionalValue) const override; void SetTimeSample(const SdfPath& path, double time, const VtValue& value) override; void EraseTimeSample(const SdfPath& path, double time) override; virtual bool Read(); protected: // SdfAbstractDataOverrides void _VisitSpecs(SdfAbstractDataSpecVisitor* visitor) const override; private: friend class EdfSourceData; // can only be constructed via CreateFromParameters EdfData(std::unique_ptr<IEdfDataProvider> dataProvider); // helper methods for retrieving spec properties // modeled after SdfData bool _GetSpecTypeAndFieldValue(const SdfPath& path, const TfToken& fieldName, SdfSpecType* specType, VtValue* value) const; bool _GetFieldValue(const SdfPath& path, const TfToken& fieldName, VtValue* value) const; // helper methods for setting properties for the root // we don't have functionality for the public Set API // but we need to do it internally - if we ever added // support for the set API (i.e. the backend provider // supported writes), we could call this internally void _SetFieldValue(const SdfPath& path, const TfToken& fieldName, const VtValue& value); void _SetFieldValue(const SdfPath& path, const TfToken& fieldName, const VtValue& value) const; void _CreateSpec(const SdfPath& path, const SdfSpecType& specType); // instance methods for callbacks on context void _CreatePrim(const SdfPath& parentPath, const std::string& name, const SdfSpecifier& specifier, const TfToken& typeName); void _CreateAttribute(const SdfPath& primPath, const std::string& name, const SdfValueTypeName& typeName, const SdfVariability& variability, const VtValue& value); private: // holds a pointer to the specific data provider to use // to query back-end data std::unique_ptr<IEdfDataProvider> _dataProvider; // holds a shared pointer to the source data object // used to callback on to create prims / attributes std::shared_ptr<IEdfSourceData> _sourceData; // mimic the storage structure of SdfData, just put it // in a concurrent_hash_map rather than a TfHashMap // the downside here is if we lock one field value for a write // the whole prim gets locked, but for our purposes // here that should be ok - the advantage we get is // that on deferred reads we should be able to multithread // the back-end object acquisition during prim indexing typedef std::pair<TfToken, VtValue> _FieldValuePair; struct _SpecData { _SpecData() : specType(SdfSpecTypeUnknown) {} SdfSpecType specType; std::vector<_FieldValuePair> fields; }; // Hash structure consistent with what TBB expects // but forwarded to what's already in USD struct SdfPathHash { static size_t hash(const SdfPath& path) { return path.GetHash(); } static bool equal(const SdfPath& path1, const SdfPath& path2) { return path1 == path2; } }; typedef tbb::concurrent_hash_map<SdfPath, _SpecData, SdfPathHash> SpecData; mutable SpecData _specData; }; PXR_NAMESPACE_CLOSE_SCOPE #endif
7,126
C
37.317204
119
0.753999
MomentFactory/Omniverse-MPCDI-converter/src/usd-plugins/fileFormat/mpcdiFileFormat/mpcdiDataProviderFactory.cpp
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <pxr/pxr.h> #include "mpcdiDataProviderFactory.h" PXR_NAMESPACE_OPEN_SCOPE EdfDataProviderFactoryBase::~EdfDataProviderFactoryBase() = default; PXR_NAMESPACE_CLOSE_SCOPE
775
C++
32.739129
75
0.766452
MomentFactory/Omniverse-MPCDI-converter/tools/packman/packmanconf.py
# Use this file to bootstrap packman into your Python environment (3.7.x). Simply # add the path by doing sys.insert to where packmanconf.py is located and then execute: # # >>> import packmanconf # >>> packmanconf.init() # # It will use the configured remote(s) and the version of packman in the same folder, # giving you full access to the packman API via the following module # # >> import packmanapi # >> dir(packmanapi) import os import platform import sys def init(): """Call this function to initialize the packman configuration. Calls to the packman API will work after successfully calling this function. Note: This function only needs to be called once during the execution of your program. Calling it repeatedly is harmless but wasteful. Compatibility with your Python interpreter is checked and upon failure the function will report what is required. Example: >>> import packmanconf >>> packmanconf.init() >>> import packmanapi >>> packmanapi.set_verbosity_level(packmanapi.VERBOSITY_HIGH) """ major = sys.version_info[0] minor = sys.version_info[1] if major != 3 or minor != 10: raise RuntimeError( f"This version of packman requires Python 3.10.x, but {major}.{minor} was provided" ) conf_dir = os.path.dirname(os.path.abspath(__file__)) os.environ["PM_INSTALL_PATH"] = conf_dir packages_root = get_packages_root(conf_dir) version = get_version(conf_dir) module_dir = get_module_dir(conf_dir, packages_root, version) sys.path.insert(1, module_dir) def get_packages_root(conf_dir: str) -> str: root = os.getenv("PM_PACKAGES_ROOT") if not root: platform_name = platform.system() if platform_name == "Windows": drive, _ = os.path.splitdrive(conf_dir) root = os.path.join(drive, "packman-repo") elif platform_name == "Darwin": # macOS root = os.path.join( os.path.expanduser("~"), "/Library/Application Support/packman-cache" ) elif platform_name == "Linux": try: cache_root = os.environ["XDG_HOME_CACHE"] except KeyError: cache_root = os.path.join(os.path.expanduser("~"), ".cache") return os.path.join(cache_root, "packman") else: raise RuntimeError(f"Unsupported platform '{platform_name}'") # make sure the path exists: os.makedirs(root, exist_ok=True) return root def get_module_dir(conf_dir, packages_root: str, version: str) -> str: module_dir = os.path.join(packages_root, "packman-common", version) if not os.path.exists(module_dir): import tempfile tf = tempfile.NamedTemporaryFile(delete=False) target_name = tf.name tf.close() url = f"http://bootstrap.packman.nvidia.com/packman-common@{version}.zip" print(f"Downloading '{url}' ...") import urllib.request urllib.request.urlretrieve(url, target_name) from importlib.machinery import SourceFileLoader # import module from path provided script_path = os.path.join(conf_dir, "bootstrap", "install_package.py") ip = SourceFileLoader("install_package", script_path).load_module() print("Unpacking ...") ip.install_package(target_name, module_dir) os.unlink(tf.name) return module_dir def get_version(conf_dir: str): path = os.path.join(conf_dir, "packman") if not os.path.exists(path): # in dev repo fallback path += ".sh" with open(path, "rt", encoding="utf8") as launch_file: for line in launch_file.readlines(): if line.startswith("PM_PACKMAN_VERSION"): _, value = line.split("=") return value.strip() raise RuntimeError(f"Unable to find 'PM_PACKMAN_VERSION' in '{path}'")
3,932
Python
35.416666
95
0.632503
MomentFactory/Omniverse-MPCDI-converter/exts/mf.ov.mpcdi_converter/mf/ov/mpcdi_converter/extension.py
import os import time from typing import List import omni.ext import omni.client import carb import omni.kit.notification_manager as nm from omni.kit.notification_manager import NotificationStatus from omni.kit.menu import utils from omni.kit.tool.asset_importer.file_picker import FilePicker from omni.kit.tool.asset_importer.filebrowser import FileBrowserMode, FileBrowserSelectionType import omni.ui as ui import omni.kit.tool.asset_importer as ai import omni.kit.window.content_browser as content from .omni_client_wrapper import OmniClientWrapper import xml.etree.ElementTree as ET from pxr import UsdGeom, Sdf, Gf, Tf import math import logging class MPCDIConverterContext: usd_reference_path = "" class MPCDIConverterHelper: def __init__(self): pass def _cleanNameForUSD(self, strIn: str) -> str: strOut = strIn # Do not allow for a blank name if len(strOut) == 0: return "Default" elif len(strOut) == 1 and strIn.isnumeric(): # If we have an index as a name, we only need to add _ beforehand. return "_" + strIn return Tf.MakeValidIdentifier(strIn) def _convert_xml_to_usd(self, absolute_path_xml): result = 0 try: _, _, content = omni.client.read_file(absolute_path_xml) data = memoryview(content).tobytes() # Read xml file here root = ET.fromstring(data) hasLensShifting = False stage = omni.usd.get_context().get_stage() mpcdiId = "/MPCDI" stage.DefinePrim(mpcdiId, "Xform") # Create usd content here for display in root: if display.tag != 'display': continue for buffer in display: bufferId = buffer.attrib['id'] bufferPath = mpcdiId + '/' + self._cleanNameForUSD(bufferId) stage.DefinePrim(bufferPath, "Scope") # A region is a projector for region in buffer: # GetCoordFrams coordinateFrame = region.find('coordinateFrame') # Get Position posX = float(coordinateFrame.find('posx').text) * 10 posY = float(coordinateFrame.find('posy').text) * 10 posZ = float(coordinateFrame.find('posz').text) * 10 # Get Axis up upX = float(coordinateFrame.find('yawx').text) upY = float(coordinateFrame.find('yawy').text) upZ = float(coordinateFrame.find('yawz').text) # Get Axis right rightX = float(coordinateFrame.find('pitchx').text) rightY = float(coordinateFrame.find('pitchy').text) rightZ = float(coordinateFrame.find('pitchz').text) # Get Axis down forwardX = float(coordinateFrame.find('rollx').text) forwardY = float(coordinateFrame.find('rolly').text) forwardZ = float(coordinateFrame.find('rollz').text) # The "coordinateFrame" provided in the MPCDI comes with three vectors to solve any coordinate # system ambiguity we meed to convert the position from the "source" coordinate system to the # standard MPCDI system And then convert from the standard to the Omniverse system sourceToStandard = Gf.Matrix3f( rightX, rightY, rightZ, upX, upY, upZ, forwardX, forwardY, forwardZ) # Omniverse uses the same axis for Roll/Pitch/Yaw than the standard, so we have a diagonal matrix # BUT the Y and Z axis are pointing to the opposite direction, so we need to invert them # in the matrix. Here we'll avoid a second matrix product and simply invert Y and Z of the # vector instead. newPos = sourceToStandard * Gf.Vec3f(posX, posY, posZ) newPos[1] = newPos[1] * -1.0 newPos[2] = newPos[2] * -1.0 frustum = region.find('frustum') yaw = float(frustum.find('yaw').text) * -1 pitch = float(frustum.find('pitch').text) roll = float(frustum.find('roll').text) # For the moment we do not support lens shifting, so we simply add the two angles and assume # They are the same on both sides of the angle. fovRight = float(frustum.find('rightAngle').text) fovLeft = float(frustum.find('leftAngle').text) fovTop = float(frustum.find('upAngle').text) fovBottom = float(frustum.find('downAngle').text) focalLength = 10 # We chose a fixed focal length. tanRight = math.tan(math.radians(fovRight)) tanLeft = math.tan(math.radians(fovLeft)) tanUp = math.tan(math.radians(fovTop)) tanDown = math.tan(math.radians(fovBottom)) apertureH = (abs(tanRight) + abs(tanLeft)) * focalLength apertureV = (abs(tanUp) + abs(tanDown)) * focalLength lightWidth = abs(tanRight) + abs(tanLeft) lightHeight = abs(tanUp) + abs(tanDown) horizLensShiftAmount = (tanLeft + tanRight) / (tanLeft - tanRight) vertLensShiftAmount = (tanUp + tanDown) / (tanUp - tanDown) horizApertureOffset = horizLensShiftAmount * apertureH / 2.0 vertApertureOffset = vertLensShiftAmount * apertureV / 2.0 if fovRight != fovLeft or fovTop != fovBottom: hasLensShifting = True regionId = region.attrib['id'] primPath = bufferPath + '/' + self._cleanNameForUSD(regionId) prim = stage.DefinePrim(primPath, "Camera") prim.GetAttribute('focalLength').Set(focalLength) prim.GetAttribute('focusDistance').Set(2000.0) prim.GetAttribute('horizontalAperture').Set(apertureH) prim.GetAttribute('horizontalApertureOffset').Set(horizApertureOffset) prim.GetAttribute('verticalAperture').Set(apertureV) prim.GetAttribute('verticalApertureOffset').Set(vertApertureOffset) primXform = UsdGeom.Xformable(prim) # This prevents from trying to add another Operation if overwritting nodes. primXform.ClearXformOpOrder() primXform.AddTranslateOp().Set(value=(newPos * 10.0)) primXform.AddRotateYOp().Set(value=yaw) primXform.AddRotateXOp().Set(value=pitch) primXform.AddRotateZOp().Set(value=roll) # Create rectLight node rectLightpath = primPath + '/ProjectLight' rectLight = stage.DefinePrim(rectLightpath, 'RectLight') # We need to create those attributes as they are not standard in USD and they are omniverse # Specific. At this point in time Omniverse hasn't added their own attributes. # We simply do it ourselves. rectLight.CreateAttribute('isProjector', Sdf.ValueTypeNames.Bool).Set(True) rectLight.CreateAttribute('intensity', Sdf.ValueTypeNames.Float).Set(15000) rectLight.CreateAttribute('exposure', Sdf.ValueTypeNames.Float).Set(5) rectLight.GetAttribute('inputs:width').Set(lightWidth) rectLight.GetAttribute('inputs:height').Set(lightHeight) # Creating projector box mesh to simulate the space a projector takes in the space projectorBoxPath = primPath + '/ProjectorBox' projector = stage.DefinePrim(projectorBoxPath, 'Cube') projectorXform = UsdGeom.Xformable(projector) projectorXform.ClearXformOpOrder() projectorXform.AddTranslateOp().Set(value=(0, 0, 42.0)) projectorXform.AddScaleOp().Set(value=(50.0, 15, 40.0)) except Exception as e: logger = logging.getLogger(__name__) logger.error(f"Failed to parse MPCDI file. Make sure it is not corrupt. {e}") return -1 if hasLensShifting: message = "Lens shifting detected in MPCDI. Lens shifting is not supported." logger = logging.getLogger(__name__) logger.warn(message) nm.post_notification(message, status=NotificationStatus.WARNING) return result def _create_import_task(self, absolute_path, relative_path, export_folder, _): stage = omni.usd.get_context().get_stage() usd_path = "" # If the stage is not saved save the imported USD next to the original asset. if not stage or stage.GetRootLayer().anonymous: now = time.localtime() ext = time.strftime("_%H%M%S", now) basename = relative_path[:relative_path.rfind(".")] no_folder_name = absolute_path[:absolute_path.find("/" + relative_path)] host_dir = os.path.join(no_folder_name, "convertedAssets", basename + ext).replace("\\", "/") # Save the imported USD next to the saved stage. path_out = omni.usd.get_context().get_stage_url() # If user makes a selection for the output folder use it. if export_folder is not None: path_out = export_folder path_out_index = path_out.rfind("/") success = self._convert_xml_to_usd(absolute_path) # self._hi.convert_cad_file_to_usd(absolute_path, path_out[:path_out_index]) ext_index = relative_path.rfind(".") relative_path = self._cleanNameForUSD(relative_path[:ext_index]) + ".usd" usd_path = os.path.join(path_out[:path_out_index], relative_path).replace("\\", "/") logger = logging.getLogger(__name__) if success == 0: message = "Import succesful" logger.info(message) nm.post_notification(message) return usd_path elif success == -10002: # TODO this is when we have problem reading the file from OV, might need to download it locally logger.info("NOT IMPLEMENTED: Failure to load model form omniverse server, please select a file from local disk.") nm.post_notification( f"Failed to convert file {os.path.basename(absolute_path)}.\n" "Please check console for more details.", status=nm.NotificationStatus.WARNING, ) return None else: logger.info("IMPORT FAILED") nm.post_notification( f"Failed to convert file {os.path.basename(absolute_path)}.\n" "Please check console for more details.", status=nm.NotificationStatus.WARNING, ) return None async def create_import_task(self, absolute_paths, relative_paths, export_folder, hoops_context): converted_assets = {} for i in range(len(absolute_paths)): converted_assets[absolute_paths[i]] = self._create_import_task(absolute_paths[i], relative_paths[i], export_folder, hoops_context) return converted_assets class MPCDIConverterOptions: def __init__(self): self.cad_converter_context = MPCDIConverterContext() self.export_folder: str = None class MPCDIConverterOptionsBuilder: def __init__(self, usd_context): super().__init__() self._file_picker = None self._usd_context = usd_context self._export_context = MPCDIConverterOptions() self._folder_button = None self._refresh_default_folder = False self._default_folder = None self._clear() def _clear(self): self._built = False self._export_folder_field = None if self._folder_button: self._folder_button.set_clicked_fn(None) self._folder_button = None def set_default_target_folder(self, folder: str): self._default_folder = folder self._refresh_default_folder = True def build_pane(self, asset_paths: List[str]): self._export_context = self.get_import_options() if self._refresh_default_folder: self._export_context.export_folder = self._default_folder self._default_folder = None self._refresh_default_folder = False self._built = True OPTIONS_STYLE = { "Rectangle::hovering": {"background_color": 0x0, "border_radius": 2, "margin": 0, "padding": 0}, "Rectangle::hovering:hovered": {"background_color": 0xFF9E9E9E}, "Button.Image::folder": {"image_url": Icons().get("folder")}, "Button.Image::folder:checked": {"image_url": Icons().get("folder")}, "Button::folder": {"background_color": 0x0, "margin": 0}, "Button::folder:checked": {"background_color": 0x0, "margin": 0}, "Button::folder:pressed": {"background_color": 0x0, "margin": 0}, "Button::folder:hovered": {"background_color": 0x0, "margin": 0}, } with ui.VStack(height=0, style=OPTIONS_STYLE): ui.Spacer(width=0, height=5) with ui.HStack(height=0): ui.Label("Convert To:", width=0) ui.Spacer(width=3) with ui.VStack(height=0): ui.Spacer(height=4) self._export_folder_field = ui.StringField(height=20, width=ui.Fraction(1), read_only=False) self._export_folder_field.set_tooltip( "Left this empty will export USD to the folder that assets are under." ) ui.Spacer(height=4) with ui.VStack(height=0, width=0): ui.Spacer(height=4) with ui.ZStack(width=20, height=20): ui.Rectangle(name="hovering") self._folder_button = ui.Button(name="folder", width=24, height=24) self._folder_button.set_tooltip("Choose folder") ui.Spacer(height=4) ui.Spacer(width=2) self._folder_button.set_clicked_fn(self._show_file_picker) ui.Spacer(width=0, height=10) if self._export_context.export_folder: self._export_folder_field.model.set_value(self._export_context.export_folder) else: self._export_folder_field.model.set_value("") def _select_picked_folder_callback(self, paths): if paths: self._export_folder_field.model.set_value(paths[0]) def _cancel_picked_folder_callback(self): pass def _show_file_picker(self): if not self._file_picker: mode = FileBrowserMode.OPEN file_type = FileBrowserSelectionType.DIRECTORY_ONLY filters = [(".*", "All Files (*.*)")] self._file_picker = FilePicker("Select Folder", mode=mode, file_type=file_type, filter_options=filters) self._file_picker.set_file_selected_fn(self._select_picked_folder_callback) self._file_picker.set_cancel_fn(self._cancel_picked_folder_callback) folder = self._export_folder_field.model.get_value_as_string() if utils.is_folder(folder): self._file_picker.show(folder) else: self._file_picker.show(self._get_current_dir_in_content_window()) def _get_current_dir_in_content_window(self): content_window = content.get_content_window() return content_window.get_current_directory() def get_import_options(self): context = MPCDIConverterOptions() # TODO enable this after the filepicker bugfix: OM-47383 # if self._built: # context.export_folder = str.strip(self._export_folder_field.model.get_value_as_string()) # context.export_folder = context.export_folder.replace("\\", "/") return context def destroy(self): self._clear() if self._file_picker: self._file_picker.destroy() class MPCDIConverterDelegate(ai.AbstractImporterDelegate): def __init__(self, usd_context, name, filters, descriptions): super().__init__() self._hoops_options_builder = MPCDIConverterOptionsBuilder(usd_context) self._hoops_converter = MPCDIConverterHelper() self._name = name self._filters = filters self._descriptions = descriptions def destroy(self): if self._hoops_converter: self._hoops_converter.destroy() self._hoops_converter = None if self._hoops_options_builder: self._hoops_options_builder.destroy() self._hoops_options_builder = None @property def name(self): return self._name @property def filter_regexes(self): return self._filters @property def filter_descriptions(self): return self._descriptions def build_options(self, paths): pass # TODO enable this after the filepicker bugfix: OM-47383 # self._hoops_options_builder.build_pane(paths) async def convert_assets(self, paths): context = self._hoops_options_builder.get_import_options() hoops_context = context.cad_converter_context absolute_paths = [] relative_paths = [] for file_path in paths: if self.is_supported_format(file_path): absolute_paths.append(file_path) filename = os.path.basename(file_path) relative_paths.append(filename) converted_assets = await self._hoops_converter.create_import_task( absolute_paths, relative_paths, context.export_folder, hoops_context ) return converted_assets _global_instance = None # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled # on_shutdown() is called. class MfMpcdiConverterExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): global _global_instance _global_instance = self self._usd_context = omni.usd.get_context() self.delegate_mpcdi = MPCDIConverterDelegate( self._usd_context, "MPCDI Converter", ["(.*\\.mpcdi\\.xml$)"], ["mpcdi XML Files (*.mpdci.xml)"] ) ai.register_importer(self.delegate_mpcdi) def on_shutdown(self): global _global_instance _global_instance = None ai.remove_importer(self.delegate_mpcdi) self.delegate_mpcdi = None
19,870
Python
43.354911
135
0.573125
MomentFactory/Omniverse-MPCDI-converter/exts/mf.ov.mpcdi_converter/mf/ov/mpcdi_converter/__init__.py
import os from pxr import Plug pluginsRoot = os.path.join(os.path.dirname(__file__), '../../../plugin/resources') Plug.Registry().RegisterPlugins(pluginsRoot) from .extension import *
191
Python
20.333331
82
0.706806
MomentFactory/Omniverse-MPCDI-converter/exts/mf.ov.mpcdi_converter/mf/ov/mpcdi_converter/omni_client_wrapper.py
import os import traceback import asyncio import carb import omni.client def _encode_content(content): if type(content) == str: payload = bytes(content.encode("utf-8")) elif type(content) != type(None): payload = bytes(content) else: payload = bytes() return payload class OmniClientWrapper: @staticmethod async def exists(path): try: result, entry = await omni.client.stat_async(path) return result == omni.client.Result.OK except Exception as e: traceback.print_exc() carb.log_error(str(e)) return False @staticmethod def exists_sync(path): try: result, entry = omni.client.stat(path) return result == omni.client.Result.OK except Exception as e: traceback.print_exc() carb.log_error(str(e)) return False @staticmethod async def write(path: str, content): carb.log_info(f"Writing {path}...") try: result = await omni.client.write_file_async(path, _encode_content(content)) if result != omni.client.Result.OK: carb.log_error(f"Cannot write {path}, error code: {result}.") return False except Exception as e: traceback.print_exc() carb.log_error(str(e)) return False finally: carb.log_info(f"Writing {path} done...") return True @staticmethod async def copy(src_path: str, dest_path: str): carb.log_info(f"Coping from {src_path} to {dest_path}...") try: await omni.client.delete_async(dest_path) result = await omni.client.copy_async(src_path, dest_path) if result != omni.client.Result.OK: carb.log_error(f"Cannot copy from {src_path} to {dest_path}, error code: {result}.") return False else: return True except Exception as e: traceback.print_exc() carb.log_error(str(e)) return False @staticmethod async def read(src_path: str): carb.log_info(f"Reading {src_path}...") try: result, version, content = await omni.client.read_file_async(src_path) if result == omni.client.Result.OK: return memoryview(content).tobytes() else: carb.log_error(f"Cannot read {src_path}, error code: {result}.") except Exception as e: traceback.print_exc() carb.log_error(str(e)) finally: carb.log_info(f"Reading {src_path} done...") return None @staticmethod async def create_folder(path): carb.log_info(f"Creating dir {path}...") result = await omni.client.create_folder_async(path) return result == omni.client.Result.OK or result == omni.client.Result.ERROR_ALREADY_EXISTS @staticmethod def create_folder_sync(path): carb.log_info(f"Creating dir {path}...") result = omni.client.create_folder(path) return result == omni.client.Result.OK or result == omni.client.Result.ERROR_ALREADY_EXISTS
3,226
Python
30.637255
100
0.574086
MomentFactory/Omniverse-MPCDI-converter/exts/mf.ov.mpcdi_converter/config/extension.toml
[package] version = "1.1.1" title = "MF MPCDI converter" description="Brings the support of MPCDI videoprojector files." authors = ["Moment Factory","Antoine Pilote"] readme = "docs/README.md" changelog="docs/CHANGELOG.md" repository = "https://github.com/MomentFactory/Omniverse-MPCDI-converter" category = "Simulation" keywords = ["videoprojector", "MPCDI", "audiovisual", "video", "projection", "videomapping"] preview_image = "data/preview.png" icon = "data/mf-ov-extensions-icons.png" toggleable = false [core] reloadable = false # Load at the start, load all schemas with order -100 (with order -1000 the USD libs are loaded) order = -100 [dependencies] "omni.kit.uiapp" = {} "omni.kit.tool.asset_importer" = {} [[python.module]] name = "mf.ov.mpcdi_converter" [package.target] kit = ["105.1"] [package.writeTarget] kit = true python = false
861
TOML
21.102564
96
0.716609
MomentFactory/Omniverse-MPCDI-converter/exts/mf.ov.mpcdi_converter/docs/CHANGELOG.md
# Changelog The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [1.1.1] - 2023-12-02 - Deprecated kit 104 and 105.0 - Monorepo for the USD fileformat plugin - Procedure to build for USDView ## [1.1.0] - 2023-10-04 - Added native USD file format plugin for payload support. ## [1.0.0] - 2023-07-19 ### Added - Compatibility with USD Composer 2023.1.1 ### Changed - More explicit error message when failing to import ## [0.1.0] - 2023-03-30 ### Added - Initial version of Omniverse MPCDI extension
536
Markdown
20.479999
80
0.697761
MomentFactory/Omniverse-MPCDI-converter/exts/mf.ov.mpcdi_converter/docs/README.md
# MPCDI converter for Omniverse [mf.ov.mpcdi_converter] An Omniverse extension for MPDCI files. Support MPCDI* to OpenUSD conversion as well as References to MPDCI files through a native USD FileFormat plugin. MPCDI* is a VESA interchange format for videoprojectors technical data. *Multiple Projection Common Data Interchange MPCDIv2 is under Copyright © 2013 – 2015 Video Electronics Standards Association. All rights reserved.
434
Markdown
38.545451
113
0.815668
MomentFactory/Omniverse-MVR-GDTF-converter/repo.toml
# common settings for repo_usd for all USD plug-ins [repo_usd] usd_root = "${root}/_build/usd-deps/nv-usd/%{config}" usd_python_root = "${root}/_build/usd-deps/python" generate_plugin_buildfiles = true plugin_buildfile_format = "cmake" generate_root_buildfile = true [repo_usd.plugin.gdtfFileFormat] plugin_dir = "${root}/src/usd-plugins/fileFormat/gdtfFileFormat" install_root = "${root}/_install/%{platform}/%{config}/gdtfFileFormat" include_dir = "include/gdtfFileFormat" additional_include_dirs = [ "../../../../_build/usd-deps/nv_usd/%{config}/include/tbb", "${root}/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include" ] public_headers = [ "api.h" ] private_headers = [ "gdtfFileFormat.h", "gdtfUsdConverter.h", "../mvrFileFormat/gdtfParser/GdtfParser.h", "tinyxml2.h" ] preprocessor_defines = [ "GDTF_FILEFORMAT" ] cpp_files = [ "gdtfFileFormat.cpp", "gdtfUsdConverter.cpp", "../mvrFileFormat/gdtfParser/GdtfParser.cpp", "tinyxml2.cpp" ] resource_files = [ "plugInfo.json" ] additional_library_dirs = [ "${root}/src/usd-plugins/fileFormat/mvrFileFormat" ] additional_static_libs = [ "assimp", "zlibstatic" ] usd_lib_dependencies = [ "arch", "tf", "plug", "vt", "gf", "sdf", "js", "pcp", "usdGeom", "usd", "usdLux" ] [repo_usd.plugin.mvrFileFormat] plugin_dir = "${root}/src/usd-plugins/fileFormat/mvrFileFormat" install_root = "${root}/_install/%{platform}/%{config}/mvrFileFormat" include_dir = "include/mvrFileFormat" additional_include_dirs = [ "../../../../_build/usd-deps/nv_usd/%{config}/include/tbb", "${root}/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include" ] public_headers = [ "api.h" ] private_headers = [ "mvrFileFormat.h", "mvrParser/tinyxml2.h", "mvrParser/Fixture.h", "mvrParser/FixtureFactory.h", "mvrParser/LayerFactory.h", "mvrParser/MVRParser.h", "gdtfParser/GdtfParser.h", "gdtfParser/ModelSpecification.h", "gdtfParser/Device.h", "../gdtfFileFormat/gdtfUsdConverter.h" ] cpp_files = [ "mvrFileFormat.cpp", "mvrParser/Fixture.cpp", "mvrParser/FixtureFactory.cpp", "mvrParser/LayerFactory.cpp", "mvrParser/MVRParser.cpp", "mvrParser/tinyxml2.cpp", "gdtfParser/GdtfParser.cpp", "../gdtfFileFormat/gdtfUsdConverter.cpp" ] resource_files = [ "plugInfo.json" ] additional_library_dirs = [ "${root}/src/usd-plugins/fileFormat/mvrFileFormat" ] additional_static_libs = [ "assimp", "zlibstatic" ] usd_lib_dependencies = [ "arch", "tf", "plug", "vt", "gf", "sdf", "js", "pcp", "usdGeom", "usd", "usdLux" ]
2,700
TOML
20.782258
70
0.644444
MomentFactory/Omniverse-MVR-GDTF-converter/README.md
# MF.OV.MVR and MF.OV.GDTF Brings support of MVR and GDTF files to Omniverse and USD. This repository contains two different extensions. GDTF (General Device Type Format) defines an asset format that collects technical information about Audiovisual devices. It is currently centered on lighting fixtures and provide accurate digital twins of lighting devices from 100+ manufacturers. MVR (My Virtual Rig) is a scene format that can describe an complete rig of lights, using GDTF assets at its core while adding capabilities to define groups, layers, DMX address and more to allow lighting designer to build virtual replicas of their lighting rigs and enforce a single file format from show design to previz to operation. This repository contains two separate extensions : - [MVR extension](./exts/mf.ov.mvr/) - [GDTF extension](./exts/mf.ov.gdtf/) # Requirements - Requires Omniverse Kit >= 105 - Tested in USD Composer 2023.2.2 and 2023.2.0 # Build ## Build for Omniverse - Just run `build.bat` - Once the build is complete, the FileFormat dlls should be located under : `_install/windows-x86_64/release` ## Build for USDView The dependency configuration is contained in the [usd-deps.packman.xml](deps/usd-deps.packman.xml) file To switch to the correct OpenUSD version for USDview compilation, it may be required to edit the packman configuration file to : ``` <project toolsVersion="5.6"> <dependency name="nv-usd" linkPath="../_build/usd-deps/nv-usd/${config}"> <package name="usd.py310.${platform}.usdview.${config}" version="0.23.05-tc.47+v23.05.b53573ea" /> </dependency> <dependency name="python" linkPath="../_build/usd-deps/python"> <package name="python" version="3.10.13+nv1-${platform}" /> </dependency> </project> ``` `source setenvwindows` Test with `usdview resources/scene.usda` Note : light meshes will not show up unless you have a GLTF FileFormat plugin enabled. ## Alternate builds At the bottom of this Readme, you will find alternative ways of building for Unreal 5.3 and Blender 4.0. # Using the extension To enable the extensions in USD Composer: - `Window` > `Extensions` - Search for `MF GDTF Converter` or `MF MVR Converter` in commuunity and enable them with the "autoload" checkbox. - Restart USD composer. ## Sample files MVR samples : - [7-fixtures-samples.mvr](./exts/mf.ov.mvr/sample/7-fixtures-sample.mvr/) - [fixture-line-gltf.mvr](./exts/mf.ov.mvr/sample/fixture-line-gltf.mvr/) GDTF sample - [Robin_MMX_Blade](./exts/mf.ov.gdtf/sample/Robe_Lighting@Robin_MMX_Blade@2023-07-25__Beam_revision.gdtf) Thousands of GDTF files are available on [GDTF-share](https://gdtf-share.com/). For example the very last version of the GDTF sample file we provide can be downloaded from [here](https://gdtf-share.com/share.php?page=home&manu.=Robe%20Lighting&fix=Robin%20MMX%20Blade) ## Reference MVR/GDTF files To reference an MVR or a GDTF file, just drag and drop the file on your viewport or your Stage Window. ## Convert MVR/GDTF files Note: to properly work with MVR files, both extension have to be enabled. 1. In the content tab, browse to the folder where you want to import your `MVR` or `GDTF` files. 2. Click the `+Import` button and select "External Assets (FBX, OBJ...) 3. Choose a `MVR` or `GDTF` file and wait for it to import. - MVR import - The import result will be stored in a folder with the same name as the imported file in the current content browser directory. - If `GDTF` files are referenced, they will be converted to `USD` in a subfolder. - GDTF import - The import result will be stored in a folder with the same name as the imported file in the current content browser directory. 4. To finalize the import, drag the freshly converted `USD` file in your project or open it. # Implementation notes ## `MVR.USD` USD schema Note : not every aspect of the MVR specification is currently implemented for USD, as we focused on the ability to retrieve the lighting fixture information. 1. Under the Root, you'll find `Scope` representing the different `Layers` of the MVR scene. 2. Inside them you'll find each GDTF Fixture represented by an `Xform` pointing to an USD payload. 3. `Xform` are named using their names and their uuid to ensure unique naming. 4. `Xform` also have custom properties (see Raw USD Properties) using the following convention: `mf:mvr:property`. ``` Root/ └─📁MVR-Layer1 (Scope) | ├─💠Make_Model_UID1 (Xform with payload) | └─💠Make_Model_UID2 (Xform with payload) └──📁MVR-Layer1 (Scope) └─💠Make_Model_UID1 (Xform with payload) └─💠Make_Model_UID2 (Xform with payload) ``` ## MVR Raw USD Properties When importing an MVR files, some properties specific to MVR and not compatible with USD will be imported as raw USD properties of an Xform holding a lighting fixture : | Property | Type | Description | |--- |--- |--- | |`mf:mvr:name` |[🔗String](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | The name of the object. | |`mf:mvr:uuid` |[🔗UUID](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | The unique identifier of the object. | |`mf:mvr:Classing` |[🔗UUID](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | The class the object belongs to | |`mf:mvr:GDTFMode` |[🔗String](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | The name of the used DMX mode. This has to match the name of a DMXMode in the GDTF file.| |`mf:mvr:GDTFSpec` |[🔗FileName](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | The name of the file containing the GDTF information for this light fixture. | |`mf:mvr:CastShadow` |[🔗Bool](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | Wether the fixture casts shadows or not. | |`mf:mvr:UnitNumber` |[🔗Integer](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) |The unit number of the lighting fixture in a position. | |`mf:mvr:Addresses` |[🔗Adresses](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#node-definition-addresses)| the DMX address of the fixture. | |`mf:mvr:CustomCommands` |[🔗CustomCommands](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#node-definition-customcommands)| Custom commands that should be executed on the fixture | |`mf:mvr:CIEColor` |[🔗CIE Color](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#user-content-attrtype-ciecolor)| A color assigned to a fixture. If it is not defined, there is no color for the fixture.| |`mf:mvr:FixtureTypeId` |[🔗Integer](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) | The Fixture Type ID is a value that can be used as a short name of the Fixture Type. | |`mf:mvr:CustomId` |[🔗Integer](https://github.com/mvrdevelopment/spec/blob/main/mvr-spec.md#generic-value-types) |The Custom ID is a value that can be used as a short name of the Fixture Instance. | Example ![Raw USD properties screenshot](img/raw_usd_properties.png) ## `GDTF.USD` USD Schema GDTF can have multiple structure type, but here is a typical example for a moving light. ``` Root/ └─💠 Base (Xform) ├─💠model (Xform) │ └─🧊 mesh (Mesh) ├─💠Yoke (Xform) │ ├─💠model (Xform) │ │ └─🧊 mesh (Mesh) | └──💠Head (Xform) │ └─💠model (Xform) │ └─🧊 mesh (Mesh) └─📁Looks (Scope) ``` ## GDTF Raw USD Properties ### Properties affecting the USD Prims properties | Property | Type | Description |--- |--- |--- |`mf:gdtf:BeamAngle` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types)| Will affect the USD Light's `Cone Angle`. |`mf:gdtf:ColorTemperature` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types)| Color temperature; Unit: kelvin. Will affec USD Light's `Color Temperature`. |`mf:gdtf:LuminousFlux` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types)| Intensity of all the represented light emitters; Unit: lumen. Will affec USD Light's `intensity` ### Fixture | Property | Type | Description |--- |--- |--- |`mf:gdtf:OperatingTemperature:High`|[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | Lowest temperature the device can be operated. Unit: °C. |`mf:gdtf:OperatingTemperature:Low` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | Highest temperature the device can be operated. Unit: °C. |`mf:gdtf:Weight` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | Weight of the device including all accessories. Unit: kilogram. |`mf:gdtf:LegHeight` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | Defines height of the legs - distance between the floor and the bottom base plate. Unit: meter. ### Beam (Light) | Property | Type | Description |--- |--- |--- |`mf:gdtf:BeamType` |[🔗Enum](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | Beam Type; Specified values: "Wash", "Spot", "None", "Rectangle", "PC", "Fresnel", "Glow". |`mf:gdtf:ColorRenderingIndex`|[🔗Uint](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | The CRI according to TM-30 is a quantitative measure of the ability of the light source showing the object color naturally as it does as daylight reference. |`mf:gdtf:FieldAngle` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types)| Field angle; Unit: degree. |`mf:gdtf:LampType` |[🔗Enum](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types) | Defines type of the light source; The currently defined types are: Discharge, Tungsten, Halogen, LED. |`mf:gdtf:PowerConsumption` |[🔗Float](https://github.com/mvrdevelopment/spec/blob/main/gdtf-spec.md#table-1--xml-attribute-value-types)| ower consumption; Unit: Watt. ### XML Notes Example of a fixture defined in a MVR file (contains some, but not all properties): ```xml <Fixture name="Sharpy" uuid="C63B1F8D-6DAD-438C-9228-E33C6EF2947E"> <Matrix>{-1.000000,0.000000,0.000000}{0.000000,-1.000000,-0.000000}{0.000000,0.000000,1.000000}{-766.333333,4572.000000,7620.000000}</Matrix> <GDTFSpec>Clay Paky@Sharpy [Bulb=MSD Platinum 5R 189W].gdtf</GDTFSpec> <GDTFMode>Vect</GDTFMode> <Addresses> <Address break="0">21</Address> </Addresses> <FixtureID>102</FixtureID> <UnitNumber>0</UnitNumber> <FixtureTypeId>0</FixtureTypeId> <CustomId>0</CustomId> <Color>0.312712,0.329008,100.000000</Color> <CastShadow>false</CastShadow> <Mappings/> </Fixture> ``` Some notes on the properties: - Matrix is in millimeters (applies to the last part, the translation). - Color is in [CIE 1931 color space](https://en.wikipedia.org/wiki/CIE_1931_color_space) and represent the color of a color gel or similar apparatus and not of the fixture itself. # Alternate builds ## Build for Unreal 5.3 Unreal 5.3 uses USD 23.02 Use the following dependency ``` <dependency name="nv-usd" linkPath="../_build/usd-deps/nv-usd/${config}"> <package name="usd.py310.${platform}.usdview.${config}" version="0.23.02-tc.1+pxr-23.02-build-patch.9ed269df" /> </dependency> ``` - In your Unreal project, enable the USD Importer plugin - Create a subfolder in your Unreal Project ex : `MyProject/Content/USDPlugins` - Copy the plugInfo.json and the mvrFileFormat.dll at the root of this folder - Adapt the plugInfo.json : - `"LibraryPath": "mvrFileFormat.dll"` - `"ResourcePath": "."`, - `"Root": "."` - Add the `MyProject/Content/USDPlugins` in Edit > Project Settings > USDImporter > Additional Plugin Directories Note. Unreal is gonna complain about missing dll. Dirty fix is to add the following dll (take the one from packman) into the `...UE_5.3\Engine\Binaries\Win64` - `boost_python310-vc142-mt-x64-1_78.dll` - `python310.dll` ## Build for Blender 3.6.x or 4.0 Waiting for a cleaner way to provide build support for Blender, here is a step by step. Use the following dependency. ``` <dependency name="blender_usd" linkPath="../_build/usd-deps/nv-usd"> <package name="blender_usd" version="63380-py310-usd23.05-windows-x86_64"/> </dependency> ``` In the `repo.toml` Modify the USD dependencies. ``` usd_lib_dependencies = [ "ms" ] ``` Remove `%{config}` after `usd_root` ``` usd_root = "${root}/_build/usd-deps/nv-usd" ``` Copy the Plugin folder : `omniverse-mvr-extension/_install/windows-x86_64/release/mvrFileFormat` into your Blender Plugin folder `BLENDER_ROOT/blender.shared/usd` # Resources - Inspired by : [NVIDIA's usd-plugin-sample](https://github.com/NVIDIA-Omniverse/usd-plugin-samples/) - [MVR and GDTF homepage with Fixture Library](https://gdtf-share.com/) - [Specifications Github repostory](https://github.com/mvrdevelopment/spec) - [Gdtf.eu](https://gdtf.eu/docs/list-of-projects/) # Known limitation - GDTF files using 3ds model are supported but will require python 3.10 cli installed on the host computer. - Some MVR or GDTF files might fail to convert due to invalid or incomplete files. - Only lighting devices are supported, prefer for importing mvr file not contaning trusses for instance. It could lead to strange behaviors and crashes.
15,288
Markdown
55.003663
336
0.652276
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/mvrFileFormat.cpp
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "mvrFileFormat.h" #include <pxr/base/tf/diagnostic.h> #include <pxr/base/tf/stringUtils.h> #include <pxr/base/tf/token.h> #include <pxr/usd/usd/prim.h> #include <pxr/usd/usd/stage.h> #include <pxr/usd/usd/usdaFileFormat.h> #include <pxr/usd/usdGeom/mesh.h> #include <pxr/usd/usdGeom/scope.h> #include <pxr/usd/usdGeom/camera.h> #include <pxr/usd/usdGeom/cube.h> #include <pxr/usd/usdGeom/xformable.h> #include <pxr/usd/usdGeom/xform.h> #include <pxr/usd/usdLux/rectLight.h> #include <pxr/base/gf/matrix3f.h> #include <pxr/base/gf/rotation.h> #include <pxr/base/gf/vec3f.h> #include <pxr/usd/usd/payloads.h> #include "mvrParser/MVRParser.h" #include "../gdtfFileFormat/gdtfUsdConverter.h" #include <iostream> #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include <experimental/filesystem> PXR_NAMESPACE_OPEN_SCOPE MvrFileFormat::MvrFileFormat() : SdfFileFormat( MvrFileFormatTokens->Id, MvrFileFormatTokens->Version, MvrFileFormatTokens->Target, MvrFileFormatTokens->Extension) { } MvrFileFormat::~MvrFileFormat() { } bool MvrFileFormat::CanRead(const std::string& filePath) const { return true; } static std::string CleanNameForUSD(const std::string& name) { std::string cleanedName = name; if(cleanedName.size() == 0) { return "Default"; } if(cleanedName.size() == 1 && !TfIsValidIdentifier(cleanedName)) { // If we have an index as a name, we only need to add _ beforehand. return CleanNameForUSD("_" + cleanedName); } return TfMakeValidIdentifier(cleanedName); } bool MvrFileFormat::Read(SdfLayer* layer, const std::string& resolvedPath, bool metadataOnly) const { // these macros emit methods defined in the Pixar namespace // but not properly scoped, so we have to use the namespace // locally here - note this isn't strictly true since we had to open // the namespace scope anyway because the macros won't allow non-Pixar namespaces // to be used because of some auto-generated content PXR_NAMESPACE_USING_DIRECTIVE if (!TF_VERIFY(layer)) { return false; } // Parse MVR file // --------------------- using namespace MVR; auto parser = MVRParser(); auto layers = parser.ParseMVRFile(resolvedPath); // Create USD Schema // ------------------------ SdfLayerRefPtr newLayer = SdfLayer::CreateAnonymous(".usd"); UsdStageRefPtr stage = UsdStage::Open(newLayer); auto xformPath = SdfPath("/mvr_payload"); auto defaultPrim = UsdGeomXform::Define(stage, xformPath); stage->SetDefaultPrim(defaultPrim.GetPrim()); for(const auto& layer : layers) { const std::string cleanName = CleanNameForUSD(layer.name); const auto& layerPath = xformPath.AppendChild(TfToken(CleanNameForUSD(layer.name))); auto layerUsd = UsdGeomScope::Define(stage, layerPath); for(const auto& fixture : layer.fixtures) { const std::string cleanFixtureName = CleanNameForUSD(fixture.Name + fixture.UUID); const auto& fixturePath = layerPath.AppendChild(TfToken(cleanFixtureName)); const auto& fixtureUsd = UsdGeomXform::Define(stage, fixturePath); GDTF::GDTFSpecification gdtfSpec = parser.GetGDTFSpecification(fixture.GDTFSpec); GDTF::ConvertToUsd(gdtfSpec, stage, fixturePath.GetAsString()); GfMatrix4d transform = GfMatrix4d( fixture.Matrix[0][0], fixture.Matrix[0][1], fixture.Matrix[0][2], 0, fixture.Matrix[1][0], fixture.Matrix[1][1], fixture.Matrix[1][2], 0, fixture.Matrix[2][0], fixture.Matrix[2][1], fixture.Matrix[2][2], 0, fixture.Matrix[3][0], fixture.Matrix[3][1], fixture.Matrix[3][2], 1 ); // Offset matrix GfMatrix3d rotateMinus90deg = GfMatrix3d(1, 0, 0, 0, 0, 1, 0, -1, 0); // Translation //transform = transform.GetTranspose(); GfVec3d translation = rotateMinus90deg * transform.ExtractTranslation() * 0.1; // Rotation GfRotation rotation = transform.ExtractRotation(); GfVec3d euler = rotation.Decompose(GfVec3f::XAxis(), GfVec3f::YAxis(), GfVec3f::ZAxis()); GfVec3d rotate = rotateMinus90deg * euler; // we somehow have a complete 180 offset here. // Set transform auto fixtureXform = UsdGeomXformable(fixtureUsd); fixtureXform.ClearXformOpOrder(); fixtureXform.AddTranslateOp().Set(translation); fixtureXform.AddScaleOp().Set(GfVec3f(100, 100, 100)); fixtureXform.AddRotateYXZOp(UsdGeomXformOp::PrecisionDouble).Set(rotate); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:name"), pxr::SdfValueTypeNames->String).Set(fixture.Name); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:uuid"), pxr::SdfValueTypeNames->String).Set(fixture.UUID); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:GDTFSpec"), pxr::SdfValueTypeNames->String).Set(fixture.GDTFSpec); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:GDTFMode"), pxr::SdfValueTypeNames->String).Set(fixture.GDTFMode); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:Classing"), pxr::SdfValueTypeNames->String).Set(fixture.Classing); int i = 0; std::string allCommands = "["; for(auto cc : fixture.CustomCommands) { allCommands += cc + ","; i++; } allCommands += "]"; fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:CustomCommands"), pxr::SdfValueTypeNames->String).Set(allCommands); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:CIEColor"), pxr::SdfValueTypeNames->String).Set(fixture.CieColor); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:FixtureID"), pxr::SdfValueTypeNames->UInt).Set(fixture.FixtureID); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:UnitNumber"), pxr::SdfValueTypeNames->UInt).Set(fixture.UnitNumber); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:FixtureTypeId"), pxr::SdfValueTypeNames->UInt).Set(fixture.FixtureTypeID); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:CustomId"), pxr::SdfValueTypeNames->UInt).Set(fixture.CustomId); fixtureUsd.GetPrim().CreateAttribute(TfToken("mf:mvr:CastShadow"), pxr::SdfValueTypeNames->Bool).Set(fixture.CastShadows); } } layer->TransferContent(newLayer); return true; } bool MvrFileFormat::WriteToString(const SdfLayer& layer, std::string* str, const std::string& comment) const { // this POC doesn't support writing return false; } bool MvrFileFormat::WriteToStream(const SdfSpecHandle& spec, std::ostream& out, size_t indent) const { // this POC doesn't support writing return false; } bool MvrFileFormat::_ShouldSkipAnonymousReload() const { return false; } bool MvrFileFormat::_ShouldReadAnonymousLayers() const { return true; } void MvrFileFormat::ComposeFieldsForFileFormatArguments(const std::string& assetPath, const PcpDynamicFileFormatContext& context, FileFormatArguments* args, VtValue* contextDependencyData) const { return; } bool MvrFileFormat::CanFieldChangeAffectFileFormatArguments(const TfToken& field, const VtValue& oldValue, const VtValue& newValue, const VtValue& contextDependencyData) const { return true; } // these macros emit methods defined in the Pixar namespace // but not properly scoped, so we have to use the namespace // locally here TF_DEFINE_PUBLIC_TOKENS( MvrFileFormatTokens, ((Id, "mvrFileFormat")) ((Version, "1.0")) ((Target, "usd")) ((Extension, "mvr")) ); TF_REGISTRY_FUNCTION(TfType) { SDF_DEFINE_FILE_FORMAT(MvrFileFormat, SdfFileFormat); } PXR_NAMESPACE_CLOSE_SCOPE
7,940
C++
32.506329
194
0.732116
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/api.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_MVR_API_H_ #define OMNI_MVR_API_H_ #include "pxr/base/arch/export.h" #if defined(PXR_STATIC) # define MVR_API # define MVR_API_TEMPLATE_CLASS(...) # define MVR_API_TEMPLATE_STRUCT(...) # define EDF_LOCAL #else # if defined(MVRFILEFORMAT_EXPORTS) # define MVR_API ARCH_EXPORT # define MVR_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__) # define MVR_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__) # else # define MVR_API ARCH_IMPORT # define MVR_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__) # define MVR_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__) # endif # define EDF_LOCAL ARCH_HIDDEN #endif #endif
1,340
C
34.289473
85
0.701493
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/mvrFileFormat.h
// Copyright 2023 NVIDIA CORPORATION // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef OMNI_EDF_EDFFILEFORMAT_H_ #define OMNI_EDF_EDFFILEFORMAT_H_ #define NOMINMAX #include <pxr/pxr.h> #include <pxr/base/tf/token.h> #include <pxr/usd/sdf/fileFormat.h> #include <pxr/usd/sdf/layer.h> #include <pxr/usd/pcp/dynamicFileFormatInterface.h> #include <pxr/usd/pcp/dynamicFileFormatContext.h> #include "api.h" PXR_NAMESPACE_OPEN_SCOPE /// \class MvrFileFormat /// /// Represents a generic dynamic file format for external data. /// Actual acquisition of the external data is done via a set /// of plug-ins to various back-end external data systems. /// class MVR_API MvrFileFormat : public SdfFileFormat, public PcpDynamicFileFormatInterface { public: // SdfFileFormat overrides bool CanRead(const std::string& filePath) const override; bool Read(SdfLayer* layer, const std::string& resolvedPath, bool metadataOnly) const override; bool WriteToString(const SdfLayer& layer, std::string* str, const std::string& comment = std::string()) const override; bool WriteToStream(const SdfSpecHandle& spec, std::ostream& out, size_t indent) const override; // PcpDynamicFileFormatInterface overrides void ComposeFieldsForFileFormatArguments(const std::string& assetPath, const PcpDynamicFileFormatContext& context, FileFormatArguments* args, VtValue* contextDependencyData) const override; bool CanFieldChangeAffectFileFormatArguments(const TfToken& field, const VtValue& oldValue, const VtValue& newValue, const VtValue& contextDependencyData) const override; protected: SDF_FILE_FORMAT_FACTORY_ACCESS; bool _ShouldSkipAnonymousReload() const override; bool _ShouldReadAnonymousLayers() const override; virtual ~MvrFileFormat(); MvrFileFormat(); }; TF_DECLARE_PUBLIC_TOKENS( MvrFileFormatTokens, ((Id, "mvrFileFormat")) ((Version, "1.0")) ((Target, "usd")) ((Extension, "mvr")) ); TF_DECLARE_WEAK_AND_REF_PTRS(MvrFileFormat); PXR_NAMESPACE_CLOSE_SCOPE #endif
2,492
C
33.150684
190
0.769262
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/README.md
# usd-mvr-plugin An OpenUSD plugin for the MVR VESA standard # Requirements 1- An USD Installation 2- CMake # Build Instructions 1- cmake . -DPXR_PATH=PATH_TO_USD_INSTALL 2- Open generated .sln file and compile
212
Markdown
20.299998
43
0.764151
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/gdtfParser/GdtfParser.cpp
#include "GdtfParser.h" #ifdef GDTF_FILEFORMAT #include "../mvrFileFormat/mvrParser/zip_file2.hpp" #endif #include "../mvrFileFormat/mvrParser/tinyxml2.h" #include "../mvrFileFormat/assimp/include/assimp/scene.h" #include "../mvrFileFormat/assimp/include/assimp/postprocess.h" #include "../mvrFileFormat/assimp/include/assimp/Importer.hpp" #include "../mvrFileFormat/assimp/include/assimp/Exporter.hpp" #include <iostream> #include <map> #include <sstream> #include <fstream> #define MINIZ_HEADER_FILE_ONLY #include "../mvrFileFormat/mvrParser/zip_file2.hpp" #undef MINIZ_HEADER_FILE_ONLY using ZipInfo = miniz_cpp2::zip_info; using ZipInfoList = std::vector<ZipInfo>; using ZipFile = miniz_cpp2::zip_file; #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include <experimental/filesystem> namespace GDTF { std::vector<std::string> GDTFParser::StringSplit(const std::string& input, const char delimiter) { std::vector<std::string> result; std::stringstream ss(input); std::string item; while (getline(ss, item, delimiter)) { result.push_back(item); } return result; } GDTF::GDTFMatrix StringToMatrix(const std::string& inputString) { std::string input = inputString; size_t pos; while ((pos = input.find("}{")) != std::string::npos) { input.replace(pos, 2, " "); } for (char& c : input) { if (c == ',' || c == ';' || c == '{' || c == '}') { c = ' '; } } GDTF::GDTFMatrix output; std::istringstream iss(input); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { if (!(iss >> output[i][j])) { } } } return output; } bool GDTFParser::FileExists(const std::string& path) const { const std::ifstream filePath(path); return filePath.good(); } GDTF::GDTFSpecification GDTFParser::ParseGDTFFile(const std::string& filePath) { if (!FileExists(filePath)) { m_Errors.push("Failed to parse GDTF file: file doesn't exists - " + filePath); return {}; } m_TargetPath = std::experimental::filesystem::temp_directory_path().string() + "/"; m_SpecName = std::experimental::filesystem::path(filePath).filename().string(); auto zipFile = std::make_shared<ZipFile>(filePath); auto spec = HandleGDTF(zipFile); spec.SpecName = std::experimental::filesystem::path(zipFile->get_filename()).filename().string(); return spec; } GDTF::GDTFSpecification GDTFParser::ParseCompressed(std::shared_ptr<ZipFile> file, const std::string& zipFileName) { m_TargetPath = std::experimental::filesystem::temp_directory_path().string() + "/"; m_SpecName = std::experimental::filesystem::path(zipFileName).filename().string(); auto spec = HandleGDTF(file); spec.SpecName = zipFileName; return spec; } bool StringEndsWith(const std::string& input, const std::string& compare) { if(input.size() >= compare.size()) { return (input.compare(input.length() - compare.length(), compare.length(), compare) == 0); } return false; } void GDTFParser::HandleModel(const File& file, const std::string& fixtureName) { Assimp::Importer importer; bool from3ds = StringEndsWith(file.name, "3ds"); const aiScene* scene = importer.ReadFileFromMemory(file.content.data(), file.content.size() , aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenSmoothNormals | aiProcess_JoinIdenticalVertices,"EXTENTION"); Assimp::Exporter exporter; std::experimental::filesystem::path targetPath = m_TargetPath; std::experimental::filesystem::path destination = targetPath.parent_path().append(fixtureName); std::experimental::filesystem::create_directory(destination); std::experimental::filesystem::path convertedFileName = destination.append(std::experimental::filesystem::path(file.name).stem().concat(".gltf").c_str()); exporter.Export(scene, "gltf2", convertedFileName.string()); m_GDTFAssets[fixtureName][file.name] = convertedFileName.string(); } std::string GDTFParser::GetFileExtension(const std::string& fileName) { const auto& fileNameSplits = StringSplit(fileName, '.'); const std::string fileExtension = fileNameSplits[fileNameSplits.size() - 1]; return fileExtension; } FileType GDTFParser::GetFileTypeFromExtension(const std::string& fileExtension) { if (fileExtension == "xml") { return FileType::XML; } else if (fileExtension == "3ds") { return FileType::MODEL; } else if(fileExtension == "gdtf") { return FileType::GDTF; } else if(fileExtension == "3ds" || fileExtension == "glb" || fileExtension == "gltf") { return FileType::MODEL; } return FileType::UNKNOWN; } void GDTFParser::HandleGDTFRecursive(tinyxml2::XMLElement* element, GDTF::GDTFSpecification& spec, int depth) { if(depth >= 4) { return; // Avoid stack overflow } int itCount = 0; for(auto* geometry = element->FirstChildElement(); geometry != nullptr; geometry = geometry->NextSiblingElement()) { itCount++; if(itCount > 8) { return; } const std::string elementName = geometry->Name(); bool isBeam = elementName == "Beam"; bool isGeometry = elementName == "Geometry"; bool isAxis = elementName == "Axis"; bool isInventory = elementName == "Inventory"; bool isValid = (isBeam || isGeometry || isAxis) && !isInventory; bool isModel = geometry->FindAttribute("Model") != nullptr; if(!isValid || !isModel) continue; auto positionString = geometry->FindAttribute("Position")->Value(); auto position = StringToMatrix(positionString); std::string name = geometry->FindAttribute("Name")->Value(); std::string model = geometry->FindAttribute("Model")->Value(); std::replace(name.begin(), name.end(), ' ', '_'); if(name == "Pigtail" || name == "pigtail" || model == "pigtail" || model == "Pigtail") { continue; } Geometry geometrySpec = {}; geometrySpec.Name = name; geometrySpec.Model = model; geometrySpec.Transform = position; geometrySpec.Depth = depth; if(isBeam) { geometrySpec.isBeam = true; float beamRadius = 0.0f; if(!geometry->QueryFloatAttribute("BeamRadius", &beamRadius)) { // Failed to find beamRadius. } geometrySpec.beamRadius = beamRadius; auto beamAngleXml = geometry->FindAttribute("BeamAngle")->Value(); if(!geometry->QueryFloatAttribute("BeamAngle", &spec.BeamAngle)) { // Failed to find beamRadius. } auto beamTypeXml = geometry->FindAttribute("BeamType")->Value(); spec.BeamType = beamTypeXml; int colorRenderingIndex = 0; if(!geometry->QueryIntAttribute("ColorRenderingIndex", &spec.ColorRenderingIndex)) { } spec.ColorRenderingIndex = colorRenderingIndex; if(!geometry->QueryFloatAttribute("ColorTemperature", &spec.ColorTemperature)) { } if(!geometry->QueryFloatAttribute("FieldAngle", &spec.FieldAngle)) { } auto lampType = geometry->FindAttribute("LampType"); if(lampType) { spec.LampType = lampType->Value(); } if(!geometry->QueryFloatAttribute("LuminousFlux", &spec.LuminousFlux)) { } if(!geometry->QueryFloatAttribute("PowerConsumption", &spec.PowerConsumption)) { } spec.BeamRadius = beamRadius; auto beamPosition = geometry->FindAttribute("Position")->Value(); spec.BeamMatrix = StringToMatrix(beamPosition); spec.HasBeam = true; } spec.Geometries.push_back(geometrySpec); HandleGDTFRecursive(geometry, spec, depth + 1); } } GDTF::GDTFSpecification GDTFParser::HandleGDTF(std::shared_ptr<ZipFile>& zipFile) { std::map<std::string, std::vector<File>> fixtures; std::vector<File> assetFiles; GDTF::GDTFSpecification spec{}; for (const ZipInfo& info : zipFile->infolist()) { std::cout << info.filename << std::endl; const std::string& fileContent = zipFile->read(info); File file = { info.filename, fileContent }; const FileType fileType = GetFileTypeFromExtension(GetFileExtension(info.filename)); switch (fileType) { case FileType::XML: { tinyxml2::XMLDocument doc; if (doc.Parse(file.content.c_str()) != tinyxml2::XML_SUCCESS) { m_Errors.push("Failed to parse XML file: " + file.name); return {}; } tinyxml2::XMLElement* root = doc.RootElement(); auto fixtureType = root->FirstChildElement("FixtureType"); std::string name = (fixtureType->FindAttribute("Name"))->Value(); if(name.empty()) { name = fixtureType->FindAttribute("LongName")->Value(); } auto physicalDescription = fixtureType->FirstChildElement("PhysicalDescriptions"); if(physicalDescription) { auto pdProp = physicalDescription->FirstChildElement("Properties"); if(pdProp) { auto temp = pdProp->FirstChildElement("OperatingTemperature"); auto highXml = temp->FindAttribute("High"); if(highXml) { spec.HighTemperature = std::atof(highXml->Value()); } auto lowXml = temp->FindAttribute("Low"); if(lowXml) { spec.LowTemperature = std::atof(lowXml->Value()); } auto weightXml = pdProp->FirstChildElement("Weight"); if(weightXml) { auto weightValueXml = weightXml->FindAttribute("Value"); if(weightValueXml) { spec.Weight = std::atof(weightValueXml->Value()); } } auto legHeightXml = pdProp->FirstChildElement("LegHeight"); if(legHeightXml) { auto legHeightValueXml = legHeightXml->FindAttribute("Value"); if(legHeightValueXml) { spec.LegHeight = std::atof(legHeightValueXml->Value()); } } } } spec.Name = std::string(name); auto models = fixtureType->FirstChildElement("Models"); for(auto* model = models->FirstChildElement("Model"); model; model = model->NextSiblingElement()) { GDTF::ModelSpecification modelSpec; modelSpec.Name = model->FindAttribute("Name")->Value(); modelSpec.File = model->FindAttribute("File")->Value(); // Fallback if the XML doesnt contain a name if(modelSpec.Name.empty()) { modelSpec.Name = modelSpec.File; } model->QueryFloatAttribute("Length", &modelSpec.Length); model->QueryFloatAttribute("Height", &modelSpec.Height); spec.Models.push_back(modelSpec); } int depth = 0; auto geometries = fixtureType->FirstChildElement("Geometries"); HandleGDTFRecursive(geometries, spec, 0); break; } case FileType::MODEL: { if(StringEndsWith(file.name, "3ds")) { spec.ConvertedFrom3ds = true; } assetFiles.push_back(file); break; } default: break; // Skip unknown file format. } } for(auto& f : assetFiles) { HandleModel(f, m_SpecName); } return spec; } }
10,925
C++
25.845209
214
0.654005
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/gdtfParser/GdtfParser.h
#pragma once #include "ModelSpecification.h" #include <vector> #include <stack> #include <string> #include <memory> #include <map> namespace tinyxml2 { class XMLElement; } namespace miniz_cpp2 { class zip_file; } using ZipFile = miniz_cpp2::zip_file; namespace GDTF { enum class FileType { GDTF, MODEL, XML, UNKNOWN }; struct File { std::string name; std::string content; }; class GDTFParser { public: GDTFParser() = default; ~GDTFParser() = default; GDTF::GDTFSpecification ParseGDTFFile(const std::string& path); GDTF::GDTFSpecification ParseCompressed(std::shared_ptr<ZipFile> file, const std::string& zipFileName); inline const bool HasError() const { return m_Errors.size() > 1; } const std::string PopError() { if (!HasError()) { throw std::exception("Error stack is empty."); } auto msg = m_Errors.top(); m_Errors.pop(); return msg; } private: const std::string m_SceneDescriptionFileName = "GeneralSceneDescription.xml"; std::stack<std::string> m_Errors; // File handling void HandleXML(const File& fileName); void HandleModel(const File& file, const std::string& fixtureName); GDTF::GDTFSpecification HandleGDTF(std::shared_ptr<ZipFile>& file); void HandleGDTFRecursive(tinyxml2::XMLElement* element, GDTF::GDTFSpecification& spec, int depth); // Utilities bool FileExists(const std::string& path) const; std::string GetFileExtension(const std::string& path); FileType GetFileTypeFromExtension(const std::string& extension); std::vector<std::string> StringSplit(const std::string& input, const char delimiter); std::map<std::string, std::map<std::string, std::string>> m_GDTFAssets; std::string m_TargetPath; std::string m_SpecName; }; }
1,764
C
19.764706
105
0.701814
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/gdtfParser/Device.h
#include <array> namespace GDTF { using GDTFMatrix = std::array<std::array<double, 4>, 4>; }
99
C
13.285712
60
0.646465
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/gdtfParser/ModelSpecification.h
#pragma once #include <string> #include <vector> #include "Device.h" namespace GDTF { struct ModelSpecification { std::string Name; std::string Id; std::string File; std::string ConvertedFilePath; int Depth = 0; float Height = 0.0f; float Length = 0.0f; }; struct Geometry { int Depth = 0.0f; GDTFMatrix Transform; std::string Name; std::string Model; bool isBeam = false; float beamRadius = 0.0f; }; struct GDTFSpecification { std::string Name; std::string SpecName; float LowTemperature = 0.0f; float HighTemperature = 0.0f; float LegHeight = 0.0f; float Weight = 0.0f; bool ConvertedFrom3ds = false; std::vector<ModelSpecification> Models; std::vector<Geometry> Geometries; GDTFMatrix BaseMatrix = GDTFMatrix(); GDTFMatrix BodyMatrix = GDTFMatrix(); GDTFMatrix YokeMatrix = GDTFMatrix(); int TreeDepth = 0; // Beam specific bool HasBeam = false; float BeamRadius = 0.0f; GDTFMatrix BeamMatrix = GDTFMatrix(); float BeamAngle = 0.0f; std::string BeamType = ""; int ColorRenderingIndex = 0; float ColorTemperature = 0.0f; float FieldAngle = 0.0f; std::string LampType = ""; float LuminousFlux = 0.0f; float PowerConsumption = 0.0f; }; }
1,498
C
21.712121
47
0.563418
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/Subdivision.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file Defines a helper class to evaluate subdivision surfaces.*/ #pragma once #ifndef AI_SUBDISIVION_H_INC #define AI_SUBDISIVION_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/types.h> struct aiMesh; namespace Assimp { // ------------------------------------------------------------------------------ /** Helper class to evaluate subdivision surfaces. Different algorithms * are provided for choice. */ // ------------------------------------------------------------------------------ class ASSIMP_API Subdivider { public: /** Enumerates all supported subvidision algorithms */ enum Algorithm { CATMULL_CLARKE = 0x1 }; virtual ~Subdivider(); // --------------------------------------------------------------- /** Create a subdivider of a specific type * * @param algo Algorithm to be used for subdivision * @return Subdivider instance. */ static Subdivider* Create (Algorithm algo); // --------------------------------------------------------------- /** Subdivide a mesh using the selected algorithm * * @param mesh First mesh to be subdivided. Must be in verbose * format. * @param out Receives the output mesh, allocated by me. * @param num Number of subdivisions to perform. * @param discard_input If true is passed, the input mesh is * deleted after the subdivision is complete. This can * improve performance because it allows the optimization * to reuse the existing mesh for intermediate results. * @pre out!=mesh*/ virtual void Subdivide ( aiMesh* mesh, aiMesh*& out, unsigned int num, bool discard_input = false) = 0; // --------------------------------------------------------------- /** Subdivide multiple meshes using the selected algorithm. This * avoids erroneous smoothing on objects consisting of multiple * per-material meshes. Usually, most 3d modellers smooth on a * per-object base, regardless the materials assigned to the * meshes. * * @param smesh Array of meshes to be subdivided. Must be in * verbose format. * @param nmesh Number of meshes in smesh. * @param out Receives the output meshes. The array must be * sufficiently large (at least @c nmesh elements) and may not * overlap the input array. Output meshes map one-to-one to * their corresponding input meshes. The meshes are allocated * by the function. * @param discard_input If true is passed, input meshes are * deleted after the subdivision is complete. This can * improve performance because it allows the optimization * of reusing existing meshes for intermediate results. * @param num Number of subdivisions to perform. * @pre nmesh != 0, smesh and out may not overlap*/ virtual void Subdivide ( aiMesh** smesh, size_t nmesh, aiMesh** out, unsigned int num, bool discard_input = false) = 0; }; inline Subdivider::~Subdivider() = default; } // end namespace Assimp #endif // !! AI_SUBDISIVION_H_INC
4,891
C
36.060606
81
0.63852
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/SmallVector.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file Defines small vector with inplace storage. Based on CppCon 2016: Chandler Carruth "High Performance Code 201: Hybrid Data Structures" */ #pragma once #ifndef AI_SMALLVECTOR_H_INC #define AI_SMALLVECTOR_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif namespace Assimp { // -------------------------------------------------------------------------------------------- /// @brief Small vector with inplace storage. /// /// Reduces heap allocations when list is shorter. It uses a small array for a dedicated size. /// When the growing gets bigger than this small cache a dynamic growing algorithm will be /// used. // -------------------------------------------------------------------------------------------- template<typename T, unsigned int Capacity> class SmallVector { public: /// @brief The default class constructor. SmallVector() : mStorage(mInplaceStorage), mSize(0), mCapacity(Capacity) { // empty } /// @brief The class destructor. ~SmallVector() { if (mStorage != mInplaceStorage) { delete [] mStorage; } } /// @brief Will push a new item. The capacity will grow in case of a too small capacity. /// @param item [in] The item to push at the end of the vector. void push_back(const T& item) { if (mSize < mCapacity) { mStorage[mSize++] = item; return; } push_back_and_grow(item); } /// @brief Will resize the vector. /// @param newSize [in] The new size. void resize(size_t newSize) { if (newSize > mCapacity) { grow(newSize); } mSize = newSize; } /// @brief Returns the current size of the vector. /// @return The current size. size_t size() const { return mSize; } /// @brief Returns a pointer to the first item. /// @return The first item as a pointer. T* begin() { return mStorage; } /// @brief Returns a pointer to the end. /// @return The end as a pointer. T* end() { return &mStorage[mSize]; } /// @brief Returns a const pointer to the first item. /// @return The first item as a const pointer. T* begin() const { return mStorage; } /// @brief Returns a const pointer to the end. /// @return The end as a const pointer. T* end() const { return &mStorage[mSize]; } SmallVector(const SmallVector &) = delete; SmallVector(SmallVector &&) = delete; SmallVector &operator = (const SmallVector &) = delete; SmallVector &operator = (SmallVector &&) = delete; private: void grow( size_t newCapacity) { T* oldStorage = mStorage; T* newStorage = new T[newCapacity]; std::memcpy(newStorage, oldStorage, mSize * sizeof(T)); mStorage = newStorage; mCapacity = newCapacity; if (oldStorage != mInplaceStorage) { delete [] oldStorage; } } void push_back_and_grow(const T& item) { grow(mCapacity + Capacity); mStorage[mSize++] = item; } T* mStorage; size_t mSize; size_t mCapacity; T mInplaceStorage[Capacity]; }; } // end namespace Assimp #endif // !! AI_SMALLVECTOR_H_INC
5,015
C
29.4
95
0.620339
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/color4.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file color4.h * @brief RGBA color structure, including operators when compiling in C++ */ #pragma once #ifndef AI_COLOR4D_H_INC #define AI_COLOR4D_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/defs.h> #ifdef __cplusplus // ---------------------------------------------------------------------------------- /** Represents a color in Red-Green-Blue space including an * alpha component. Color values range from 0 to 1. */ // ---------------------------------------------------------------------------------- template <typename TReal> class aiColor4t { public: aiColor4t() AI_NO_EXCEPT : r(), g(), b(), a() {} aiColor4t (TReal _r, TReal _g, TReal _b, TReal _a) : r(_r), g(_g), b(_b), a(_a) {} explicit aiColor4t (TReal _r) : r(_r), g(_r), b(_r), a(_r) {} aiColor4t (const aiColor4t& o) = default; // combined operators const aiColor4t& operator += (const aiColor4t& o); const aiColor4t& operator -= (const aiColor4t& o); const aiColor4t& operator *= (TReal f); const aiColor4t& operator /= (TReal f); // comparison bool operator == (const aiColor4t& other) const; bool operator != (const aiColor4t& other) const; bool operator < (const aiColor4t& other) const; // color tuple access, rgba order inline TReal operator[](unsigned int i) const; inline TReal& operator[](unsigned int i); /** check whether a color is (close to) black */ inline bool IsBlack() const; // Red, green, blue and alpha color values TReal r, g, b, a; }; // !struct aiColor4D typedef aiColor4t<ai_real> aiColor4D; #else struct aiColor4D { ai_real r, g, b, a; }; #endif // __cplusplus #endif // AI_COLOR4D_H_INC
3,528
C
33.598039
85
0.639172
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/DefaultLogger.hpp
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** * @file DefaultLogger.hpp */ #pragma once #ifndef INCLUDED_AI_DEFAULTLOGGER #define INCLUDED_AI_DEFAULTLOGGER #ifdef __GNUC__ # pragma GCC system_header #endif #include "LogStream.hpp" #include "Logger.hpp" #include "NullLogger.hpp" #include <vector> namespace Assimp { // ------------------------------------------------------------------------------------ class IOStream; struct LogStreamInfo; /** default name of log-file */ #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt" // ------------------------------------------------------------------------------------ /** @brief CPP-API: Primary logging facility of Assimp. * * The library stores its primary #Logger as a static member of this class. * #get() returns this primary logger. By default the underlying implementation is * just a #NullLogger which rejects all log messages. By calling #create(), logging * is turned on. To capture the log output multiple log streams (#LogStream) can be * attach to the logger. Some default streams for common streaming locations (such as * a file, std::cout, OutputDebugString()) are also provided. * * If you wish to customize the logging at an even deeper level supply your own * implementation of #Logger to #set(). * @note The whole logging stuff causes a small extra overhead for all imports. */ class ASSIMP_API DefaultLogger : public Logger { public: // ---------------------------------------------------------------------- /** @brief Creates a logging instance. * @param name Name for log file. Only valid in combination * with the aiDefaultLogStream_FILE flag. * @param severity Log severity, DEBUG turns on debug messages and VERBOSE turns on all messages. * @param defStreams Default log streams to be attached. Any bitwise * combination of the aiDefaultLogStream enumerated values. * If #aiDefaultLogStream_FILE is specified but an empty string is * passed for 'name', no log file is created at all. * @param io IOSystem to be used to open external files (such as the * log file). Pass nullptr to rely on the default implementation. * This replaces the default #NullLogger with a #DefaultLogger instance. */ static Logger *create(const char *name = ASSIMP_DEFAULT_LOG_NAME, LogSeverity severity = NORMAL, unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE, IOSystem *io = nullptr); // ---------------------------------------------------------------------- /** @brief Setup a custom #Logger implementation. * * Use this if the provided #DefaultLogger class doesn't fit into * your needs. If the provided message formatting is OK for you, * it's much easier to use #create() and to attach your own custom * output streams to it. * @param logger Pass NULL to setup a default NullLogger*/ static void set(Logger *logger); // ---------------------------------------------------------------------- /** @brief Getter for singleton instance * @return Only instance. This is never null, but it could be a * NullLogger. Use isNullLogger to check this.*/ static Logger *get(); // ---------------------------------------------------------------------- /** @brief Return whether a #NullLogger is currently active * @return true if the current logger is a #NullLogger. * Use create() or set() to setup a logger that does actually do * something else than just rejecting all log messages. */ static bool isNullLogger(); // ---------------------------------------------------------------------- /** @brief Kills the current singleton logger and replaces it with a * #NullLogger instance. */ static void kill(); // ---------------------------------------------------------------------- /** @copydoc Logger::attachStream */ bool attachStream(LogStream *pStream, unsigned int severity) override; // ---------------------------------------------------------------------- /** @copydoc Logger::detachStream */ bool detachStream(LogStream *pStream, unsigned int severity) override; private: // ---------------------------------------------------------------------- /** @briefPrivate construction for internal use by create(). * @param severity Logging granularity */ explicit DefaultLogger(LogSeverity severity); // ---------------------------------------------------------------------- /** @briefDestructor */ ~DefaultLogger() override; /** @brief Logs debug infos, only been written when severity level DEBUG or higher is set */ void OnDebug(const char *message) override; /** @brief Logs debug infos, only been written when severity level VERBOSE is set */ void OnVerboseDebug(const char *message) override; /** @brief Logs an info message */ void OnInfo(const char *message) override; /** @brief Logs a warning message */ void OnWarn(const char *message) override; /** @brief Logs an error message */ void OnError(const char *message) override; // ---------------------------------------------------------------------- /** @brief Writes a message to all streams */ void WriteToStreams(const char *message, ErrorSeverity ErrorSev); // ---------------------------------------------------------------------- /** @brief Returns the thread id. * @note This is an OS specific feature, if not supported, a * zero will be returned. */ unsigned int GetThreadID(); private: // Aliases for stream container using StreamArray = std::vector<LogStreamInfo *>; using StreamIt = std::vector<LogStreamInfo *>::iterator; using ConstStreamIt = std::vector<LogStreamInfo *>::const_iterator; //! only logging instance static Logger *m_pLogger; static NullLogger s_pNullLogger; //! Attached streams StreamArray m_StreamArray; bool noRepeatMsg; char lastMsg[MAX_LOG_MESSAGE_LENGTH * 2]; size_t lastLen; }; // ------------------------------------------------------------------------------------ } // Namespace Assimp #endif // !! INCLUDED_AI_DEFAULTLOGGER
7,961
C++
40.041237
102
0.604321
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/StreamReader.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file Defines the StreamReader class which reads data from * a binary stream with a well-defined endianness. */ #pragma once #ifndef AI_STREAMREADER_H_INCLUDED #define AI_STREAMREADER_H_INCLUDED #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/ByteSwapper.h> #include <assimp/Exceptional.h> #include <assimp/IOStream.hpp> #include <memory> namespace Assimp { // -------------------------------------------------------------------------------------------- /** Wrapper class around IOStream to allow for consistent reading of binary data in both * little and big endian format. Don't attempt to instance the template directly. Use * StreamReaderLE to read from a little-endian stream and StreamReaderBE to read from a * BE stream. The class expects that the endianness of any input data is known at * compile-time, which should usually be true (#BaseImporter::ConvertToUTF8 implements * runtime endianness conversions for text files). * * XXX switch from unsigned int for size types to size_t? or ptrdiff_t?*/ // -------------------------------------------------------------------------------------------- template <bool SwapEndianess = false, bool RuntimeSwitch = false> class StreamReader { public: using diff = size_t; using pos = size_t; // --------------------------------------------------------------------- /** Construction from a given stream with a well-defined endianness. * * The StreamReader holds a permanent strong reference to the * stream, which is released upon destruction. * @param stream Input stream. The stream is not restarted if * its file pointer is not at 0. Instead, the stream reader * reads from the current position to the end of the stream. * @param le If @c RuntimeSwitch is true: specifies whether the * stream is in little endian byte order. Otherwise the * endianness information is contained in the @c SwapEndianess * template parameter and this parameter is meaningless. */ StreamReader(std::shared_ptr<IOStream> stream, bool le = false) : mStream(stream), mBuffer(nullptr), mCurrent(nullptr), mEnd(nullptr), mLimit(nullptr), mLe(le) { ai_assert(stream); InternBegin(); } // --------------------------------------------------------------------- StreamReader(IOStream *stream, bool le = false) : mStream(std::shared_ptr<IOStream>(stream)), mBuffer(nullptr), mCurrent(nullptr), mEnd(nullptr), mLimit(nullptr), mLe(le) { ai_assert(nullptr != stream); InternBegin(); } // --------------------------------------------------------------------- ~StreamReader() { delete[] mBuffer; } // deprecated, use overloaded operator>> instead // --------------------------------------------------------------------- /// Read a float from the stream. float GetF4() { return Get<float>(); } // --------------------------------------------------------------------- /// Read a double from the stream. double GetF8() { return Get<double>(); } // --------------------------------------------------------------------- /** Read a signed 16 bit integer from the stream */ int16_t GetI2() { return Get<int16_t>(); } // --------------------------------------------------------------------- /** Read a signed 8 bit integer from the stream */ int8_t GetI1() { return Get<int8_t>(); } // --------------------------------------------------------------------- /** Read an signed 32 bit integer from the stream */ int32_t GetI4() { return Get<int32_t>(); } // --------------------------------------------------------------------- /** Read a signed 64 bit integer from the stream */ int64_t GetI8() { return Get<int64_t>(); } // --------------------------------------------------------------------- /** Read a unsigned 16 bit integer from the stream */ uint16_t GetU2() { return Get<uint16_t>(); } // --------------------------------------------------------------------- /// Read a unsigned 8 bit integer from the stream uint8_t GetU1() { return Get<uint8_t>(); } // --------------------------------------------------------------------- /// Read an unsigned 32 bit integer from the stream uint32_t GetU4() { return Get<uint32_t>(); } // --------------------------------------------------------------------- /// Read a unsigned 64 bit integer from the stream uint64_t GetU8() { return Get<uint64_t>(); } // --------------------------------------------------------------------- /// Get the remaining stream size (to the end of the stream) size_t GetRemainingSize() const { return (unsigned int)(mEnd - mCurrent); } // --------------------------------------------------------------------- /** Get the remaining stream size (to the current read limit). The * return value is the remaining size of the stream if no custom * read limit has been set. */ size_t GetRemainingSizeToLimit() const { return (unsigned int)(mLimit - mCurrent); } // --------------------------------------------------------------------- /** Increase the file pointer (relative seeking) */ void IncPtr(intptr_t plus) { mCurrent += plus; if (mCurrent > mLimit) { throw DeadlyImportError("End of file or read limit was reached"); } } // --------------------------------------------------------------------- /** Get the current file pointer */ int8_t *GetPtr() const { return mCurrent; } // --------------------------------------------------------------------- /** Set current file pointer (Get it from #GetPtr). This is if you * prefer to do pointer arithmetic on your own or want to copy * large chunks of data at once. * @param p The new pointer, which is validated against the size * limit and buffer boundaries. */ void SetPtr(int8_t *p) { mCurrent = p; if (mCurrent > mLimit || mCurrent < mBuffer) { throw DeadlyImportError("End of file or read limit was reached"); } } // --------------------------------------------------------------------- /** Copy n bytes to an external buffer * @param out Destination for copying * @param bytes Number of bytes to copy */ void CopyAndAdvance(void *out, size_t bytes) { int8_t *ur = GetPtr(); SetPtr(ur + bytes); // fire exception if eof ::memcpy(out, ur, bytes); } /// @brief Get the current offset from the beginning of the file int GetCurrentPos() const { return (unsigned int)(mCurrent - mBuffer); } void SetCurrentPos(size_t pos) { SetPtr(mBuffer + pos); } // --------------------------------------------------------------------- /** Setup a temporary read limit * * @param limit Maximum number of bytes to be read from * the beginning of the file. Specifying UINT_MAX * resets the limit to the original end of the stream. * Returns the previously set limit. */ unsigned int SetReadLimit(unsigned int _limit) { unsigned int prev = GetReadLimit(); if (UINT_MAX == _limit) { mLimit = mEnd; return prev; } mLimit = mBuffer + _limit; if (mLimit > mEnd) { throw DeadlyImportError("StreamReader: Invalid read limit"); } return prev; } // --------------------------------------------------------------------- /** Get the current read limit in bytes. Reading over this limit * accidentally raises an exception. */ unsigned int GetReadLimit() const { return (unsigned int)(mLimit - mBuffer); } // --------------------------------------------------------------------- /** Skip to the read limit in bytes. Reading over this limit * accidentally raises an exception. */ void SkipToReadLimit() { mCurrent = mLimit; } // --------------------------------------------------------------------- /** overload operator>> and allow chaining of >> ops. */ template <typename T> StreamReader &operator>>(T &f) { f = Get<T>(); return *this; } // --------------------------------------------------------------------- /** Generic read method. ByteSwap::Swap(T*) *must* be defined */ template <typename T> T Get() { if (mCurrent + sizeof(T) > mLimit) { throw DeadlyImportError("End of file or stream limit was reached"); } T f; ::memcpy(&f, mCurrent, sizeof(T)); Intern::Getter<SwapEndianess, T, RuntimeSwitch>()(&f, mLe); mCurrent += sizeof(T); return f; } private: // --------------------------------------------------------------------- void InternBegin() { if (nullptr == mStream) { throw DeadlyImportError("StreamReader: Unable to open file"); } const size_t filesize = mStream->FileSize() - mStream->Tell(); if (0 == filesize) { throw DeadlyImportError("StreamReader: File is empty or EOF is already reached"); } mCurrent = mBuffer = new int8_t[filesize]; const size_t read = mStream->Read(mCurrent, 1, filesize); // (read < s) can only happen if the stream was opened in text mode, in which case FileSize() is not reliable ai_assert(read <= filesize); mEnd = mLimit = &mBuffer[read - 1] + 1; } private: std::shared_ptr<IOStream> mStream; int8_t *mBuffer; int8_t *mCurrent; int8_t *mEnd; int8_t *mLimit; bool mLe; }; // -------------------------------------------------------------------------------------------- // `static` StreamReaders. Their byte order is fixed and they might be a little bit faster. #ifdef AI_BUILD_BIG_ENDIAN typedef StreamReader<true> StreamReaderLE; typedef StreamReader<false> StreamReaderBE; #else typedef StreamReader<true> StreamReaderBE; typedef StreamReader<false> StreamReaderLE; #endif // `dynamic` StreamReader. The byte order of the input data is specified in the // c'tor. This involves runtime branching and might be a little bit slower. typedef StreamReader<true, true> StreamReaderAny; } // end namespace Assimp #endif // !! AI_STREAMREADER_H_INCLUDED
12,485
C
35.191304
117
0.520785
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/StreamWriter.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file Defines the StreamWriter class which writes data to * a binary stream with a well-defined endianness. */ #pragma once #ifndef AI_STREAMWRITER_H_INCLUDED #define AI_STREAMWRITER_H_INCLUDED #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/ByteSwapper.h> #include <assimp/IOStream.hpp> #include <memory> #include <vector> namespace Assimp { // -------------------------------------------------------------------------------------------- /** Wrapper class around IOStream to allow for consistent writing of binary data in both * little and big endian format. Don't attempt to instance the template directly. Use * StreamWriterLE to write to a little-endian stream and StreamWriterBE to write to a * BE stream. Alternatively, there is StreamWriterAny if the endianness of the output * stream is to be determined at runtime. */ // -------------------------------------------------------------------------------------------- template <bool SwapEndianess = false, bool RuntimeSwitch = false> class StreamWriter { enum { INITIAL_CAPACITY = 1024 }; public: // --------------------------------------------------------------------- /** Construction from a given stream with a well-defined endianness. * * The StreamReader holds a permanent strong reference to the * stream, which is released upon destruction. * @param stream Input stream. The stream is not re-seeked and writing continues at the current position of the stream cursor. * @param le If @c RuntimeSwitch is true: specifies whether the * stream is in little endian byte order. Otherwise the * endianness information is defined by the @c SwapEndianess * template parameter and this parameter is meaningless. */ StreamWriter(std::shared_ptr<IOStream> stream, bool le = false) : stream(stream) , le(le) , cursor() { ai_assert(stream); buffer.reserve(INITIAL_CAPACITY); } // --------------------------------------------------------------------- StreamWriter(IOStream* stream, bool le = false) : stream(std::shared_ptr<IOStream>(stream)) , le(le) , cursor() { ai_assert(stream); buffer.reserve(INITIAL_CAPACITY); } // --------------------------------------------------------------------- ~StreamWriter() { stream->Write(buffer.data(), 1, buffer.size()); stream->Flush(); } public: // --------------------------------------------------------------------- /** Flush the contents of the internal buffer, and the output IOStream */ void Flush() { stream->Write(buffer.data(), 1, buffer.size()); stream->Flush(); buffer.clear(); cursor = 0; } // --------------------------------------------------------------------- /** Seek to the given offset / origin in the output IOStream. * * Flushes the internal buffer and the output IOStream prior to seeking. */ aiReturn Seek(size_t pOffset, aiOrigin pOrigin=aiOrigin_SET) { Flush(); return stream->Seek(pOffset, pOrigin); } // --------------------------------------------------------------------- /** Tell the current position in the output IOStream. * * First flushes the internal buffer and the output IOStream. */ size_t Tell() { Flush(); return stream->Tell(); } public: // --------------------------------------------------------------------- /** Write a float to the stream */ void PutF4(float f) { Put(f); } // --------------------------------------------------------------------- /** Write a double to the stream */ void PutF8(double d) { Put(d); } // --------------------------------------------------------------------- /** Write a signed 16 bit integer to the stream */ void PutI2(int16_t n) { Put(n); } // --------------------------------------------------------------------- /** Write a signed 8 bit integer to the stream */ void PutI1(int8_t n) { Put(n); } // --------------------------------------------------------------------- /** Write an signed 32 bit integer to the stream */ void PutI4(int32_t n) { Put(n); } // --------------------------------------------------------------------- /** Write a signed 64 bit integer to the stream */ void PutI8(int64_t n) { Put(n); } // --------------------------------------------------------------------- /** Write a unsigned 16 bit integer to the stream */ void PutU2(uint16_t n) { Put(n); } // --------------------------------------------------------------------- /** Write a unsigned 8 bit integer to the stream */ void PutU1(uint8_t n) { Put(n); } // --------------------------------------------------------------------- /** Write an unsigned 32 bit integer to the stream */ void PutU4(uint32_t n) { Put(n); } // --------------------------------------------------------------------- /** Write a unsigned 64 bit integer to the stream */ void PutU8(uint64_t n) { Put(n); } // --------------------------------------------------------------------- /** Write a single character to the stream */ void PutChar(char c) { Put(c); } // --------------------------------------------------------------------- /** Write an aiString to the stream */ void PutString(const aiString& s) { // as Put(T f) below if (cursor + s.length >= buffer.size()) { buffer.resize(cursor + s.length); } void* dest = &buffer[cursor]; ::memcpy(dest, s.C_Str(), s.length); cursor += s.length; } // --------------------------------------------------------------------- /** Write a std::string to the stream */ void PutString(const std::string& s) { // as Put(T f) below if (cursor + s.size() >= buffer.size()) { buffer.resize(cursor + s.size()); } void* dest = &buffer[cursor]; ::memcpy(dest, s.c_str(), s.size()); cursor += s.size(); } public: // --------------------------------------------------------------------- /** overload operator<< and allow chaining of MM ops. */ template <typename T> StreamWriter& operator << (T f) { Put(f); return *this; } // --------------------------------------------------------------------- std::size_t GetCurrentPos() const { return cursor; } // --------------------------------------------------------------------- void SetCurrentPos(std::size_t new_cursor) { cursor = new_cursor; } // --------------------------------------------------------------------- /** Generic write method. ByteSwap::Swap(T*) *must* be defined */ template <typename T> void Put(T f) { Intern :: Getter<SwapEndianess,T,RuntimeSwitch>() (&f, le); if (cursor + sizeof(T) >= buffer.size()) { buffer.resize(cursor + sizeof(T)); } void* dest = &buffer[cursor]; // reinterpret_cast + assignment breaks strict aliasing rules // and generally causes trouble on platforms such as ARM that // do not silently ignore alignment faults. ::memcpy(dest, &f, sizeof(T)); cursor += sizeof(T); } private: std::shared_ptr<IOStream> stream; bool le; std::vector<uint8_t> buffer; std::size_t cursor; }; // -------------------------------------------------------------------------------------------- // `static` StreamWriter. Their byte order is fixed and they might be a little bit faster. #ifdef AI_BUILD_BIG_ENDIAN typedef StreamWriter<true> StreamWriterLE; typedef StreamWriter<false> StreamWriterBE; #else typedef StreamWriter<true> StreamWriterBE; typedef StreamWriter<false> StreamWriterLE; #endif // `dynamic` StreamWriter. The byte order of the input data is specified in the // c'tor. This involves runtime branching and might be a little bit slower. typedef StreamWriter<true,true> StreamWriterAny; } // end namespace Assimp #endif // !! AI_STREAMWriter_H_INCLUDED
10,198
C
32.439344
95
0.498921
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/CreateAnimMesh.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file CreateAnimMesh.h * Create AnimMesh from Mesh */ #pragma once #ifndef INCLUDED_AI_CREATE_ANIM_MESH_H #define INCLUDED_AI_CREATE_ANIM_MESH_H #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/mesh.h> namespace Assimp { /** * Create aiAnimMesh from aiMesh. * @param mesh The input mesh to create an animated mesh from. * @param needPositions If true, positions will be copied from. * @param needNormals If true, normals will be copied from. * @param needTangents If true, tangents and bitangents will be copied from. * @param needColors If true, colors will be copied from. * @param needTexCoords If true, texCoords will be copied from. * @return The new created animated mesh. */ ASSIMP_API aiAnimMesh *aiCreateAnimMesh(const aiMesh *mesh, bool needPositions = true, bool needNormals = true, bool needTangents = true, bool needColors = true, bool needTexCoords = true); } // end of namespace Assimp #endif // INCLUDED_AI_CREATE_ANIM_MESH_H
2,944
C
36.75641
81
0.67697
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/StringUtils.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ #pragma once #ifndef INCLUDED_AI_STRINGUTILS_H #define INCLUDED_AI_STRINGUTILS_H #ifdef __GNUC__ #pragma GCC system_header #endif #include <assimp/defs.h> #include <cstdarg> #include <algorithm> #include <cctype> #include <cstdlib> #include <locale> #include <sstream> #include <iomanip> #if defined(_MSC_VER) && !defined(__clang__) #define AI_SIZEFMT "%Iu" #else #define AI_SIZEFMT "%zu" #endif // --------------------------------------------------------------------------------- /// @fn ai_snprintf /// @brief The portable version of the function snprintf ( C99 standard ), which /// works on visual studio compilers 2013 and earlier. /// @param outBuf The buffer to write in /// @param size The buffer size /// @param format The format string /// @param ap The additional arguments. /// @return The number of written characters if the buffer size was big enough. /// If an encoding error occurs, a negative number is returned. // --------------------------------------------------------------------------------- #if defined(_MSC_VER) && _MSC_VER < 1900 inline int c99_ai_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) { int count(-1); if (0 != size) { count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); } if (count == -1) { count = _vscprintf(format, ap); } return count; } inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) { int count; va_list ap; va_start(ap, format); count = c99_ai_vsnprintf(outBuf, size, format, ap); va_end(ap); return count; } #elif defined(__MINGW32__) #define ai_snprintf __mingw_snprintf #else #define ai_snprintf snprintf #endif // --------------------------------------------------------------------------------- /// @fn to_string /// @brief The portable version of to_string ( some gcc-versions on embedded /// devices are not supporting this). /// @param value The value to write into the std::string. /// @return The value as a std::string // --------------------------------------------------------------------------------- template <typename T> AI_FORCE_INLINE std::string ai_to_string(T value) { std::ostringstream os; os << value; return os.str(); } // --------------------------------------------------------------------------------- /// @fn ai_strtof /// @brief The portable version of strtof. /// @param begin The first character of the string. /// @param end The last character /// @return The float value, 0.0f in case of an error. // --------------------------------------------------------------------------------- AI_FORCE_INLINE float ai_strtof(const char *begin, const char *end) { if (nullptr == begin) { return 0.0f; } float val(0.0f); if (nullptr == end) { val = static_cast<float>(::atof(begin)); } else { std::string::size_type len(end - begin); std::string token(begin, len); val = static_cast<float>(::atof(token.c_str())); } return val; } // --------------------------------------------------------------------------------- /// @fn DecimalToHexa /// @brief The portable to convert a decimal value into a hexadecimal string. /// @param toConvert Value to convert /// @return The hexadecimal string, is empty in case of an error. // --------------------------------------------------------------------------------- template <class T> AI_FORCE_INLINE std::string ai_decimal_to_hexa(T toConvert) { std::string result; std::stringstream ss; ss << std::hex << toConvert; ss >> result; for (size_t i = 0; i < result.size(); ++i) { result[i] = (char)toupper((unsigned char)result[i]); } return result; } // --------------------------------------------------------------------------------- /// @brief translate RGBA to String /// @param r aiColor.r /// @param g aiColor.g /// @param b aiColor.b /// @param a aiColor.a /// @param with_head # /// @return The hexadecimal string, is empty in case of an error. // --------------------------------------------------------------------------------- AI_FORCE_INLINE std::string ai_rgba2hex(int r, int g, int b, int a, bool with_head) { std::stringstream ss; if (with_head) { ss << "#"; } ss << std::hex << std::setfill('0') << std::setw(8) << (r << 24 | g << 16 | b << 8 | a); return ss.str(); } // --------------------------------------------------------------------------------- /// @brief Performs a trim from start (in place) /// @param s string to trim. AI_FORCE_INLINE void ai_trim_left(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); } // --------------------------------------------------------------------------------- /// @brief Performs a trim from end (in place). /// @param s string to trim. // --------------------------------------------------------------------------------- // --------------------------------------------------------------------------------- AI_FORCE_INLINE void ai_trim_right(std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); } // --------------------------------------------------------------------------------- /// @brief Performs a trim from both ends (in place). /// @param s string to trim. // --------------------------------------------------------------------------------- AI_FORCE_INLINE std::string ai_trim(std::string &s) { std::string out(s); ai_trim_left(out); ai_trim_right(out); return out; } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE char_t ai_tolower(char_t in) { return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in + 0x20) : in; } // --------------------------------------------------------------------------------- /// @brief Performs a ToLower-operation and return the lower-case string. /// @param in The incoming string. /// @return The string as lowercase. // --------------------------------------------------------------------------------- AI_FORCE_INLINE std::string ai_tolower(const std::string &in) { std::string out(in); ai_trim_left(out); ai_trim_right(out); std::transform(out.begin(), out.end(), out.begin(), [](unsigned char c) { return ai_tolower(c); }); return out; } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE char_t ai_toupper(char_t in) { return (in >= (char_t)'a' && in <= (char_t)'z') ? (char_t)(in - 0x20) : in; } // --------------------------------------------------------------------------------- /// @brief Performs a ToLower-operation and return the upper-case string. /// @param in The incoming string. /// @return The string as uppercase. AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) { std::string out(in); std::transform(out.begin(), out.end(), out.begin(), [](char c) { return ai_toupper(c); }); return out; } // --------------------------------------------------------------------------------- /// @brief Make a string printable by replacing all non-printable characters with /// the specified placeholder character. /// @param in The incoming string. /// @param placeholder Placeholder character, default is a question mark. /// @return The string, with all non-printable characters replaced. AI_FORCE_INLINE std::string ai_str_toprintable(const std::string &in, char placeholder = '?') { std::string out(in); std::transform(out.begin(), out.end(), out.begin(), [placeholder] (unsigned char c) { return isprint(c) ? (char)c : placeholder; }); return out; } // --------------------------------------------------------------------------------- /// @brief Make a string printable by replacing all non-printable characters with /// the specified placeholder character. /// @param in The incoming string. /// @param len The length of the incoming string. /// @param placeholder Placeholder character, default is a question mark. /// @return The string, with all non-printable characters replaced. Will return an /// empty string if in is null or len is <= 0. AI_FORCE_INLINE std::string ai_str_toprintable(const char *in, int len, char placeholder = '?') { return (in && len > 0) ? ai_str_toprintable(std::string(in, len), placeholder) : std::string(); } #endif // INCLUDED_AI_STRINGUTILS_H
10,335
C
35.914286
103
0.534107
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/defs.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file defs.h * @brief Assimp build configuration setup. See the notes in the comment * blocks to find out how to customize _your_ Assimp build. */ #pragma once #ifndef AI_DEFINES_H_INC #define AI_DEFINES_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #include <assimp/config.h> ////////////////////////////////////////////////////////////////////////// /* Define ASSIMP_BUILD_NO_XX_IMPORTER to disable a specific * file format loader. The loader is be excluded from the * build in this case. 'XX' stands for the most common file * extension of the file format. E.g.: * ASSIMP_BUILD_NO_X_IMPORTER disables the X loader. * * If you're unsure about that, take a look at the implementation of the * import plugin you wish to disable. You'll find the right define in the * first lines of the corresponding unit. * * Other (mixed) configuration switches are listed here: * ASSIMP_BUILD_NO_COMPRESSED_X * - Disable support for compressed X files (zip) * ASSIMP_BUILD_NO_COMPRESSED_BLEND * - Disable support for compressed Blender files (zip) * ASSIMP_BUILD_NO_COMPRESSED_IFC * - Disable support for IFCZIP files (unzip) */ ////////////////////////////////////////////////////////////////////////// #ifndef ASSIMP_BUILD_NO_COMPRESSED_X #define ASSIMP_BUILD_NEED_Z_INFLATE #endif #ifndef ASSIMP_BUILD_NO_COMPRESSED_BLEND #define ASSIMP_BUILD_NEED_Z_INFLATE #endif #ifndef ASSIMP_BUILD_NO_COMPRESSED_IFC #define ASSIMP_BUILD_NEED_Z_INFLATE #define ASSIMP_BUILD_NEED_UNZIP #endif #ifndef ASSIMP_BUILD_NO_Q3BSP_IMPORTER #define ASSIMP_BUILD_NEED_Z_INFLATE #define ASSIMP_BUILD_NEED_UNZIP #endif // We need those constants, workaround for any platforms where nobody defined them yet #if (!defined SIZE_MAX) #define SIZE_MAX (~((size_t)0)) #endif /*#if (!defined UINT_MAX) #define UINT_MAX (~((unsigned int)0)) #endif*/ ////////////////////////////////////////////////////////////////////////// /* Define ASSIMP_BUILD_NO_XX_PROCESS to disable a specific * post processing step. This is the current list of process names ('XX'): * CALCTANGENTS * JOINVERTICES * TRIANGULATE * DROPFACENORMALS * GENFACENORMALS * GENVERTEXNORMALS * REMOVEVC * SPLITLARGEMESHES * PRETRANSFORMVERTICES * LIMITBONEWEIGHTS * VALIDATEDS * IMPROVECACHELOCALITY * FIXINFACINGNORMALS * REMOVE_REDUNDANTMATERIALS * OPTIMIZEGRAPH * SORTBYPTYPE * FINDINVALIDDATA * TRANSFORMTEXCOORDS * GENUVCOORDS * ENTITYMESHBUILDER * EMBEDTEXTURES * MAKELEFTHANDED * FLIPUVS * FLIPWINDINGORDER * OPTIMIZEMESHES * OPTIMIZEANIMS * OPTIMIZEGRAPH * GENENTITYMESHES * FIXTEXTUREPATHS * GENBOUNDINGBOXES */ ////////////////////////////////////////////////////////////////////////// #ifdef _WIN32 #undef ASSIMP_API ////////////////////////////////////////////////////////////////////////// /* Define 'ASSIMP_BUILD_DLL_EXPORT' to build a DLL of the library */ ////////////////////////////////////////////////////////////////////////// #ifdef ASSIMP_BUILD_DLL_EXPORT #define ASSIMP_API __declspec(dllexport) #define ASSIMP_API_WINONLY __declspec(dllexport) ////////////////////////////////////////////////////////////////////////// /* Define 'ASSIMP_DLL' before including Assimp to link to ASSIMP in * an external DLL under Windows. Default is static linkage. */ ////////////////////////////////////////////////////////////////////////// #elif (defined ASSIMP_DLL) #define ASSIMP_API __declspec(dllimport) #define ASSIMP_API_WINONLY __declspec(dllimport) #else #define ASSIMP_API #define ASSIMP_API_WINONLY #endif #elif defined(SWIG) /* Do nothing, the relevant defines are all in AssimpSwigPort.i */ #else #define ASSIMP_API __attribute__((visibility("default"))) #define ASSIMP_API_WINONLY #endif // _WIN32 #ifdef _MSC_VER #pragma warning(disable : 4521 4512 4714 4127 4351 4510) #ifdef ASSIMP_BUILD_DLL_EXPORT #pragma warning(disable : 4251) #endif /* Force the compiler to inline a function, if possible */ #define AI_FORCE_INLINE inline /* Tells the compiler that a function never returns. Used in code analysis * to skip dead paths (e.g. after an assertion evaluated to false). */ #define AI_WONT_RETURN __declspec(noreturn) #elif defined(SWIG) /* Do nothing, the relevant defines are all in AssimpSwigPort.i */ #else #define AI_WONT_RETURN #define AI_FORCE_INLINE inline #endif // (defined _MSC_VER) #ifdef __GNUC__ # define AI_WONT_RETURN_SUFFIX __attribute__((noreturn)) #elif _MSC_VER #if defined(__clang__) # define AI_WONT_RETURN_SUFFIX __attribute__((noreturn)) #else # define AI_WONT_RETURN_SUFFIX #endif #else # define AI_WONT_RETURN_SUFFIX #endif // (defined __clang__) #ifdef __cplusplus /* No explicit 'struct' and 'enum' tags for C++, this keeps showing up * in doxydocs. */ #define C_STRUCT #define C_ENUM #else ////////////////////////////////////////////////////////////////////////// /* To build the documentation, make sure ASSIMP_DOXYGEN_BUILD * is defined by Doxygen's preprocessor. The corresponding * entries in the DOXYFILE are: */ ////////////////////////////////////////////////////////////////////////// #if 0 ENABLE_PREPROCESSING = YES MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = PREDEFINED = ASSIMP_DOXYGEN_BUILD=1 EXPAND_AS_DEFINED = C_STRUCT C_ENUM SKIP_FUNCTION_MACROS = YES #endif ////////////////////////////////////////////////////////////////////////// /* Doxygen gets confused if we use c-struct typedefs to avoid * the explicit 'struct' notation. This trick here has the same * effect as the TYPEDEF_HIDES_STRUCT option, but we don't need * to typedef all structs/enums. */ ////////////////////////////////////////////////////////////////////////// #if (defined ASSIMP_DOXYGEN_BUILD) #define C_STRUCT #define C_ENUM #else #define C_STRUCT struct #define C_ENUM enum #endif #endif #if (defined(__BORLANDC__) || defined(__BCPLUSPLUS__)) #error Currently, Borland is unsupported. Feel free to port Assimp. #endif ////////////////////////////////////////////////////////////////////////// /* Define ASSIMP_BUILD_SINGLETHREADED to compile assimp * without threading support. The library doesn't utilize * threads then and is itself not threadsafe. */ ////////////////////////////////////////////////////////////////////////// #ifndef ASSIMP_BUILD_SINGLETHREADED #define ASSIMP_BUILD_SINGLETHREADED #endif #if defined(_DEBUG) || !defined(NDEBUG) #define ASSIMP_BUILD_DEBUG #endif ////////////////////////////////////////////////////////////////////////// /* Define ASSIMP_DOUBLE_PRECISION to compile assimp * with double precision support (64-bit). */ ////////////////////////////////////////////////////////////////////////// #ifdef ASSIMP_DOUBLE_PRECISION typedef double ai_real; typedef signed long long int ai_int; typedef unsigned long long int ai_uint; #ifndef ASSIMP_AI_REAL_TEXT_PRECISION #define ASSIMP_AI_REAL_TEXT_PRECISION 17 #endif // ASSIMP_AI_REAL_TEXT_PRECISION #else // ASSIMP_DOUBLE_PRECISION typedef float ai_real; typedef signed int ai_int; typedef unsigned int ai_uint; #ifndef ASSIMP_AI_REAL_TEXT_PRECISION #define ASSIMP_AI_REAL_TEXT_PRECISION 9 #endif // ASSIMP_AI_REAL_TEXT_PRECISION #endif // ASSIMP_DOUBLE_PRECISION ////////////////////////////////////////////////////////////////////////// /* Useful constants */ ////////////////////////////////////////////////////////////////////////// /* This is PI. Hi PI. */ #define AI_MATH_PI (3.141592653589793238462643383279) #define AI_MATH_TWO_PI (AI_MATH_PI * 2.0) #define AI_MATH_HALF_PI (AI_MATH_PI * 0.5) /* And this is to avoid endless casts to float */ #define AI_MATH_PI_F (3.1415926538f) #define AI_MATH_TWO_PI_F (AI_MATH_PI_F * 2.0f) #define AI_MATH_HALF_PI_F (AI_MATH_PI_F * 0.5f) /* Tiny macro to convert from radians to degrees and back */ #define AI_DEG_TO_RAD(x) ((x) * (ai_real) 0.0174532925) #define AI_RAD_TO_DEG(x) ((x) * (ai_real) 57.2957795) /* Numerical limits */ #ifdef __cplusplus constexpr ai_real ai_epsilon = (ai_real) 1e-6; #else #define ai_epsilon ((ai_real)1e-6) #endif /* Support for big-endian builds */ #if defined(__BYTE_ORDER__) #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) #if !defined(__BIG_ENDIAN__) #define __BIG_ENDIAN__ #endif #else /* little endian */ #if defined(__BIG_ENDIAN__) #undef __BIG_ENDIAN__ #endif #endif #endif #if defined(__BIG_ENDIAN__) #define AI_BUILD_BIG_ENDIAN #endif /** * To avoid running out of memory * This can be adjusted for specific use cases * It's NOT a total limit, just a limit for individual allocations */ #define AI_MAX_ALLOC(type) ((256U * 1024 * 1024) / sizeof(type)) #ifndef _MSC_VER #if __cplusplus >= 201103L // C++11 #define AI_NO_EXCEPT noexcept #else #define AI_NO_EXCEPT #endif #else #if (_MSC_VER >= 1915) #define AI_NO_EXCEPT noexcept #else #define AI_NO_EXCEPT #endif #endif // _MSC_VER /** * Helper macro to set a pointer to NULL in debug builds */ #if (defined ASSIMP_BUILD_DEBUG) #define AI_DEBUG_INVALIDATE_PTR(x) x = NULL; #else #define AI_DEBUG_INVALIDATE_PTR(x) #endif #define AI_COUNT_OF(X) (sizeof(X) / sizeof((X)[0])) #endif // !! AI_DEFINES_H_INC
11,072
C
31.00289
86
0.624368
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/GltfMaterial.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file GltfMaterial.h * @brief glTF-specific material macros * These will be made generic at some future date */ #ifndef AI_GLTFMATERIAL_H_INC #define AI_GLTFMATERIAL_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/material.h> #define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE aiTextureType_UNKNOWN, 0 #define AI_MATKEY_GLTF_ALPHAMODE "$mat.gltf.alphaMode", 0, 0 #define AI_MATKEY_GLTF_ALPHACUTOFF "$mat.gltf.alphaCutoff", 0, 0 #define _AI_MATKEY_GLTF_MAPPINGNAME_BASE "$tex.mappingname" #define _AI_MATKEY_GLTF_MAPPINGID_BASE "$tex.mappingid" #define _AI_MATKEY_GLTF_MAPPINGFILTER_MAG_BASE "$tex.mappingfiltermag" #define _AI_MATKEY_GLTF_MAPPINGFILTER_MIN_BASE "$tex.mappingfiltermin" #define _AI_MATKEY_GLTF_SCALE_BASE "$tex.scale" #define _AI_MATKEY_GLTF_STRENGTH_BASE "$tex.strength" #define AI_MATKEY_GLTF_MAPPINGNAME(type, N) _AI_MATKEY_GLTF_MAPPINGNAME_BASE, type, N #define AI_MATKEY_GLTF_MAPPINGID(type, N) _AI_MATKEY_GLTF_MAPPINGID_BASE, type, N #define AI_MATKEY_GLTF_MAPPINGFILTER_MAG(type, N) _AI_MATKEY_GLTF_MAPPINGFILTER_MAG_BASE, type, N #define AI_MATKEY_GLTF_MAPPINGFILTER_MIN(type, N) _AI_MATKEY_GLTF_MAPPINGFILTER_MIN_BASE, type, N #define AI_MATKEY_GLTF_TEXTURE_SCALE(type, N) _AI_MATKEY_GLTF_SCALE_BASE, type, N #define AI_MATKEY_GLTF_TEXTURE_STRENGTH(type, N) _AI_MATKEY_GLTF_STRENGTH_BASE, type, N #endif
3,194
C
41.599999
97
0.727614
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/Importer.hpp
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file Importer.hpp * @brief Defines the C++-API to the Open Asset Import Library. */ #pragma once #ifndef AI_ASSIMP_HPP_INC #define AI_ASSIMP_HPP_INC #ifdef __GNUC__ #pragma GCC system_header #endif #ifndef __cplusplus #error This header requires C++ to be used. Use assimp.h for plain C. #endif // __cplusplus // Public ASSIMP data structures #include <assimp/types.h> #include <exception> namespace Assimp { // ======================================================================= // Public interface to Assimp class Importer; class IOStream; class IOSystem; class ProgressHandler; // ======================================================================= // Plugin development // // Include the following headers for the declarations: // BaseImporter.h // BaseProcess.h class BaseImporter; class BaseProcess; class SharedPostProcessInfo; class BatchLoader; // ======================================================================= // Holy stuff, only for members of the high council of the Jedi. class ImporterPimpl; } // namespace Assimp #define AI_PROPERTY_WAS_NOT_EXISTING 0xffffffff struct aiScene; // importerdesc.h struct aiImporterDesc; /** @namespace Assimp Assimp's CPP-API and all internal APIs */ namespace Assimp { // ---------------------------------------------------------------------------------- /** CPP-API: The Importer class forms an C++ interface to the functionality of the * Open Asset Import Library. * * Create an object of this class and call ReadFile() to import a file. * If the import succeeds, the function returns a pointer to the imported data. * The data remains property of the object, it is intended to be accessed * read-only. The imported data will be destroyed along with the Importer * object. If the import fails, ReadFile() returns a nullptr pointer. In this * case you can retrieve a human-readable error description be calling * GetErrorString(). You can call ReadFile() multiple times with a single Importer * instance. Actually, constructing Importer objects involves quite many * allocations and may take some time, so it's better to reuse them as often as * possible. * * If you need the Importer to do custom file handling to access the files, * implement IOSystem and IOStream and supply an instance of your custom * IOSystem implementation by calling SetIOHandler() before calling ReadFile(). * If you do not assign a custom IO handler, a default handler using the * standard C++ IO logic will be used. * * @note One Importer instance is not thread-safe. If you use multiple * threads for loading, each thread should maintain its own Importer instance. */ class ASSIMP_API Importer { public: /** * @brief The upper limit for hints. */ static const unsigned int MaxLenHint = 200; public: // ------------------------------------------------------------------- /** Constructor. Creates an empty importer object. * * Call ReadFile() to start the import process. The configuration * property table is initially empty. */ Importer(); // ------------------------------------------------------------------- /** Copy constructor. * * This copies the configuration properties of another Importer. * If this Importer owns a scene it won't be copied. * Call ReadFile() to start the import process. */ Importer(const Importer &other) = delete; // ------------------------------------------------------------------- /** Assignment operator has been deleted */ Importer &operator=(const Importer &) = delete; // ------------------------------------------------------------------- /** Destructor. The object kept ownership of the imported data, * which now will be destroyed along with the object. */ ~Importer(); // ------------------------------------------------------------------- /** Registers a new loader. * * @param pImp Importer to be added. The Importer instance takes * ownership of the pointer, so it will be automatically deleted * with the Importer instance. * @return AI_SUCCESS if the loader has been added. The registration * fails if there is already a loader for a specific file extension. */ aiReturn RegisterLoader(BaseImporter *pImp); // ------------------------------------------------------------------- /** Unregisters a loader. * * @param pImp Importer to be unregistered. * @return AI_SUCCESS if the loader has been removed. The function * fails if the loader is currently in use (this could happen * if the #Importer instance is used by more than one thread) or * if it has not yet been registered. */ aiReturn UnregisterLoader(BaseImporter *pImp); // ------------------------------------------------------------------- /** Registers a new post-process step. * * At the moment, there's a small limitation: new post processing * steps are added to end of the list, or in other words, executed * last, after all built-in steps. * @param pImp Post-process step to be added. The Importer instance * takes ownership of the pointer, so it will be automatically * deleted with the Importer instance. * @return AI_SUCCESS if the step has been added correctly. */ aiReturn RegisterPPStep(BaseProcess *pImp); // ------------------------------------------------------------------- /** Unregisters a post-process step. * * @param pImp Step to be unregistered. * @return AI_SUCCESS if the step has been removed. The function * fails if the step is currently in use (this could happen * if the #Importer instance is used by more than one thread) or * if it has not yet been registered. */ aiReturn UnregisterPPStep(BaseProcess *pImp); // ------------------------------------------------------------------- /** Set an integer configuration property. * @param szName Name of the property. All supported properties * are defined in the aiConfig.g header (all constants share the * prefix AI_CONFIG_XXX and are simple strings). * @param iValue New value of the property * @return true if the property was set before. The new value replaces * the previous value in this case. * @note Property of different types (float, int, string ..) are kept * on different stacks, so calling SetPropertyInteger() for a * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ bool SetPropertyInteger(const char *szName, int iValue); // ------------------------------------------------------------------- /** Set a boolean configuration property. Boolean properties * are stored on the integer stack internally so it's possible * to set them via #SetPropertyBool and query them with * #GetPropertyBool and vice versa. * @see SetPropertyInteger() */ bool SetPropertyBool(const char *szName, bool value) { return SetPropertyInteger(szName, value); } // ------------------------------------------------------------------- /** Set a floating-point configuration property. * @see SetPropertyInteger() */ bool SetPropertyFloat(const char *szName, ai_real fValue); // ------------------------------------------------------------------- /** Set a string configuration property. * @see SetPropertyInteger() */ bool SetPropertyString(const char *szName, const std::string &sValue); // ------------------------------------------------------------------- /** Set a matrix configuration property. * @see SetPropertyInteger() */ bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); // ------------------------------------------------------------------- /** Set a pointer configuration property. * @see SetPropertyInteger() */ bool SetPropertyPointer(const char *szName, void *sValue); // ------------------------------------------------------------------- /** Get a configuration property. * @param szName Name of the property. All supported properties * are defined in the aiConfig.g header (all constants share the * prefix AI_CONFIG_XXX). * @param iErrorReturn Value that is returned if the property * is not found. * @return Current value of the property * @note Property of different types (float, int, string ..) are kept * on different lists, so calling SetPropertyInteger() for a * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ int GetPropertyInteger(const char *szName, int iErrorReturn = 0xffffffff) const; // ------------------------------------------------------------------- /** Get a boolean configuration property. Boolean properties * are stored on the integer stack internally so it's possible * to set them via #SetPropertyBool and query them with * #GetPropertyBool and vice versa. * @see GetPropertyInteger() */ bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const { return GetPropertyInteger(szName, bErrorReturn) != 0; } // ------------------------------------------------------------------- /** Get a floating-point configuration property * @see GetPropertyInteger() */ ai_real GetPropertyFloat(const char *szName, ai_real fErrorReturn = 10e10) const; // ------------------------------------------------------------------- /** Get a string configuration property * * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ std::string GetPropertyString(const char *szName, const std::string &sErrorReturn = std::string()) const; // ------------------------------------------------------------------- /** Get a matrix configuration property * * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; // ------------------------------------------------------------------- /** Get a pointer configuration property * * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ void* GetPropertyPointer(const char *szName, void *sErrorReturn = nullptr) const; // ------------------------------------------------------------------- /** Supplies a custom IO handler to the importer to use to open and * access files. If you need the importer to use custom IO logic to * access the files, you need to provide a custom implementation of * IOSystem and IOFile to the importer. Then create an instance of * your custom IOSystem implementation and supply it by this function. * * The Importer takes ownership of the object and will destroy it * afterwards. The previously assigned handler will be deleted. * Pass nullptr to take again ownership of your IOSystem and reset Assimp * to use its default implementation. * * @param pIOHandler The IO handler to be used in all file accesses * of the Importer. */ void SetIOHandler(IOSystem *pIOHandler); // ------------------------------------------------------------------- /** Retrieves the IO handler that is currently set. * You can use #IsDefaultIOHandler() to check whether the returned * interface is the default IO handler provided by ASSIMP. The default * handler is active as long the application doesn't supply its own * custom IO handler via #SetIOHandler(). * @return A valid IOSystem interface, never nullptr. */ IOSystem *GetIOHandler() const; // ------------------------------------------------------------------- /** Checks whether a default IO handler is active * A default handler is active as long the application doesn't * supply its own custom IO handler via #SetIOHandler(). * @return true by default */ bool IsDefaultIOHandler() const; // ------------------------------------------------------------------- /** Supplies a custom progress handler to the importer. This * interface exposes an #Update() callback, which is called * more or less periodically (please don't sue us if it * isn't as periodically as you'd like it to have ...). * This can be used to implement progress bars and loading * timeouts. * @param pHandler Progress callback interface. Pass nullptr to * disable progress reporting. * @note Progress handlers can be used to abort the loading * at almost any time.*/ void SetProgressHandler(ProgressHandler *pHandler); // ------------------------------------------------------------------- /** Retrieves the progress handler that is currently set. * You can use #IsDefaultProgressHandler() to check whether the returned * interface is the default handler provided by ASSIMP. The default * handler is active as long the application doesn't supply its own * custom handler via #SetProgressHandler(). * @return A valid ProgressHandler interface, never nullptr. */ ProgressHandler *GetProgressHandler() const; // ------------------------------------------------------------------- /** Checks whether a default progress handler is active * A default handler is active as long the application doesn't * supply its own custom progress handler via #SetProgressHandler(). * @return true by default */ bool IsDefaultProgressHandler() const; // ------------------------------------------------------------------- /** @brief Check whether a given set of post-processing flags * is supported. * * Some flags are mutually exclusive, others are probably * not available because your excluded them from your * Assimp builds. Calling this function is recommended if * you're unsure. * * @param pFlags Bitwise combination of the aiPostProcess flags. * @return true if this flag combination is fine. */ bool ValidateFlags(unsigned int pFlags) const; // ------------------------------------------------------------------- /** Reads the given file and returns its contents if successful. * * If the call succeeds, the contents of the file are returned as a * pointer to an aiScene object. The returned data is intended to be * read-only, the importer object keeps ownership of the data and will * destroy it upon destruction. If the import fails, nullptr is returned. * A human-readable error description can be retrieved by calling * GetErrorString(). The previous scene will be deleted during this call. * @param pFile Path and filename to the file to be imported. * @param pFlags Optional post processing steps to be executed after * a successful import. Provide a bitwise combination of the * #aiPostProcessSteps flags. If you wish to inspect the imported * scene first in order to fine-tune your post-processing setup, * consider to use #ApplyPostProcessing(). * @return A pointer to the imported data, nullptr if the import failed. * The pointer to the scene remains in possession of the Importer * instance. Use GetOrphanedScene() to take ownership of it. * * @note Assimp is able to determine the file format of a file * automatically. */ const aiScene *ReadFile( const char *pFile, unsigned int pFlags); // ------------------------------------------------------------------- /** Reads the given file from a memory buffer and returns its * contents if successful. * * If the call succeeds, the contents of the file are returned as a * pointer to an aiScene object. The returned data is intended to be * read-only, the importer object keeps ownership of the data and will * destroy it upon destruction. If the import fails, nullptr is returned. * A human-readable error description can be retrieved by calling * GetErrorString(). The previous scene will be deleted during this call. * Calling this method doesn't affect the active IOSystem. * @param pBuffer Pointer to the file data * @param pLength Length of pBuffer, in bytes * @param pFlags Optional post processing steps to be executed after * a successful import. Provide a bitwise combination of the * #aiPostProcessSteps flags. If you wish to inspect the imported * scene first in order to fine-tune your post-processing setup, * consider to use #ApplyPostProcessing(). * @param pHint An additional hint to the library. If this is a non * empty string, the library looks for a loader to support * the file extension specified by pHint and passes the file to * the first matching loader. If this loader is unable to completely * the request, the library continues and tries to determine the * file format on its own, a task that may or may not be successful. * Check the return value, and you'll know ... * @return A pointer to the imported data, nullptr if the import failed. * The pointer to the scene remains in possession of the Importer * instance. Use GetOrphanedScene() to take ownership of it. * * @note This is a straightforward way to decode models from memory * buffers, but it doesn't handle model formats that spread their * data across multiple files or even directories. Examples include * OBJ or MD3, which outsource parts of their material info into * external scripts. If you need full functionality, provide * a custom IOSystem to make Assimp find these files and use * the regular ReadFile() API. */ const aiScene *ReadFileFromMemory( const void *pBuffer, size_t pLength, unsigned int pFlags, const char *pHint = ""); // ------------------------------------------------------------------- /** Apply post-processing to an already-imported scene. * * This is strictly equivalent to calling #ReadFile() with the same * flags. However, you can use this separate function to inspect * the imported scene first to fine-tune your post-processing setup. * @param pFlags Provide a bitwise combination of the * #aiPostProcessSteps flags. * @return A pointer to the post-processed data. This is still the * same as the pointer returned by #ReadFile(). However, if * post-processing fails, the scene could now be nullptr. * That's quite a rare case, post processing steps are not really * designed to 'fail'. To be exact, the #aiProcess_ValidateDS * flag is currently the only post processing step which can actually * cause the scene to be reset to nullptr. * * @note The method does nothing if no scene is currently bound * to the #Importer instance. */ const aiScene *ApplyPostProcessing(unsigned int pFlags); const aiScene *ApplyCustomizedPostProcessing(BaseProcess *rootProcess, bool requestValidation); // ------------------------------------------------------------------- /** @brief Reads the given file and returns its contents if successful. * * This function is provided for backward compatibility. * See the const char* version for detailed docs. * @see ReadFile(const char*, pFlags) */ const aiScene *ReadFile( const std::string &pFile, unsigned int pFlags); // ------------------------------------------------------------------- /** Frees the current scene. * * The function does nothing if no scene has previously been * read via ReadFile(). FreeScene() is called automatically by the * destructor and ReadFile() itself. */ void FreeScene(); // ------------------------------------------------------------------- /** Returns an error description of an error that occurred in ReadFile(). * * Returns an empty string if no error occurred. * @return A description of the last error, an empty string if no * error occurred. The string is never nullptr. * * @note The returned function remains valid until one of the * following methods is called: #ReadFile(), #FreeScene(). */ const char *GetErrorString() const; // ------------------------------------------------------------------- /** Returns an exception if one occurred during import. * * @return The last exception which occurred. * * @note The returned value remains valid until one of the * following methods is called: #ReadFile(), #FreeScene(). */ const std::exception_ptr& GetException() const; // ------------------------------------------------------------------- /** Returns the scene loaded by the last successful call to ReadFile() * * @return Current scene or nullptr if there is currently no scene loaded */ const aiScene *GetScene() const; // ------------------------------------------------------------------- /** Returns the scene loaded by the last successful call to ReadFile() * and releases the scene from the ownership of the Importer * instance. The application is now responsible for deleting the * scene. Any further calls to GetScene() or GetOrphanedScene() * will return nullptr - until a new scene has been loaded via ReadFile(). * * @return Current scene or nullptr if there is currently no scene loaded * @note Use this method with maximal caution, and only if you have to. * By design, aiScene's are exclusively maintained, allocated and * deallocated by Assimp and no one else. The reasoning behind this * is the golden rule that deallocations should always be done * by the module that did the original allocation because heaps * are not necessarily shared. GetOrphanedScene() enforces you * to delete the returned scene by yourself, but this will only * be fine if and only if you're using the same heap as assimp. * On Windows, it's typically fine provided everything is linked * against the multithreaded-dll version of the runtime library. * It will work as well for static linkage with Assimp.*/ aiScene *GetOrphanedScene(); // ------------------------------------------------------------------- /** Returns whether a given file extension is supported by ASSIMP. * * @param szExtension Extension to be checked. * Must include a trailing dot '.'. Example: ".3ds", ".md3". * Cases-insensitive. * @return true if the extension is supported, false otherwise */ bool IsExtensionSupported(const char *szExtension) const; // ------------------------------------------------------------------- /** @brief Returns whether a given file extension is supported by ASSIMP. * * This function is provided for backward compatibility. * See the const char* version for detailed and up-to-date docs. * @see IsExtensionSupported(const char*) */ inline bool IsExtensionSupported(const std::string &szExtension) const; // ------------------------------------------------------------------- /** Get a full list of all file extensions supported by ASSIMP. * * If a file extension is contained in the list this does of course not * mean that ASSIMP is able to load all files with this extension --- * it simply means there is an importer loaded which claims to handle * files with this file extension. * @param szOut String to receive the extension list. * Format of the list: "*.3ds;*.obj;*.dae". This is useful for * use with the WinAPI call GetOpenFileName(Ex). */ void GetExtensionList(aiString &szOut) const; // ------------------------------------------------------------------- /** @brief Get a full list of all file extensions supported by ASSIMP. * * This function is provided for backward compatibility. * See the aiString version for detailed and up-to-date docs. * @see GetExtensionList(aiString&)*/ inline void GetExtensionList(std::string &szOut) const; // ------------------------------------------------------------------- /** Get the number of importers currently registered with Assimp. */ size_t GetImporterCount() const; // ------------------------------------------------------------------- /** Get meta data for the importer corresponding to a specific index.. * * For the declaration of #aiImporterDesc, include <assimp/importerdesc.h>. * @param index Index to query, must be within [0,GetImporterCount()) * @return Importer meta data structure, nullptr if the index does not * exist or if the importer doesn't offer meta information ( * importers may do this at the cost of being hated by their peers).*/ const aiImporterDesc *GetImporterInfo(size_t index) const; // ------------------------------------------------------------------- /** Find the importer corresponding to a specific index. * * @param index Index to query, must be within [0,GetImporterCount()) * @return Importer instance. nullptr if the index does not * exist. */ BaseImporter *GetImporter(size_t index) const; // ------------------------------------------------------------------- /** Find the importer corresponding to a specific file extension. * * This is quite similar to #IsExtensionSupported except a * BaseImporter instance is returned. * @param szExtension Extension to check for. The following formats * are recognized (BAH being the file extension): "BAH" (comparison * is case-insensitive), ".bah", "*.bah" (wild card and dot * characters at the beginning of the extension are skipped). * @return nullptr if no importer is found*/ BaseImporter *GetImporter(const char *szExtension) const; // ------------------------------------------------------------------- /** Find the importer index corresponding to a specific file extension. * * @param szExtension Extension to check for. The following formats * are recognized (BAH being the file extension): "BAH" (comparison * is case-insensitive), ".bah", "*.bah" (wild card and dot * characters at the beginning of the extension are skipped). * @return (size_t)-1 if no importer is found */ size_t GetImporterIndex(const char *szExtension) const; // ------------------------------------------------------------------- /** Returns the storage allocated by ASSIMP to hold the scene data * in memory. * * This refers to the currently loaded file, see #ReadFile(). * @param in Data structure to be filled. * @note The returned memory statistics refer to the actual * size of the use data of the aiScene. Heap-related overhead * is (naturally) not included.*/ void GetMemoryRequirements(aiMemoryInfo &in) const; // ------------------------------------------------------------------- /** Enables "extra verbose" mode. * * 'Extra verbose' means the data structure is validated after *every* * single post processing step to make sure everyone modifies the data * structure in a well-defined manner. This is a debug feature and not * intended for use in production environments. */ void SetExtraVerbose(bool bDo); // ------------------------------------------------------------------- /** Private, do not use. */ ImporterPimpl *Pimpl() { return pimpl; } const ImporterPimpl *Pimpl() const { return pimpl; } protected: // Just because we don't want you to know how we're hacking around. ImporterPimpl *pimpl; }; //! class Importer // ---------------------------------------------------------------------------- // For compatibility, the interface of some functions taking a std::string was // changed to const char* to avoid crashes between binary incompatible STL // versions. This code her is inlined, so it shouldn't cause any problems. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- AI_FORCE_INLINE const aiScene *Importer::ReadFile(const std::string &pFile, unsigned int pFlags) { return ReadFile(pFile.c_str(), pFlags); } // ---------------------------------------------------------------------------- AI_FORCE_INLINE void Importer::GetExtensionList(std::string &szOut) const { aiString s; GetExtensionList(s); szOut = s.data; } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool Importer::IsExtensionSupported(const std::string &szExtension) const { return IsExtensionSupported(szExtension.c_str()); } } // namespace Assimp #endif // AI_ASSIMP_HPP_INC
31,289
C++
44.612245
99
0.596536
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/SpatialSort.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** Small helper classes to optimise finding vertizes close to a given location */ #pragma once #ifndef AI_SPATIALSORT_H_INC #define AI_SPATIALSORT_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #include <assimp/types.h> #include <vector> #include <limits> namespace Assimp { // ------------------------------------------------------------------------------------------------ /** A little helper class to quickly find all vertices in the epsilon environment of a given * position. Construct an instance with an array of positions. The class stores the given positions * by their indices and sorts them by their distance to an arbitrary chosen plane. * You can then query the instance for all vertices close to a given position in an average O(log n) * time, with O(n) worst case complexity when all vertices lay on the plane. The plane is chosen * so that it avoids common planes in usual data sets. */ // ------------------------------------------------------------------------------------------------ class ASSIMP_API SpatialSort { public: SpatialSort(); // ------------------------------------------------------------------------------------ /** Constructs a spatially sorted representation from the given position array. * Supply the positions in its layout in memory, the class will only refer to them * by index. * @param pPositions Pointer to the first position vector of the array. * @param pNumPositions Number of vectors to expect in that array. * @param pElementOffset Offset in bytes from the beginning of one vector in memory * to the beginning of the next vector. */ SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset); /** Destructor */ ~SpatialSort(); // ------------------------------------------------------------------------------------ /** Sets the input data for the SpatialSort. This replaces existing data, if any. * The new data receives new indices in ascending order. * * @param pPositions Pointer to the first position vector of the array. * @param pNumPositions Number of vectors to expect in that array. * @param pElementOffset Offset in bytes from the beginning of one vector in memory * to the beginning of the next vector. * @param pFinalize Specifies whether the SpatialSort's internal representation * is finalized after the new data has been added. Finalization is * required in order to use #FindPosition() or #GenerateMappingTable(). * If you don't finalize yet, you can use #Append() to add data from * other sources.*/ void Fill(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset, bool pFinalize = true); // ------------------------------------------------------------------------------------ /** Same as #Fill(), except the method appends to existing data in the #SpatialSort. */ void Append(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset, bool pFinalize = true); // ------------------------------------------------------------------------------------ /** Finalize the spatial hash data structure. This can be useful after * multiple calls to #Append() with the pFinalize parameter set to false. * This is finally required before one of #FindPositions() and #GenerateMappingTable() * can be called to query the spatial sort.*/ void Finalize(); // ------------------------------------------------------------------------------------ /** Returns an iterator for all positions close to the given position. * @param pPosition The position to look for vertices. * @param pRadius Maximal distance from the position a vertex may have to be counted in. * @param poResults The container to store the indices of the found positions. * Will be emptied by the call so it may contain anything. * @return An iterator to iterate over all vertices in the given area.*/ void FindPositions(const aiVector3D &pPosition, ai_real pRadius, std::vector<unsigned int> &poResults) const; // ------------------------------------------------------------------------------------ /** Fills an array with indices of all positions identical to the given position. In * opposite to FindPositions(), not an epsilon is used but a (very low) tolerance of * four floating-point units. * @param pPosition The position to look for vertices. * @param poResults The container to store the indices of the found positions. * Will be emptied by the call so it may contain anything.*/ void FindIdenticalPositions(const aiVector3D &pPosition, std::vector<unsigned int> &poResults) const; // ------------------------------------------------------------------------------------ /** Compute a table that maps each vertex ID referring to a spatially close * enough position to the same output ID. Output IDs are assigned in ascending order * from 0...n. * @param fill Will be filled with numPositions entries. * @param pRadius Maximal distance from the position a vertex may have to * be counted in. * @return Number of unique vertices (n). */ unsigned int GenerateMappingTable(std::vector<unsigned int> &fill, ai_real pRadius) const; protected: /** Return the distance to the sorting plane. */ ai_real CalculateDistance(const aiVector3D &pPosition) const; protected: /** Normal of the sorting plane, normalized. */ aiVector3D mPlaneNormal; /** The centroid of the positions, which is used as a point on the sorting plane * when calculating distance. This value is calculated in Finalize. */ aiVector3D mCentroid; /** An entry in a spatially sorted position array. Consists of a vertex index, * its position and its pre-calculated distance from the reference plane */ struct Entry { unsigned int mIndex; ///< The vertex referred by this entry aiVector3D mPosition; ///< Position /// Distance of this vertex to the sorting plane. This is set by Finalize. ai_real mDistance; Entry() AI_NO_EXCEPT : mIndex(std::numeric_limits<unsigned int>::max()), mPosition(), mDistance(std::numeric_limits<ai_real>::max()) { // empty } Entry(unsigned int pIndex, const aiVector3D &pPosition) : mIndex(pIndex), mPosition(pPosition), mDistance(std::numeric_limits<ai_real>::max()) { // empty } bool operator<(const Entry &e) const { return mDistance < e.mDistance; } }; // all positions, sorted by distance to the sorting plane std::vector<Entry> mPositions; /// false until the Finalize method is called. bool mFinalized; }; } // end of namespace Assimp #endif // AI_SPATIALSORT_H_INC
8,768
C
44.910995
102
0.631843
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/TinyFormatter.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file TinyFormatter.h * @brief Utility to format log messages more easily. Introduced * to get rid of the boost::format dependency. Much slinker, * basically just extends stringstream. */ #pragma once #ifndef INCLUDED_TINY_FORMATTER_H #define INCLUDED_TINY_FORMATTER_H #ifdef __GNUC__ # pragma GCC system_header #endif #include <sstream> namespace Assimp { namespace Formatter { // ------------------------------------------------------------------------------------------------ /** stringstream utility. Usage: * @code * void writelog(const std::string&s); * void writelog(const std::wstring&s); * ... * writelog(format()<< "hi! this is a number: " << 4); * writelog(wformat()<< L"hi! this is a number: " << 4); * * @endcode */ template < typename T, typename CharTraits = std::char_traits<T>, typename Allocator = std::allocator<T> > class basic_formatter { public: typedef class std::basic_string<T,CharTraits,Allocator> string; typedef class std::basic_ostringstream<T,CharTraits,Allocator> stringstream; basic_formatter() { // empty } /* Allow basic_formatter<T>'s to be used almost interchangeably * with std::(w)string or const (w)char* arguments because the * conversion c'tor is called implicitly. */ template <typename TT> basic_formatter(const TT& sin) { underlying << sin; } // Same problem as the copy constructor below, but with root cause is that stream move // is not permitted on older GCC versions. Small performance impact on those platforms. #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 9) basic_formatter(basic_formatter&& other) { underlying << (string)other; } #else basic_formatter(basic_formatter&& other) : underlying(std::move(other.underlying)) { } #endif // The problem described here: // https://sourceforge.net/tracker/?func=detail&atid=1067632&aid=3358562&group_id=226462 // can also cause trouble here. Apparently, older gcc versions sometimes copy temporaries // being bound to const ref& function parameters. Copying streams is not permitted, though. // This workaround avoids this by manually specifying a copy ctor. #if !defined(__GNUC__) || !defined(__APPLE__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) explicit basic_formatter(const basic_formatter& other) { underlying << (string)other; } #endif operator string () const { return underlying.str(); } /* note - this is declared const because binding temporaries does only * work for const references, so many function prototypes will * include const basic_formatter<T>& s but might still want to * modify the formatted string without the need for a full copy.*/ template <typename TToken, typename std::enable_if<!std::is_base_of<std::exception, TToken>::value>::type * = nullptr> const basic_formatter &operator<<(const TToken &s) const { underlying << s; return *this; } template <typename TToken, typename std::enable_if<std::is_base_of<std::exception, TToken>::value>::type * = nullptr> const basic_formatter &operator<<(const TToken &s) const { underlying << s.what(); return *this; } template <typename TToken, typename std::enable_if<!std::is_base_of<std::exception, TToken>::value>::type * = nullptr> basic_formatter &operator<<(const TToken &s) { underlying << s; return *this; } template <typename TToken, typename std::enable_if<std::is_base_of<std::exception, TToken>::value>::type * = nullptr> basic_formatter &operator<<(const TToken &s) { underlying << s.what(); return *this; } // comma operator overloaded as well, choose your preferred way. template <typename TToken> const basic_formatter& operator, (const TToken& s) const { *this << s; return *this; } template <typename TToken> basic_formatter& operator, (const TToken& s) { *this << s; return *this; } // Fix for MSVC8 // See https://sourceforge.net/projects/assimp/forums/forum/817654/topic/4372824 template <typename TToken> basic_formatter& operator, (TToken& s) { *this << s; return *this; } private: mutable stringstream underlying; }; typedef basic_formatter< char > format; typedef basic_formatter< wchar_t > wformat; } // ! namespace Formatter } // ! namespace Assimp #endif
6,244
C
33.313187
122
0.664638
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/LineSplitter.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file LineSplitter.h * @brief LineSplitter, a helper class to iterate through all lines * of a file easily. Works with StreamReader. */ #pragma once #ifndef INCLUDED_LINE_SPLITTER_H #define INCLUDED_LINE_SPLITTER_H #ifdef __GNUC__ # pragma GCC system_header #endif #include <stdexcept> #include <assimp/StreamReader.h> #include <assimp/ParsingUtils.h> namespace Assimp { // ------------------------------------------------------------------------------------------------ /** Usage: @code for(LineSplitter splitter(stream);splitter;++splitter) { if (*splitter == "hi!") { ... } else if (splitter->substr(0,5) == "hello") { ... // access the third token in the line (tokens are space-separated) if (strtol(splitter[2]) > 5) { .. } } ASSIMP_LOG_VERBOSE_DEBUG("Current line is: ", splitter.get_index()); } @endcode */ // ------------------------------------------------------------------------------------------------ class LineSplitter { public: typedef size_t line_idx; // ----------------------------------------- /** construct from existing stream reader note: trim is *always* assumed true if skyp_empty_lines==true */ LineSplitter(StreamReaderLE& stream, bool skip_empty_lines = true, bool trim = true); ~LineSplitter(); // ----------------------------------------- /** pseudo-iterator increment */ LineSplitter& operator++(); // ----------------------------------------- LineSplitter& operator++(int); // ----------------------------------------- /** get a pointer to the beginning of a particular token */ const char* operator[] (size_t idx) const; // ----------------------------------------- /** extract the start positions of N tokens from the current line*/ template <size_t N> void get_tokens(const char* (&tokens)[N]) const; // ----------------------------------------- /** member access */ const std::string* operator -> () const; std::string operator* () const; // ----------------------------------------- /** boolean context */ operator bool() const; // ----------------------------------------- /** line indices are zero-based, empty lines are included */ operator line_idx() const; line_idx get_index() const; // ----------------------------------------- /** access the underlying stream object */ StreamReaderLE& get_stream(); // ----------------------------------------- /** !strcmp((*this)->substr(0,strlen(check)),check) */ bool match_start(const char* check); // ----------------------------------------- /** swallow the next call to ++, return the previous value. */ void swallow_next_increment(); LineSplitter( const LineSplitter & ) = delete; LineSplitter(LineSplitter &&) = delete; LineSplitter &operator = ( const LineSplitter & ) = delete; private: line_idx mIdx; std::string mCur; StreamReaderLE& mStream; bool mSwallow, mSkip_empty_lines, mTrim; }; AI_FORCE_INLINE LineSplitter::LineSplitter(StreamReaderLE& stream, bool skip_empty_lines, bool trim ) : mIdx(0), mStream(stream), mSwallow(), mSkip_empty_lines(skip_empty_lines), mTrim(trim) { mCur.reserve(1024); operator++(); mIdx = 0; } AI_FORCE_INLINE LineSplitter::~LineSplitter() = default; AI_FORCE_INLINE LineSplitter& LineSplitter::operator++() { if (mSwallow) { mSwallow = false; return *this; } if (!*this) { throw std::logic_error("End of file, no more lines to be retrieved."); } char s; mCur.clear(); while (mStream.GetRemainingSize() && (s = mStream.GetI1(), 1)) { if (s == '\n' || s == '\r') { if (mSkip_empty_lines) { while (mStream.GetRemainingSize() && ((s = mStream.GetI1()) == ' ' || s == '\r' || s == '\n')); if (mStream.GetRemainingSize()) { mStream.IncPtr(-1); } } else { // skip both potential line terminators but don't read past this line. if (mStream.GetRemainingSize() && (s == '\r' && mStream.GetI1() != '\n')) { mStream.IncPtr(-1); } if (mTrim) { while (mStream.GetRemainingSize() && ((s = mStream.GetI1()) == ' ' || s == '\t')); if (mStream.GetRemainingSize()) { mStream.IncPtr(-1); } } } break; } mCur += s; } ++mIdx; return *this; } AI_FORCE_INLINE LineSplitter &LineSplitter::operator++(int) { return ++(*this); } AI_FORCE_INLINE const char *LineSplitter::operator[] (size_t idx) const { const char* s = operator->()->c_str(); SkipSpaces(&s); for (size_t i = 0; i < idx; ++i) { for (; !IsSpace(*s); ++s) { if (IsLineEnd(*s)) { throw std::range_error("Token index out of range, EOL reached"); } } SkipSpaces(&s); } return s; } template <size_t N> AI_FORCE_INLINE void LineSplitter::get_tokens(const char* (&tokens)[N]) const { const char* s = operator->()->c_str(); SkipSpaces(&s); for (size_t i = 0; i < N; ++i) { if (IsLineEnd(*s)) { throw std::range_error("Token count out of range, EOL reached"); } tokens[i] = s; for (; *s && !IsSpace(*s); ++s); SkipSpaces(&s); } } AI_FORCE_INLINE const std::string* LineSplitter::operator -> () const { return &mCur; } AI_FORCE_INLINE std::string LineSplitter::operator* () const { return mCur; } AI_FORCE_INLINE LineSplitter::operator bool() const { return mStream.GetRemainingSize() > 0; } AI_FORCE_INLINE LineSplitter::operator line_idx() const { return mIdx; } AI_FORCE_INLINE LineSplitter::line_idx LineSplitter::get_index() const { return mIdx; } AI_FORCE_INLINE StreamReaderLE &LineSplitter::get_stream() { return mStream; } AI_FORCE_INLINE bool LineSplitter::match_start(const char* check) { const size_t len = ::strlen(check); return len <= mCur.length() && std::equal(check, check + len, mCur.begin()); } AI_FORCE_INLINE void LineSplitter::swallow_next_increment() { mSwallow = true; } } // Namespace Assimp #endif // INCLUDED_LINE_SPLITTER_H
8,145
C
29.05904
111
0.560098
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/ProgressHandler.hpp
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file ProgressHandler.hpp * @brief Abstract base class 'ProgressHandler'. */ #pragma once #ifndef AI_PROGRESSHANDLER_H_INC #define AI_PROGRESSHANDLER_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/types.h> namespace Assimp { // ------------------------------------------------------------------------------------ /** @brief CPP-API: Abstract interface for custom progress report receivers. * * Each #Importer instance maintains its own #ProgressHandler. The default * implementation provided by Assimp doesn't do anything at all. */ class ASSIMP_API ProgressHandler #ifndef SWIG : public Intern::AllocateFromAssimpHeap #endif { protected: /// @brief Default constructor ProgressHandler () AI_NO_EXCEPT = default; public: /// @brief Virtual destructor. virtual ~ProgressHandler () = default; // ------------------------------------------------------------------- /** @brief Progress callback. * @param percentage An estimate of the current loading progress, * in percent. Or -1.f if such an estimate is not available. * * There are restriction on what you may do from within your * implementation of this method: no exceptions may be thrown and no * non-const #Importer methods may be called. It is * not generally possible to predict the number of callbacks * fired during a single import. * * @return Return false to abort loading at the next possible * occasion (loaders and Assimp are generally allowed to perform * all needed cleanup tasks prior to returning control to the * caller). If the loading is aborted, #Importer::ReadFile() * returns always nullptr. * */ virtual bool Update(float percentage = -1.f) = 0; // ------------------------------------------------------------------- /** @brief Progress callback for file loading steps * @param numberOfSteps The number of total post-processing * steps * @param currentStep The index of the current post-processing * step that will run, or equal to numberOfSteps if all of * them has finished. This number is always strictly monotone * increasing, although not necessarily linearly. * * @note This is currently only used at the start and the end * of the file parsing. * */ virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; Update( f * 0.5f ); } // ------------------------------------------------------------------- /** @brief Progress callback for post-processing steps * @param numberOfSteps The number of total post-processing * steps * @param currentStep The index of the current post-processing * step that will run, or equal to numberOfSteps if all of * them has finished. This number is always strictly monotone * increasing, although not necessarily linearly. * */ virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; Update( f * 0.5f + 0.5f ); } // ------------------------------------------------------------------- /** @brief Progress callback for export steps. * @param numberOfSteps The number of total processing * steps * @param currentStep The index of the current post-processing * step that will run, or equal to numberOfSteps if all of * them has finished. This number is always strictly monotone * increasing, although not necessarily linearly. * */ virtual void UpdateFileWrite(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) { float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f; Update(f * 0.5f); } }; // !class ProgressHandler // ------------------------------------------------------------------------------------ } // Namespace Assimp #endif // AI_PROGRESSHANDLER_H_INC
5,831
C++
38.673469
88
0.635569
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/IOSystem.hpp
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file IOSystem.hpp * @brief File system wrapper for C++. Inherit this class to supply * custom file handling logic to the Import library. */ #pragma once #ifndef AI_IOSYSTEM_H_INC #define AI_IOSYSTEM_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #ifndef __cplusplus # error This header requires C++ to be used. aiFileIO.h is the \ corresponding C interface. #endif #include "types.h" #ifdef _WIN32 # include <direct.h> # include <cstdlib> # include <cstdio> #else # include <sys/stat.h> # include <sys/types.h> # include <unistd.h> #endif // _WIN32 #include <vector> namespace Assimp { class IOStream; // --------------------------------------------------------------------------- /** @brief CPP-API: Interface to the file system. * * Derive an own implementation from this interface to supply custom file handling * to the importer library. If you implement this interface, you also want to * supply a custom implementation for IOStream. * * @see Importer::SetIOHandler() */ class ASSIMP_API IOSystem #ifndef SWIG : public Intern::AllocateFromAssimpHeap #endif { public: // ------------------------------------------------------------------- /** @brief Default constructor. * * Create an instance of your derived class and assign it to an * #Assimp::Importer instance by calling Importer::SetIOHandler(). */ IOSystem() AI_NO_EXCEPT; // ------------------------------------------------------------------- /** @brief Virtual destructor. * * It is safe to be called from within DLL Assimp, we're constructed * on Assimp's heap. */ virtual ~IOSystem(); // ------------------------------------------------------------------- /** @brief For backward compatibility * @see Exists(const char*) */ AI_FORCE_INLINE bool Exists( const std::string& pFile) const; // ------------------------------------------------------------------- /** @brief Tests for the existence of a file at the given path. * * @param pFile Path to the file * @return true if there is a file with this path, else false. */ virtual bool Exists( const char* pFile) const = 0; // ------------------------------------------------------------------- /** @brief Returns the system specific directory separator * @return System specific directory separator */ virtual char getOsSeparator() const = 0; // ------------------------------------------------------------------- /** @brief Open a new file with a given path. * * When the access to the file is finished, call Close() to release * all associated resources (or the virtual dtor of the IOStream). * * @param pFile Path to the file * @param pMode Desired file I/O mode. Required are: "wb", "w", "wt", * "rb", "r", "rt". * * @return New IOStream interface allowing the lib to access * the underlying file. * @note When implementing this class to provide custom IO handling, * you probably have to supply an own implementation of IOStream as well. */ virtual IOStream* Open(const char* pFile, const char* pMode = "rb") = 0; // ------------------------------------------------------------------- /** @brief For backward compatibility * @see Open(const char*, const char*) */ inline IOStream* Open(const std::string& pFile, const std::string& pMode = std::string("rb")); // ------------------------------------------------------------------- /** @brief Closes the given file and releases all resources * associated with it. * @param pFile The file instance previously created by Open(). */ virtual void Close( IOStream* pFile) = 0; // ------------------------------------------------------------------- /** @brief Compares two paths and check whether the point to * identical files. * * The dummy implementation of this virtual member performs a * case-insensitive comparison of the given strings. The default IO * system implementation uses OS mechanisms to convert relative into * absolute paths, so the result can be trusted. * @param one First file * @param second Second file * @return true if the paths point to the same file. The file needn't * be existing, however. */ virtual bool ComparePaths (const char* one, const char* second) const; // ------------------------------------------------------------------- /** @brief For backward compatibility * @see ComparePaths(const char*, const char*) */ inline bool ComparePaths (const std::string& one, const std::string& second) const; // ------------------------------------------------------------------- /** @brief Pushes a new directory onto the directory stack. * @param path Path to push onto the stack. * @return True, when push was successful, false if path is empty. */ virtual bool PushDirectory( const std::string &path ); // ------------------------------------------------------------------- /** @brief Returns the top directory from the stack. * @return The directory on the top of the stack. * Returns empty when no directory was pushed to the stack. */ virtual const std::string &CurrentDirectory() const; // ------------------------------------------------------------------- /** @brief Returns the number of directories stored on the stack. * @return The number of directories of the stack. */ virtual size_t StackSize() const; // ------------------------------------------------------------------- /** @brief Pops the top directory from the stack. * @return True, when a directory was on the stack. False if no * directory was on the stack. */ virtual bool PopDirectory(); // ------------------------------------------------------------------- /** @brief CReates an new directory at the given path. * @param path [in] The path to create. * @return True, when a directory was created. False if the directory * cannot be created. */ virtual bool CreateDirectory( const std::string &path ); // ------------------------------------------------------------------- /** @brief Will change the current directory to the given path. * @param path [in] The path to change to. * @return True, when the directory has changed successfully. */ virtual bool ChangeDirectory( const std::string &path ); // ------------------------------------------------------------------- /** * @brief Will delete the given file. * @param file [in] The filename * @return true, if the file wase deleted, false if not. */ virtual bool DeleteFile(const std::string &file); private: std::vector<std::string> m_pathStack; }; // ---------------------------------------------------------------------------- AI_FORCE_INLINE IOSystem::IOSystem() AI_NO_EXCEPT = default; // ---------------------------------------------------------------------------- AI_FORCE_INLINE IOSystem::~IOSystem() = default; // ---------------------------------------------------------------------------- // For compatibility, the interface of some functions taking a std::string was // changed to const char* to avoid crashes between binary incompatible STL // versions. This code her is inlined, so it shouldn't cause any problems. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile, const std::string& pMode) { // NOTE: // For compatibility, interface was changed to const char* to // avoid crashes between binary incompatible STL versions return Open(pFile.c_str(),pMode.c_str()); } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const { // NOTE: // For compatibility, interface was changed to const char* to // avoid crashes between binary incompatible STL versions return Exists(pFile.c_str()); } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::ComparePaths(const std::string& one, const std::string& second) const { // NOTE: // For compatibility, interface was changed to const char* to // avoid crashes between binary incompatible STL versions return ComparePaths(one.c_str(),second.c_str()); } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::PushDirectory( const std::string &path ) { if ( path.empty() ) { return false; } m_pathStack.push_back( path ); return true; } // ---------------------------------------------------------------------------- AI_FORCE_INLINE size_t IOSystem::StackSize() const { return m_pathStack.size(); } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::PopDirectory() { if ( m_pathStack.empty() ) { return false; } m_pathStack.pop_back(); return true; } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::CreateDirectory( const std::string &path ) { if ( path.empty() ) { return false; } #ifdef _WIN32 return 0 != ::_mkdir( path.c_str() ); #else return 0 != ::mkdir( path.c_str(), 0777 ); #endif // _WIN32 } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::ChangeDirectory( const std::string &path ) { if ( path.empty() ) { return false; } #ifdef _WIN32 return 0 != ::_chdir( path.c_str() ); #else return 0 != ::chdir( path.c_str() ); #endif // _WIN32 } // ---------------------------------------------------------------------------- AI_FORCE_INLINE bool IOSystem::DeleteFile( const std::string &file ) { if ( file.empty() ) { return false; } const int retCode( ::remove( file.c_str() ) ); return ( 0 == retCode ); } } //!ns Assimp #endif //AI_IOSYSTEM_H_INC
12,253
C++
35.041176
102
0.528442
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/Exporter.hpp
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file Exporter.hpp * @brief Defines the CPP-API for the Assimp export interface */ #pragma once #ifndef AI_EXPORT_HPP_INC #define AI_EXPORT_HPP_INC #ifdef __GNUC__ #pragma GCC system_header #endif #ifndef ASSIMP_BUILD_NO_EXPORT #include "cexport.h" #include <map> #include <functional> namespace Assimp { class ExporterPimpl; class IOSystem; class ProgressHandler; // ---------------------------------------------------------------------------------- /** CPP-API: The Exporter class forms an C++ interface to the export functionality * of the Open Asset Import Library. Note that the export interface is available * only if Assimp has been built with ASSIMP_BUILD_NO_EXPORT not defined. * * The interface is modeled after the importer interface and mostly * symmetric. The same rules for threading etc. apply. * * In a nutshell, there are two export interfaces: #Export, which writes the * output file(s) either to the regular file system or to a user-supplied * #IOSystem, and #ExportToBlob which returns a linked list of memory * buffers (blob), each referring to one output file (in most cases * there will be only one output file of course, but this extra complexity is * needed since Assimp aims at supporting a wide range of file formats). * * #ExportToBlob is especially useful if you intend to work * with the data in-memory. */ class ASSIMP_API ExportProperties; class ASSIMP_API Exporter { public: /** Function pointer type of a Export worker function */ typedef void (*fpExportFunc)(const char *, IOSystem *, const aiScene *, const ExportProperties *); /** Internal description of an Assimp export format option */ struct ExportFormatEntry { /// Public description structure to be returned by aiGetExportFormatDescription() aiExportFormatDesc mDescription; // Worker function to do the actual exporting fpExportFunc mExportFunction; // Post-processing steps to be executed PRIOR to invoking mExportFunction unsigned int mEnforcePP; // Constructor to fill all entries ExportFormatEntry(const char *pId, const char *pDesc, const char *pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) { mDescription.id = pId; mDescription.description = pDesc; mDescription.fileExtension = pExtension; mExportFunction = pFunction; mEnforcePP = pEnforcePP; } ExportFormatEntry() : mExportFunction(), mEnforcePP() { mDescription.id = nullptr; mDescription.description = nullptr; mDescription.fileExtension = nullptr; } }; /** * @brief The class constructor. */ Exporter(); /** * @brief The class destructor. */ ~Exporter(); // ------------------------------------------------------------------- /** Supplies a custom IO handler to the exporter to use to open and * access files. * * If you need #Export to use custom IO logic to access the files, * you need to supply a custom implementation of IOSystem and * IOFile to the exporter. * * #Exporter takes ownership of the object and will destroy it * afterwards. The previously assigned handler will be deleted. * Pass NULL to take again ownership of your IOSystem and reset Assimp * to use its default implementation, which uses plain file IO. * * @param pIOHandler The IO handler to be used in all file accesses * of the Importer. */ void SetIOHandler(IOSystem *pIOHandler); // ------------------------------------------------------------------- /** Retrieves the IO handler that is currently set. * You can use #IsDefaultIOHandler() to check whether the returned * interface is the default IO handler provided by ASSIMP. The default * handler is active as long the application doesn't supply its own * custom IO handler via #SetIOHandler(). * @return A valid IOSystem interface, never NULL. */ IOSystem *GetIOHandler() const; // ------------------------------------------------------------------- /** Checks whether a default IO handler is active * A default handler is active as long the application doesn't * supply its own custom IO handler via #SetIOHandler(). * @return true by default */ bool IsDefaultIOHandler() const; // ------------------------------------------------------------------- /** Supplies a custom progress handler to the exporter. This * interface exposes an #Update() callback, which is called * more or less periodically (please don't sue us if it * isn't as periodically as you'd like it to have ...). * This can be used to implement progress bars and loading * timeouts. * @param pHandler Progress callback interface. Pass nullptr to * disable progress reporting. * @note Progress handlers can be used to abort the loading * at almost any time.*/ void SetProgressHandler(ProgressHandler *pHandler); // ------------------------------------------------------------------- /** Exports the given scene to a chosen file format. Returns the exported * data as a binary blob which you can write into a file or something. * When you're done with the data, simply let the #Exporter instance go * out of scope to have it released automatically. * @param pScene The scene to export. Stays in possession of the caller, * is not changed by the function. * @param pFormatId ID string to specify to which format you want to * export to. Use * #GetExportFormatCount / #GetExportFormatDescription to learn which * export formats are available. * @param pPreprocessing See the documentation for #Export * @return the exported data or nullptr in case of error. * @note If the Exporter instance did already hold a blob from * a previous call to #ExportToBlob, it will be disposed. * Any IO handlers set via #SetIOHandler are ignored here. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene. */ const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const char *pFormatId, unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const std::string &pFormatId, unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); // ------------------------------------------------------------------- /** Convenience function to export directly to a file. Use * #SetIOSystem to supply a custom IOSystem to gain fine-grained control * about the output data flow of the export process. * @param pBlob A data blob obtained from a previous call to #aiExportScene. Must not be nullptr. * @param pPath Full target file name. Target must be accessible. * @param pPreprocessing Accepts any choice of the #aiPostProcessSteps enumerated * flags, but in reality only a subset of them makes sense here. Specifying * 'preprocessing' flags is useful if the input scene does not conform to * Assimp's default conventions as specified in the @link data Data Structures Page @endlink. * In short, this means the geometry data should use a right-handed coordinate systems, face * winding should be counter-clockwise and the UV coordinate origin is assumed to be in * the upper left. The #aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and * #aiProcess_FlipWindingOrder flags are used in the import side to allow users * to have those defaults automatically adapted to their conventions. Specifying those flags * for exporting has the opposite effect, respectively. Some other of the * #aiPostProcessSteps enumerated values may be useful as well, but you'll need * to try out what their effect on the exported file is. Many formats impose * their own restrictions on the structure of the geometry stored therein, * so some preprocessing may have little or no effect at all, or may be * redundant as exporters would apply them anyhow. A good example * is triangulation - whilst you can enforce it by specifying * the #aiProcess_Triangulate flag, most export formats support only * triangulate data so they would run the step even if it wasn't requested. * * If assimp detects that the input scene was directly taken from the importer side of * the library (i.e. not copied using aiCopyScene and potentially modified afterwards), * any post-processing steps already applied to the scene will not be applied again, unless * they show non-idempotent behavior (#aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and * #aiProcess_FlipWindingOrder). * @return AI_SUCCESS if everything was fine. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene.*/ aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath, unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); aiReturn Export(const aiScene *pScene, const std::string &pFormatId, const std::string &pPath, unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); // ------------------------------------------------------------------- /** Returns an error description of an error that occurred in #Export * or #ExportToBlob * * Returns an empty string if no error occurred. * @return A description of the last error, an empty string if no * error occurred. The string is never nullptr. * * @note The returned function remains valid until one of the * following methods is called: #Export, #ExportToBlob, #FreeBlob */ const char *GetErrorString() const; // ------------------------------------------------------------------- /** Return the blob obtained from the last call to #ExportToBlob */ const aiExportDataBlob *GetBlob() const; // ------------------------------------------------------------------- /** Orphan the blob from the last call to #ExportToBlob. This means * the caller takes ownership and is thus responsible for calling * the C API function #aiReleaseExportBlob to release it. */ const aiExportDataBlob *GetOrphanedBlob() const; // ------------------------------------------------------------------- /** Frees the current blob. * * The function does nothing if no blob has previously been * previously produced via #ExportToBlob. #FreeBlob is called * automatically by the destructor. The only reason to call * it manually would be to reclaim as much storage as possible * without giving up the #Exporter instance yet. */ void FreeBlob(); // ------------------------------------------------------------------- /** Returns the number of export file formats available in the current * Assimp build. Use #Exporter::GetExportFormatDescription to * retrieve infos of a specific export format. * * This includes built-in exporters as well as exporters registered * using #RegisterExporter. **/ size_t GetExportFormatCount() const; // ------------------------------------------------------------------- /** Returns a description of the nth export file format. Use # * #Exporter::GetExportFormatCount to learn how many export * formats are supported. * * The returned pointer is of static storage duration if the * pIndex pertains to a built-in exporter (i.e. one not registered * via #RegistrerExporter). It is restricted to the life-time of the * #Exporter instance otherwise. * * @param pIndex Index of the export format to retrieve information * for. Valid range is 0 to #Exporter::GetExportFormatCount * @return A description of that specific export format. * NULL if pIndex is out of range. */ const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const; // ------------------------------------------------------------------- /** Register a custom exporter. Custom export formats are limited to * to the current #Exporter instance and do not affect the * library globally. The indexes under which the format's * export format description can be queried are assigned * monotonously. * @param desc Exporter description. * @return aiReturn_SUCCESS if the export format was successfully * registered. A common cause that would prevent an exporter * from being registered is that its format id is already * occupied by another format. */ aiReturn RegisterExporter(const ExportFormatEntry &desc); // ------------------------------------------------------------------- /** Remove an export format previously registered with #RegisterExporter * from the #Exporter instance (this can also be used to drop * built-in exporters because those are implicitly registered * using #RegisterExporter). * @param id Format id to be unregistered, this refers to the * 'id' field of #aiExportFormatDesc. * @note Calling this method on a format description not yet registered * has no effect.*/ void UnregisterExporter(const char *id); protected: // Just because we don't want you to know how we're hacking around. ExporterPimpl *pimpl; }; class ASSIMP_API ExportProperties { public: // Data type to store the key hash typedef unsigned int KeyType; // typedefs for our four configuration maps. // We don't need more, so there is no need for a generic solution typedef std::map<KeyType, int> IntPropertyMap; typedef std::map<KeyType, ai_real> FloatPropertyMap; typedef std::map<KeyType, std::string> StringPropertyMap; typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap; public: /** Standard constructor * @see ExportProperties() */ ExportProperties(); // ------------------------------------------------------------------- /** Copy constructor. * * This copies the configuration properties of another ExportProperties. * @see ExportProperties(const ExportProperties& other) */ ExportProperties(const ExportProperties &other); // ------------------------------------------------------------------- /** Set an integer configuration property. * @param szName Name of the property. All supported properties * are defined in the aiConfig.g header (all constants share the * prefix AI_CONFIG_XXX and are simple strings). * @param iValue New value of the property * @return true if the property was set before. The new value replaces * the previous value in this case. * @note Property of different types (float, int, string ..) are kept * on different stacks, so calling SetPropertyInteger() for a * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ bool SetPropertyInteger(const char *szName, int iValue); // ------------------------------------------------------------------- /** Set a boolean configuration property. Boolean properties * are stored on the integer stack internally so it's possible * to set them via #SetPropertyBool and query them with * #GetPropertyBool and vice versa. * @see SetPropertyInteger() */ bool SetPropertyBool(const char *szName, bool value) { return SetPropertyInteger(szName, value); } // ------------------------------------------------------------------- /** Set a floating-point configuration property. * @see SetPropertyInteger() */ bool SetPropertyFloat(const char *szName, ai_real fValue); // ------------------------------------------------------------------- /** Set a string configuration property. * @see SetPropertyInteger() */ bool SetPropertyString(const char *szName, const std::string &sValue); // ------------------------------------------------------------------- /** Set a matrix configuration property. * @see SetPropertyInteger() */ bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); bool SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f); // ------------------------------------------------------------------- /** Get a configuration property. * @param szName Name of the property. All supported properties * are defined in the aiConfig.g header (all constants share the * prefix AI_CONFIG_XXX). * @param iErrorReturn Value that is returned if the property * is not found. * @return Current value of the property * @note Property of different types (float, int, string ..) are kept * on different lists, so calling SetPropertyInteger() for a * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ int GetPropertyInteger(const char *szName, int iErrorReturn = 0xffffffff) const; // ------------------------------------------------------------------- /** Get a boolean configuration property. Boolean properties * are stored on the integer stack internally so it's possible * to set them via #SetPropertyBool and query them with * #GetPropertyBool and vice versa. * @see GetPropertyInteger() */ bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const { return GetPropertyInteger(szName, bErrorReturn) != 0; } // ------------------------------------------------------------------- /** Get a floating-point configuration property * @see GetPropertyInteger() */ ai_real GetPropertyFloat(const char *szName, ai_real fErrorReturn = 10e10f) const; // ------------------------------------------------------------------- /** Get a string configuration property * * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ const std::string GetPropertyString(const char *szName, const std::string &sErrorReturn = "") const; // ------------------------------------------------------------------- /** Get a matrix configuration property * * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; std::function<void *(void *)> GetPropertyCallback(const char* szName) const; // ------------------------------------------------------------------- /** Determine a integer configuration property has been set. * @see HasPropertyInteger() */ bool HasPropertyInteger(const char *szName) const; /** Determine a boolean configuration property has been set. * @see HasPropertyBool() */ bool HasPropertyBool(const char *szName) const; /** Determine a boolean configuration property has been set. * @see HasPropertyFloat() */ bool HasPropertyFloat(const char *szName) const; /** Determine a String configuration property has been set. * @see HasPropertyString() */ bool HasPropertyString(const char *szName) const; /** Determine a Matrix configuration property has been set. * @see HasPropertyMatrix() */ bool HasPropertyMatrix(const char *szName) const; bool HasPropertyCallback(const char *szName) const; /** List of integer properties */ IntPropertyMap mIntProperties; /** List of floating-point properties */ FloatPropertyMap mFloatProperties; /** List of string properties */ StringPropertyMap mStringProperties; /** List of Matrix properties */ MatrixPropertyMap mMatrixProperties; CallbackPropertyMap mCallbackProperties; }; // ---------------------------------------------------------------------------------- inline const aiExportDataBlob *Exporter::ExportToBlob(const aiScene *pScene, const std::string &pFormatId, unsigned int pPreprocessing, const ExportProperties *pProperties) { return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties); } // ---------------------------------------------------------------------------------- inline aiReturn Exporter ::Export(const aiScene *pScene, const std::string &pFormatId, const std::string &pPath, unsigned int pPreprocessing, const ExportProperties *pProperties) { return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties); } } // namespace Assimp #endif // ASSIMP_BUILD_NO_EXPORT #endif // AI_EXPORT_HPP_INC
23,002
C++
44.103921
141
0.630858
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/SGSpatialSort.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** Small helper classes to optimize finding vertices close to a given location */ #pragma once #ifndef AI_D3DSSPATIALSORT_H_INC #define AI_D3DSSPATIALSORT_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/types.h> #include <vector> #include <stdint.h> namespace Assimp { // ---------------------------------------------------------------------------------- /** Specialized version of SpatialSort to support smoothing groups * This is used in by the 3DS, ASE and LWO loaders. 3DS and ASE share their * normal computation code in SmoothingGroups.inl, the LWO loader has its own * implementation to handle all details of its file format correctly. */ // ---------------------------------------------------------------------------------- class ASSIMP_API SGSpatialSort { public: SGSpatialSort(); // ------------------------------------------------------------------- /** Construction from a given face array, handling smoothing groups * properly */ explicit SGSpatialSort(const std::vector<aiVector3D>& vPositions); // ------------------------------------------------------------------- /** Add a vertex to the spatial sort * @param vPosition Vertex position to be added * @param index Index of the vrtex * @param smoothingGroup SmoothingGroup for this vertex */ void Add(const aiVector3D& vPosition, unsigned int index, unsigned int smoothingGroup); // ------------------------------------------------------------------- /** Prepare the spatial sorter for use. This step runs in O(logn) */ void Prepare(); /** Destructor */ ~SGSpatialSort(); // ------------------------------------------------------------------- /** Returns an iterator for all positions close to the given position. * @param pPosition The position to look for vertices. * @param pSG Only included vertices with at least one shared smooth group * @param pRadius Maximal distance from the position a vertex may have * to be counted in. * @param poResults The container to store the indices of the found * positions. Will be emptied by the call so it may contain anything. * @param exactMatch Specifies whether smoothing groups are bit masks * (false) or integral values (true). In the latter case, a vertex * cannot belong to more than one smoothing group. * @return An iterator to iterate over all vertices in the given area. */ // ------------------------------------------------------------------- void FindPositions( const aiVector3D& pPosition, uint32_t pSG, float pRadius, std::vector<unsigned int>& poResults, bool exactMatch = false) const; protected: /** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */ aiVector3D mPlaneNormal; // ------------------------------------------------------------------- /** An entry in a spatially sorted position array. Consists of a * vertex index, its position and its pre-calculated distance from * the reference plane */ // ------------------------------------------------------------------- struct Entry { unsigned int mIndex; ///< The vertex referred by this entry aiVector3D mPosition; ///< Position uint32_t mSmoothGroups; float mDistance; ///< Distance of this vertex to the sorting plane Entry() AI_NO_EXCEPT : mIndex(0) , mPosition() , mSmoothGroups(0) , mDistance(0.0f) { // empty } Entry( unsigned int pIndex, const aiVector3D& pPosition, float pDistance,uint32_t pSG) : mIndex( pIndex) , mPosition( pPosition) , mSmoothGroups(pSG) , mDistance( pDistance) { // empty } bool operator < (const Entry& e) const { return mDistance < e.mDistance; } }; // all positions, sorted by distance to the sorting plane std::vector<Entry> mPositions; }; } // end of namespace Assimp #endif // AI_SPATIALSORT_H_INC
5,845
C
36.474359
94
0.604619
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/aabb.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ #pragma once #ifndef AI_AABB_H_INC #define AI_AABB_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #include <assimp/vector3.h> // --------------------------------------------------------------------------- /** * An axis-aligned bounding box. */ struct aiAABB { C_STRUCT aiVector3D mMin; C_STRUCT aiVector3D mMax; #ifdef __cplusplus /// @brief The default class constructor. aiAABB() : mMin(), mMax() { // empty } /// @brief The class constructor with the minimum and maximum. /// @param min The minimum dimension. /// @param max The maximum dimension. aiAABB(const aiVector3D &min, const aiVector3D &max) : mMin(min), mMax(max) { // empty } /// @brief The class destructor. ~aiAABB() = default; #endif // __cplusplus }; #endif // AI_AABB_H_INC
2,640
C
31.207317
78
0.655682
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/Vertex.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file Defines a helper class to represent an interleaved vertex along with arithmetic operations to support vertex operations such as subdivision, smoothing etc. While the code is kept as general as possible, arithmetic operations that are not currently well-defined (and would cause compile errors due to missing operators in the math library), are commented. */ #pragma once #ifndef AI_VERTEX_H_INC #define AI_VERTEX_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #include <assimp/vector3.h> #include <assimp/mesh.h> #include <assimp/ai_assert.h> #include <functional> namespace Assimp { /////////////////////////////////////////////////////////////////////////// // std::plus-family operates on operands with identical types - we need to // support all the (vectype op float) combinations in vector maths. // Providing T(float) would open the way to endless implicit conversions. /////////////////////////////////////////////////////////////////////////// namespace Intern { template <typename T0, typename T1, typename TRES = T0> struct plus { TRES operator() (const T0& t0, const T1& t1) const { return t0+t1; } }; template <typename T0, typename T1, typename TRES = T0> struct minus { TRES operator() (const T0& t0, const T1& t1) const { return t0-t1; } }; template <typename T0, typename T1, typename TRES = T0> struct multiplies { TRES operator() (const T0& t0, const T1& t1) const { return t0*t1; } }; template <typename T0, typename T1, typename TRES = T0> struct divides { TRES operator() (const T0& t0, const T1& t1) const { return t0/t1; } }; } // ------------------------------------------------------------------------------------------------ /** Intermediate description a vertex with all possible components. Defines a full set of * operators, so you may use such a 'Vertex' in basic arithmetic. All operators are applied * to *all* vertex components equally. This is useful for stuff like interpolation * or subdivision, but won't work if special handling is required for some vertex components. */ // ------------------------------------------------------------------------------------------------ struct Vertex { friend Vertex operator + (const Vertex&,const Vertex&); friend Vertex operator - (const Vertex&,const Vertex&); friend Vertex operator * (const Vertex&,ai_real); friend Vertex operator / (const Vertex&,ai_real); friend Vertex operator * (ai_real, const Vertex&); aiVector3D position; aiVector3D normal; aiVector3D tangent, bitangent; aiVector3D texcoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; aiColor4D colors[AI_MAX_NUMBER_OF_COLOR_SETS]; Vertex() = default; // ---------------------------------------------------------------------------- /** Extract a particular vertex from a mesh and interleave all components */ explicit Vertex(const aiMesh* msh, unsigned int idx) { ai_assert(idx < msh->mNumVertices); position = msh->mVertices[idx]; if (msh->HasNormals()) { normal = msh->mNormals[idx]; } if (msh->HasTangentsAndBitangents()) { tangent = msh->mTangents[idx]; bitangent = msh->mBitangents[idx]; } for (unsigned int i = 0; msh->HasTextureCoords(i); ++i) { texcoords[i] = msh->mTextureCoords[i][idx]; } for (unsigned int i = 0; msh->HasVertexColors(i); ++i) { colors[i] = msh->mColors[i][idx]; } } // ---------------------------------------------------------------------------- /** Extract a particular vertex from a anim mesh and interleave all components */ explicit Vertex(const aiAnimMesh* msh, unsigned int idx) { ai_assert(idx < msh->mNumVertices); if (msh->HasPositions()) { position = msh->mVertices[idx]; } if (msh->HasNormals()) { normal = msh->mNormals[idx]; } if (msh->HasTangentsAndBitangents()) { tangent = msh->mTangents[idx]; bitangent = msh->mBitangents[idx]; } for (unsigned int i = 0; msh->HasTextureCoords(i); ++i) { texcoords[i] = msh->mTextureCoords[i][idx]; } for (unsigned int i = 0; msh->HasVertexColors(i); ++i) { colors[i] = msh->mColors[i][idx]; } } Vertex& operator += (const Vertex& v) { *this = *this+v; return *this; } Vertex& operator -= (const Vertex& v) { *this = *this-v; return *this; } Vertex& operator *= (ai_real v) { *this = *this*v; return *this; } Vertex& operator /= (ai_real v) { *this = *this/v; return *this; } // ---------------------------------------------------------------------------- /// Convert back to non-interleaved storage void SortBack(aiMesh* out, unsigned int idx) const { ai_assert(idx<out->mNumVertices); out->mVertices[idx] = position; if (out->HasNormals()) { out->mNormals[idx] = normal; } if (out->HasTangentsAndBitangents()) { out->mTangents[idx] = tangent; out->mBitangents[idx] = bitangent; } for(unsigned int i = 0; out->HasTextureCoords(i); ++i) { out->mTextureCoords[i][idx] = texcoords[i]; } for(unsigned int i = 0; out->HasVertexColors(i); ++i) { out->mColors[i][idx] = colors[i]; } } private: // ---------------------------------------------------------------------------- /// Construct from two operands and a binary operation to combine them template <template <typename t> class op> static Vertex BinaryOp(const Vertex& v0, const Vertex& v1) { // this is a heavy task for the compiler to optimize ... *pray* Vertex res; res.position = op<aiVector3D>()(v0.position,v1.position); res.normal = op<aiVector3D>()(v0.normal,v1.normal); res.tangent = op<aiVector3D>()(v0.tangent,v1.tangent); res.bitangent = op<aiVector3D>()(v0.bitangent,v1.bitangent); for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { res.texcoords[i] = op<aiVector3D>()(v0.texcoords[i],v1.texcoords[i]); } for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) { res.colors[i] = op<aiColor4D>()(v0.colors[i],v1.colors[i]); } return res; } // ---------------------------------------------------------------------------- /// This time binary arithmetic of v0 with a floating-point number template <template <typename, typename, typename> class op> static Vertex BinaryOp(const Vertex& v0, ai_real f) { // this is a heavy task for the compiler to optimize ... *pray* Vertex res; res.position = op<aiVector3D,ai_real,aiVector3D>()(v0.position,f); res.normal = op<aiVector3D,ai_real,aiVector3D>()(v0.normal,f); res.tangent = op<aiVector3D,ai_real,aiVector3D>()(v0.tangent,f); res.bitangent = op<aiVector3D,ai_real,aiVector3D>()(v0.bitangent,f); for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { res.texcoords[i] = op<aiVector3D,ai_real,aiVector3D>()(v0.texcoords[i],f); } for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) { res.colors[i] = op<aiColor4D,ai_real,aiColor4D>()(v0.colors[i],f); } return res; } // ---------------------------------------------------------------------------- /** This time binary arithmetic of v0 with a floating-point number */ template <template <typename, typename, typename> class op> static Vertex BinaryOp(ai_real f, const Vertex& v0) { // this is a heavy task for the compiler to optimize ... *pray* Vertex res; res.position = op<ai_real,aiVector3D,aiVector3D>()(f,v0.position); res.normal = op<ai_real,aiVector3D,aiVector3D>()(f,v0.normal); res.tangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.tangent); res.bitangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.bitangent); for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { res.texcoords[i] = op<ai_real,aiVector3D,aiVector3D>()(f,v0.texcoords[i]); } for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) { res.colors[i] = op<ai_real,aiColor4D,aiColor4D>()(f,v0.colors[i]); } return res; } }; // ------------------------------------------------------------------------------------------------ AI_FORCE_INLINE Vertex operator + (const Vertex& v0,const Vertex& v1) { return Vertex::BinaryOp<std::plus>(v0,v1); } AI_FORCE_INLINE Vertex operator - (const Vertex& v0,const Vertex& v1) { return Vertex::BinaryOp<std::minus>(v0,v1); } AI_FORCE_INLINE Vertex operator * (const Vertex& v0,ai_real f) { return Vertex::BinaryOp<Intern::multiplies>(v0,f); } AI_FORCE_INLINE Vertex operator / (const Vertex& v0,ai_real f) { return Vertex::BinaryOp<Intern::multiplies>(v0,1.f/f); } AI_FORCE_INLINE Vertex operator * (ai_real f,const Vertex& v0) { return Vertex::BinaryOp<Intern::multiplies>(f,v0); } } #endif // AI_VERTEX_H_INC
11,255
C
36.89899
117
0.571835
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/ai_assert.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file ai_assert.h * @brief Declares the assimp-specific assertion handler. */ #pragma once #ifndef AI_ASSERT_H_INC #define AI_ASSERT_H_INC #include <assimp/defs.h> #if defined(ASSIMP_BUILD_DEBUG) namespace Assimp { /// @brief Assert violation behavior can be customized: see AssertHandler.h. /// @param failedExpression The expression to validate. /// @param file The file location /// @param line The line number ASSIMP_API void aiAssertViolation(const char* failedExpression, const char* file, int line); } #endif // Define assertion resolinig #if defined(ASSIMP_BUILD_DEBUG) # define ai_assert(expression) (void)((!!(expression)) || (Assimp::aiAssertViolation(#expression, __FILE__, __LINE__), 0)) # define ai_assert_entry() ai_assert(false) #else # define ai_assert(expression) # define ai_assert_entry() #endif // ASSIMP_BUILD_DEBUG #endif // AI_ASSERT_H_INC
2,728
C
35.386666
124
0.697214
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/vector3.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file vector3.h * @brief 3D vector structure, including operators when compiling in C++ */ #pragma once #ifndef AI_VECTOR3D_H_INC #define AI_VECTOR3D_H_INC #ifdef __GNUC__ # pragma GCC system_header #endif #ifdef __cplusplus # include <cmath> #else # include <math.h> #endif #include <assimp/defs.h> #ifdef __cplusplus template<typename TReal> class aiMatrix3x3t; template<typename TReal> class aiMatrix4x4t; // --------------------------------------------------------------------------- /// @brief Represents a three-dimensional vector. // --------------------------------------------------------------------------- template <typename TReal> class aiVector3t { public: /// @brief The default class constructor. aiVector3t() AI_NO_EXCEPT : x(), y(), z() {} /// @brief The class constructor with the components. /// @param _x The x-component for the vector. /// @param _y The y-component for the vector. /// @param _z The z-component for the vector. aiVector3t(TReal _x, TReal _y, TReal _z) : x(_x), y(_y), z(_z) {} /// @brief The class constructor with a default value. /// @param _xyz The value for x, y and z. explicit aiVector3t (TReal _xyz ) : x(_xyz), y(_xyz), z(_xyz) {} /// @brief The copy constructor. /// @param o The instance to copy from. aiVector3t( const aiVector3t& o ) = default; /// @brief combined operators /// @brief The copy constructor. const aiVector3t& operator += (const aiVector3t& o); /// @brief The copy constructor. const aiVector3t& operator -= (const aiVector3t& o); /// @brief The copy constructor. const aiVector3t& operator *= (TReal f); /// @brief The copy constructor. const aiVector3t& operator /= (TReal f); /// @brief Transform vector by matrix aiVector3t& operator *= (const aiMatrix3x3t<TReal>& mat); aiVector3t& operator *= (const aiMatrix4x4t<TReal>& mat); /// @brief access a single element, const. TReal operator[](unsigned int i) const; /// @brief access a single element, non-const. TReal& operator[](unsigned int i); // comparison bool operator== (const aiVector3t& other) const; bool operator!= (const aiVector3t& other) const; bool operator < (const aiVector3t& other) const; /// @brief bool Equal(const aiVector3t &other, TReal epsilon = ai_epsilon) const; template <typename TOther> operator aiVector3t<TOther> () const; /** @brief Set the components of a vector * @param pX X component * @param pY Y component * @param pZ Z component */ void Set( TReal pX, TReal pY, TReal pZ); /** @brief Get the squared length of the vector * @return Square length */ TReal SquareLength() const; /** @brief Get the length of the vector * @return length */ TReal Length() const; /** @brief Normalize the vector */ aiVector3t& Normalize(); /** @brief Normalize the vector with extra check for zero vectors */ aiVector3t& NormalizeSafe(); /** @brief Componentwise multiplication of two vectors * * Note that vec*vec yields the dot product. * @param o Second factor */ const aiVector3t SymMul(const aiVector3t& o); TReal x, y, z; }; typedef aiVector3t<ai_real> aiVector3D; typedef aiVector3t<float> aiVector3f; typedef aiVector3t<double> aiVector3d; #else struct aiVector3D { ai_real x, y, z; }; #endif // __cplusplus #ifdef __cplusplus #endif // __cplusplus #endif // AI_VECTOR3D_H_INC
5,344
C
30.441176
78
0.647081
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/material.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file material.h * @brief Defines the material system of the library */ #pragma once #ifndef AI_MATERIAL_H_INC #define AI_MATERIAL_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #include <assimp/types.h> #ifdef __cplusplus extern "C" { #endif // Name for default materials (2nd is used if meshes have UV coords) #define AI_DEFAULT_MATERIAL_NAME "DefaultMaterial" // --------------------------------------------------------------------------- /** @brief Defines how the Nth texture of a specific type is combined with * the result of all previous layers. * * Example (left: key, right: value): <br> * @code * DiffColor0 - gray * DiffTextureOp0 - aiTextureOpMultiply * DiffTexture0 - tex1.png * DiffTextureOp0 - aiTextureOpAdd * DiffTexture1 - tex2.png * @endcode * Written as equation, the final diffuse term for a specific pixel would be: * @code * diffFinal = DiffColor0 * sampleTex(DiffTexture0,UV0) + * sampleTex(DiffTexture1,UV0) * diffContrib; * @endcode * where 'diffContrib' is the intensity of the incoming light for that pixel. */ enum aiTextureOp { /** T = T1 * T2 */ aiTextureOp_Multiply = 0x0, /** T = T1 + T2 */ aiTextureOp_Add = 0x1, /** T = T1 - T2 */ aiTextureOp_Subtract = 0x2, /** T = T1 / T2 */ aiTextureOp_Divide = 0x3, /** T = (T1 + T2) - (T1 * T2) */ aiTextureOp_SmoothAdd = 0x4, /** T = T1 + (T2-0.5) */ aiTextureOp_SignedAdd = 0x5, #ifndef SWIG _aiTextureOp_Force32Bit = INT_MAX #endif }; // --------------------------------------------------------------------------- /** @brief Defines how UV coordinates outside the [0...1] range are handled. * * Commonly referred to as 'wrapping mode'. */ enum aiTextureMapMode { /** A texture coordinate u|v is translated to u%1|v%1 */ aiTextureMapMode_Wrap = 0x0, /** Texture coordinates outside [0...1] * are clamped to the nearest valid value. */ aiTextureMapMode_Clamp = 0x1, /** If the texture coordinates for a pixel are outside [0...1] * the texture is not applied to that pixel */ aiTextureMapMode_Decal = 0x3, /** A texture coordinate u|v becomes u%1|v%1 if (u-(u%1))%2 is zero and * 1-(u%1)|1-(v%1) otherwise */ aiTextureMapMode_Mirror = 0x2, #ifndef SWIG _aiTextureMapMode_Force32Bit = INT_MAX #endif }; // --------------------------------------------------------------------------- /** @brief Defines how the mapping coords for a texture are generated. * * Real-time applications typically require full UV coordinates, so the use of * the aiProcess_GenUVCoords step is highly recommended. It generates proper * UV channels for non-UV mapped objects, as long as an accurate description * how the mapping should look like (e.g spherical) is given. * See the #AI_MATKEY_MAPPING property for more details. */ enum aiTextureMapping { /** The mapping coordinates are taken from an UV channel. * * #AI_MATKEY_UVWSRC property specifies from which UV channel * the texture coordinates are to be taken from (remember, * meshes can have more than one UV channel). */ aiTextureMapping_UV = 0x0, /** Spherical mapping */ aiTextureMapping_SPHERE = 0x1, /** Cylindrical mapping */ aiTextureMapping_CYLINDER = 0x2, /** Cubic mapping */ aiTextureMapping_BOX = 0x3, /** Planar mapping */ aiTextureMapping_PLANE = 0x4, /** Undefined mapping. Have fun. */ aiTextureMapping_OTHER = 0x5, #ifndef SWIG _aiTextureMapping_Force32Bit = INT_MAX #endif }; // --------------------------------------------------------------------------- /** @brief Defines the purpose of a texture * * This is a very difficult topic. Different 3D packages support different * kinds of textures. For very common texture types, such as bumpmaps, the * rendering results depend on implementation details in the rendering * pipelines of these applications. Assimp loads all texture references from * the model file and tries to determine which of the predefined texture * types below is the best choice to match the original use of the texture * as closely as possible.<br> * * In content pipelines you'll usually define how textures have to be handled, * and the artists working on models have to conform to this specification, * regardless which 3D tool they're using. */ enum aiTextureType { /** Dummy value. * * No texture, but the value to be used as 'texture semantic' * (#aiMaterialProperty::mSemantic) for all material properties * *not* related to textures. */ aiTextureType_NONE = 0, /** LEGACY API MATERIALS * Legacy refers to materials which * Were originally implemented in the specifications around 2000. * These must never be removed, as most engines support them. */ /** The texture is combined with the result of the diffuse * lighting equation. * OR * PBR Specular/Glossiness */ aiTextureType_DIFFUSE = 1, /** The texture is combined with the result of the specular * lighting equation. * OR * PBR Specular/Glossiness */ aiTextureType_SPECULAR = 2, /** The texture is combined with the result of the ambient * lighting equation. */ aiTextureType_AMBIENT = 3, /** The texture is added to the result of the lighting * calculation. It isn't influenced by incoming light. */ aiTextureType_EMISSIVE = 4, /** The texture is a height map. * * By convention, higher gray-scale values stand for * higher elevations from the base height. */ aiTextureType_HEIGHT = 5, /** The texture is a (tangent space) normal-map. * * Again, there are several conventions for tangent-space * normal maps. Assimp does (intentionally) not * distinguish here. */ aiTextureType_NORMALS = 6, /** The texture defines the glossiness of the material. * * The glossiness is in fact the exponent of the specular * (phong) lighting equation. Usually there is a conversion * function defined to map the linear color values in the * texture to a suitable exponent. Have fun. */ aiTextureType_SHININESS = 7, /** The texture defines per-pixel opacity. * * Usually 'white' means opaque and 'black' means * 'transparency'. Or quite the opposite. Have fun. */ aiTextureType_OPACITY = 8, /** Displacement texture * * The exact purpose and format is application-dependent. * Higher color values stand for higher vertex displacements. */ aiTextureType_DISPLACEMENT = 9, /** Lightmap texture (aka Ambient Occlusion) * * Both 'Lightmaps' and dedicated 'ambient occlusion maps' are * covered by this material property. The texture contains a * scaling value for the final color value of a pixel. Its * intensity is not affected by incoming light. */ aiTextureType_LIGHTMAP = 10, /** Reflection texture * * Contains the color of a perfect mirror reflection. * Rarely used, almost never for real-time applications. */ aiTextureType_REFLECTION = 11, /** PBR Materials * PBR definitions from maya and other modelling packages now use this standard. * This was originally introduced around 2012. * Support for this is in game engines like Godot, Unreal or Unity3D. * Modelling packages which use this are very common now. */ aiTextureType_BASE_COLOR = 12, aiTextureType_NORMAL_CAMERA = 13, aiTextureType_EMISSION_COLOR = 14, aiTextureType_METALNESS = 15, aiTextureType_DIFFUSE_ROUGHNESS = 16, aiTextureType_AMBIENT_OCCLUSION = 17, /** PBR Material Modifiers * Some modern renderers have further PBR modifiers that may be overlaid * on top of the 'base' PBR materials for additional realism. * These use multiple texture maps, so only the base type is directly defined */ /** Sheen * Generally used to simulate textiles that are covered in a layer of microfibers * eg velvet * https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_sheen */ aiTextureType_SHEEN = 19, /** Clearcoat * Simulates a layer of 'polish' or 'lacquer' layered on top of a PBR substrate * https://autodesk.github.io/standard-surface/#closures/coating * https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat */ aiTextureType_CLEARCOAT = 20, /** Transmission * Simulates transmission through the surface * May include further information such as wall thickness */ aiTextureType_TRANSMISSION = 21, /** Unknown texture * * A texture reference that does not match any of the definitions * above is considered to be 'unknown'. It is still imported, * but is excluded from any further post-processing. */ aiTextureType_UNKNOWN = 18, #ifndef SWIG _aiTextureType_Force32Bit = INT_MAX #endif }; #define AI_TEXTURE_TYPE_MAX aiTextureType_TRANSMISSION // ------------------------------------------------------------------------------- // Get a string for a given aiTextureType ASSIMP_API const char *aiTextureTypeToString(enum aiTextureType in); // --------------------------------------------------------------------------- /** @brief Defines all shading models supported by the library * * Property: #AI_MATKEY_SHADING_MODEL * * The list of shading modes has been taken from Blender. * See Blender documentation for more information. The API does * not distinguish between "specular" and "diffuse" shaders (thus the * specular term for diffuse shading models like Oren-Nayar remains * undefined). <br> * Again, this value is just a hint. Assimp tries to select the shader whose * most common implementation matches the original rendering results of the * 3D modeler which wrote a particular model as closely as possible. * */ enum aiShadingMode { /** Flat shading. Shading is done on per-face base, * diffuse only. Also known as 'faceted shading'. */ aiShadingMode_Flat = 0x1, /** Simple Gouraud shading. */ aiShadingMode_Gouraud = 0x2, /** Phong-Shading - */ aiShadingMode_Phong = 0x3, /** Phong-Blinn-Shading */ aiShadingMode_Blinn = 0x4, /** Toon-Shading per pixel * * Also known as 'comic' shader. */ aiShadingMode_Toon = 0x5, /** OrenNayar-Shading per pixel * * Extension to standard Lambertian shading, taking the * roughness of the material into account */ aiShadingMode_OrenNayar = 0x6, /** Minnaert-Shading per pixel * * Extension to standard Lambertian shading, taking the * "darkness" of the material into account */ aiShadingMode_Minnaert = 0x7, /** CookTorrance-Shading per pixel * * Special shader for metallic surfaces. */ aiShadingMode_CookTorrance = 0x8, /** No shading at all. Constant light influence of 1.0. * Also known as "Unlit" */ aiShadingMode_NoShading = 0x9, aiShadingMode_Unlit = aiShadingMode_NoShading, // Alias /** Fresnel shading */ aiShadingMode_Fresnel = 0xa, /** Physically-Based Rendering (PBR) shading using * Bidirectional scattering/reflectance distribution function (BSDF/BRDF) * There are multiple methods under this banner, and model files may provide * data for more than one PBR-BRDF method. * Applications should use the set of provided properties to determine which * of their preferred PBR rendering methods are likely to be available * eg: * - If AI_MATKEY_METALLIC_FACTOR is set, then a Metallic/Roughness is available * - If AI_MATKEY_GLOSSINESS_FACTOR is set, then a Specular/Glossiness is available * Note that some PBR methods allow layering of techniques */ aiShadingMode_PBR_BRDF = 0xb, #ifndef SWIG _aiShadingMode_Force32Bit = INT_MAX #endif }; // --------------------------------------------------------------------------- /** @brief Defines some mixed flags for a particular texture. * * Usually you'll instruct your cg artists how textures have to look like ... * and how they will be processed in your application. However, if you use * Assimp for completely generic loading purposes you might also need to * process these flags in order to display as many 'unknown' 3D models as * possible correctly. * * This corresponds to the #AI_MATKEY_TEXFLAGS property. */ enum aiTextureFlags { /** The texture's color values have to be inverted (component-wise 1-n) */ aiTextureFlags_Invert = 0x1, /** Explicit request to the application to process the alpha channel * of the texture. * * Mutually exclusive with #aiTextureFlags_IgnoreAlpha. These * flags are set if the library can say for sure that the alpha * channel is used/is not used. If the model format does not * define this, it is left to the application to decide whether * the texture alpha channel - if any - is evaluated or not. */ aiTextureFlags_UseAlpha = 0x2, /** Explicit request to the application to ignore the alpha channel * of the texture. * * Mutually exclusive with #aiTextureFlags_UseAlpha. */ aiTextureFlags_IgnoreAlpha = 0x4, #ifndef SWIG _aiTextureFlags_Force32Bit = INT_MAX #endif }; // --------------------------------------------------------------------------- /** @brief Defines alpha-blend flags. * * If you're familiar with OpenGL or D3D, these flags aren't new to you. * They define *how* the final color value of a pixel is computed, basing * on the previous color at that pixel and the new color value from the * material. * The blend formula is: * @code * SourceColor * SourceBlend + DestColor * DestBlend * @endcode * where DestColor is the previous color in the frame-buffer at this * position and SourceColor is the material color before the transparency * calculation.<br> * This corresponds to the #AI_MATKEY_BLEND_FUNC property. */ enum aiBlendMode { /** * Formula: * @code * SourceColor*SourceAlpha + DestColor*(1-SourceAlpha) * @endcode */ aiBlendMode_Default = 0x0, /** Additive blending * * Formula: * @code * SourceColor*1 + DestColor*1 * @endcode */ aiBlendMode_Additive = 0x1, // we don't need more for the moment, but we might need them // in future versions ... #ifndef SWIG _aiBlendMode_Force32Bit = INT_MAX #endif }; #include "./Compiler/pushpack1.h" // --------------------------------------------------------------------------- /** @brief Defines how an UV channel is transformed. * * This is just a helper structure for the #AI_MATKEY_UVTRANSFORM key. * See its documentation for more details. * * Typically you'll want to build a matrix of this information. However, * we keep separate scaling/translation/rotation values to make it * easier to process and optimize UV transformations internally. */ struct aiUVTransform { /** Translation on the u and v axes. * * The default value is (0|0). */ C_STRUCT aiVector2D mTranslation; /** Scaling on the u and v axes. * * The default value is (1|1). */ C_STRUCT aiVector2D mScaling; /** Rotation - in counter-clockwise direction. * * The rotation angle is specified in radians. The * rotation center is 0.5f|0.5f. The default value * 0.f. */ ai_real mRotation; #ifdef __cplusplus aiUVTransform() AI_NO_EXCEPT : mTranslation(0.0, 0.0), mScaling(1.0, 1.0), mRotation(0.0) { // nothing to be done here ... } #endif }; #include "./Compiler/poppack1.h" //! @cond AI_DOX_INCLUDE_INTERNAL // --------------------------------------------------------------------------- /** @brief A very primitive RTTI system for the contents of material * properties. */ enum aiPropertyTypeInfo { /** Array of single-precision (32 Bit) floats * * It is possible to use aiGetMaterialInteger[Array]() (or the C++-API * aiMaterial::Get()) to query properties stored in floating-point format. * The material system performs the type conversion automatically. */ aiPTI_Float = 0x1, /** Array of double-precision (64 Bit) floats * * It is possible to use aiGetMaterialInteger[Array]() (or the C++-API * aiMaterial::Get()) to query properties stored in floating-point format. * The material system performs the type conversion automatically. */ aiPTI_Double = 0x2, /** The material property is an aiString. * * Arrays of strings aren't possible, aiGetMaterialString() (or the * C++-API aiMaterial::Get()) *must* be used to query a string property. */ aiPTI_String = 0x3, /** Array of (32 Bit) integers * * It is possible to use aiGetMaterialFloat[Array]() (or the C++-API * aiMaterial::Get()) to query properties stored in integer format. * The material system performs the type conversion automatically. */ aiPTI_Integer = 0x4, /** Simple binary buffer, content undefined. Not convertible to anything. */ aiPTI_Buffer = 0x5, /** This value is not used. It is just there to force the * compiler to map this enum to a 32 Bit integer. */ #ifndef SWIG _aiPTI_Force32Bit = INT_MAX #endif }; // --------------------------------------------------------------------------- /** @brief Data structure for a single material property * * As an user, you'll probably never need to deal with this data structure. * Just use the provided aiGetMaterialXXX() or aiMaterial::Get() family * of functions to query material properties easily. Processing them * manually is faster, but it is not the recommended way. It isn't worth * the effort. <br> * Material property names follow a simple scheme: * @code * $<name> * ?<name> * A public property, there must be corresponding AI_MATKEY_XXX define * 2nd: Public, but ignored by the #aiProcess_RemoveRedundantMaterials * post-processing step. * ~<name> * A temporary property for internal use. * @endcode * @see aiMaterial */ struct aiMaterialProperty { /** Specifies the name of the property (key) * Keys are generally case insensitive. */ C_STRUCT aiString mKey; /** Textures: Specifies their exact usage semantic. * For non-texture properties, this member is always 0 * (or, better-said, #aiTextureType_NONE). */ unsigned int mSemantic; /** Textures: Specifies the index of the texture. * For non-texture properties, this member is always 0. */ unsigned int mIndex; /** Size of the buffer mData is pointing to, in bytes. * This value may not be 0. */ unsigned int mDataLength; /** Type information for the property. * * Defines the data layout inside the data buffer. This is used * by the library internally to perform debug checks and to * utilize proper type conversions. * (It's probably a hacky solution, but it works.) */ C_ENUM aiPropertyTypeInfo mType; /** Binary buffer to hold the property's value. * The size of the buffer is always mDataLength. */ char *mData; #ifdef __cplusplus aiMaterialProperty() AI_NO_EXCEPT : mSemantic(0), mIndex(0), mDataLength(0), mType(aiPTI_Float), mData(nullptr) { // empty } ~aiMaterialProperty() { delete[] mData; mData = nullptr; } #endif }; //! @endcond #ifdef __cplusplus } // We need to leave the "C" block here to allow template member functions #endif // --------------------------------------------------------------------------- /** @brief Data structure for a material * * Material data is stored using a key-value structure. A single key-value * pair is called a 'material property'. C++ users should use the provided * member functions of aiMaterial to process material properties, C users * have to stick with the aiMaterialGetXXX family of unbound functions. * The library defines a set of standard keys (AI_MATKEY_XXX). */ #ifdef __cplusplus struct ASSIMP_API aiMaterial #else struct aiMaterial #endif { #ifdef __cplusplus public: aiMaterial(); ~aiMaterial(); // ------------------------------------------------------------------- /** * @brief Returns the name of the material. * @return The name of the material. */ // ------------------------------------------------------------------- aiString GetName() const; // ------------------------------------------------------------------- /** @brief Retrieve an array of Type values with a specific key * from the material * * @param pKey Key to search for. One of the AI_MATKEY_XXX constants. * @param type .. set by AI_MATKEY_XXX * @param idx .. set by AI_MATKEY_XXX * @param pOut Pointer to a buffer to receive the result. * @param pMax Specifies the size of the given buffer, in Type's. * Receives the number of values (not bytes!) read. * NULL is a valid value for this parameter. */ template <typename Type> aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, Type *pOut, unsigned int *pMax) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, int *pOut, unsigned int *pMax) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, ai_real *pOut, unsigned int *pMax) const; // ------------------------------------------------------------------- /** @brief Retrieve a Type value with a specific key * from the material * * @param pKey Key to search for. One of the AI_MATKEY_XXX constants. * @param type Specifies the type of the texture to be retrieved ( * e.g. diffuse, specular, height map ...) * @param idx Index of the texture to be retrieved. * @param pOut Reference to receive the output value */ template <typename Type> aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, Type &pOut) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, int &pOut) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, ai_real &pOut) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, aiString &pOut) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, aiColor3D &pOut) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, aiColor4D &pOut) const; aiReturn Get(const char *pKey, unsigned int type, unsigned int idx, aiUVTransform &pOut) const; // ------------------------------------------------------------------- /** Get the number of textures for a particular texture type. * @param type Texture type to check for * @return Number of textures for this type. * @note A texture can be easily queried using #GetTexture() */ unsigned int GetTextureCount(aiTextureType type) const; // ------------------------------------------------------------------- /** Helper function to get all parameters pertaining to a * particular texture slot from a material. * * This function is provided just for convenience, you could also * read the single material properties manually. * @param type Specifies the type of the texture to be retrieved ( * e.g. diffuse, specular, height map ...) * @param index Index of the texture to be retrieved. The function fails * if there is no texture of that type with this index. * #GetTextureCount() can be used to determine the number of textures * per texture type. * @param path Receives the path to the texture. * Use aiScene::GetEmbeddedTexture() method to determine if returned path * is an image file to be opened or a string key of embedded texture stored in the corresponding scene * (could be a '*' followed by the id of the texture in case of no name) * NULL is a valid value. * @param mapping The texture mapping. * NULL is allowed as value. * @param uvindex Receives the UV index of the texture. * NULL is a valid value. * @param blend Receives the blend factor for the texture * NULL is a valid value. * @param op Receives the texture operation to be performed between * this texture and the previous texture. NULL is allowed as value. * @param mapmode Receives the mapping modes to be used for the texture. * The parameter may be NULL but if it is a valid pointer it MUST * point to an array of 3 aiTextureMapMode's (one for each * axis: UVW order (=XYZ)). */ // ------------------------------------------------------------------- aiReturn GetTexture(aiTextureType type, unsigned int index, C_STRUCT aiString *path, aiTextureMapping *mapping = NULL, unsigned int *uvindex = NULL, ai_real *blend = NULL, aiTextureOp *op = NULL, aiTextureMapMode *mapmode = NULL) const; // Setters // ------------------------------------------------------------------------------ /** @brief Add a property with a given key and type info to the material * structure * * @param pInput Pointer to input data * @param pSizeInBytes Size of input data * @param pKey Key/Usage of the property (AI_MATKEY_XXX) * @param type Set by the AI_MATKEY_XXX macro * @param index Set by the AI_MATKEY_XXX macro * @param pType Type information hint */ aiReturn AddBinaryProperty(const void *pInput, unsigned int pSizeInBytes, const char *pKey, unsigned int type, unsigned int index, aiPropertyTypeInfo pType); // ------------------------------------------------------------------------------ /** @brief Add a string property with a given key and type info to the * material structure * * @param pInput Input string * @param pKey Key/Usage of the property (AI_MATKEY_XXX) * @param type Set by the AI_MATKEY_XXX macro * @param index Set by the AI_MATKEY_XXX macro */ aiReturn AddProperty(const aiString *pInput, const char *pKey, unsigned int type = 0, unsigned int index = 0); // ------------------------------------------------------------------------------ /** @brief Add a property with a given key to the material structure * @param pInput Pointer to the input data * @param pNumValues Number of values in the array * @param pKey Key/Usage of the property (AI_MATKEY_XXX) * @param type Set by the AI_MATKEY_XXX macro * @param index Set by the AI_MATKEY_XXX macro */ template <class TYPE> aiReturn AddProperty(const TYPE *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const aiVector3D *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const aiColor3D *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const aiColor4D *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const int *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const float *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const double *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); aiReturn AddProperty(const aiUVTransform *pInput, unsigned int pNumValues, const char *pKey, unsigned int type = 0, unsigned int index = 0); // ------------------------------------------------------------------------------ /** @brief Remove a given key from the list. * * The function fails if the key isn't found * @param pKey Key to be deleted * @param type Set by the AI_MATKEY_XXX macro * @param index Set by the AI_MATKEY_XXX macro */ aiReturn RemoveProperty(const char *pKey, unsigned int type = 0, unsigned int index = 0); // ------------------------------------------------------------------------------ /** @brief Removes all properties from the material. * * The data array remains allocated so adding new properties is quite fast. */ void Clear(); // ------------------------------------------------------------------------------ /** Copy the property list of a material * @param pcDest Destination material * @param pcSrc Source material */ static void CopyPropertyList(aiMaterial *pcDest, const aiMaterial *pcSrc); #endif /** List of all material properties loaded. */ C_STRUCT aiMaterialProperty **mProperties; /** Number of properties in the data base */ unsigned int mNumProperties; /** Storage allocated */ unsigned int mNumAllocated; }; // Go back to extern "C" again #ifdef __cplusplus extern "C" { #endif // --------------------------------------------------------------------------- #define AI_MATKEY_NAME "?mat.name", 0, 0 #define AI_MATKEY_TWOSIDED "$mat.twosided", 0, 0 #define AI_MATKEY_SHADING_MODEL "$mat.shadingm", 0, 0 #define AI_MATKEY_ENABLE_WIREFRAME "$mat.wireframe", 0, 0 #define AI_MATKEY_BLEND_FUNC "$mat.blend", 0, 0 #define AI_MATKEY_OPACITY "$mat.opacity", 0, 0 #define AI_MATKEY_TRANSPARENCYFACTOR "$mat.transparencyfactor", 0, 0 #define AI_MATKEY_BUMPSCALING "$mat.bumpscaling", 0, 0 #define AI_MATKEY_SHININESS "$mat.shininess", 0, 0 #define AI_MATKEY_REFLECTIVITY "$mat.reflectivity", 0, 0 #define AI_MATKEY_SHININESS_STRENGTH "$mat.shinpercent", 0, 0 #define AI_MATKEY_REFRACTI "$mat.refracti", 0, 0 #define AI_MATKEY_COLOR_DIFFUSE "$clr.diffuse", 0, 0 #define AI_MATKEY_COLOR_AMBIENT "$clr.ambient", 0, 0 #define AI_MATKEY_COLOR_SPECULAR "$clr.specular", 0, 0 #define AI_MATKEY_COLOR_EMISSIVE "$clr.emissive", 0, 0 #define AI_MATKEY_COLOR_TRANSPARENT "$clr.transparent", 0, 0 #define AI_MATKEY_COLOR_REFLECTIVE "$clr.reflective", 0, 0 #define AI_MATKEY_GLOBAL_BACKGROUND_IMAGE "?bg.global", 0, 0 #define AI_MATKEY_GLOBAL_SHADERLANG "?sh.lang", 0, 0 #define AI_MATKEY_SHADER_VERTEX "?sh.vs", 0, 0 #define AI_MATKEY_SHADER_FRAGMENT "?sh.fs", 0, 0 #define AI_MATKEY_SHADER_GEO "?sh.gs", 0, 0 #define AI_MATKEY_SHADER_TESSELATION "?sh.ts", 0, 0 #define AI_MATKEY_SHADER_PRIMITIVE "?sh.ps", 0, 0 #define AI_MATKEY_SHADER_COMPUTE "?sh.cs", 0, 0 // --------------------------------------------------------------------------- // PBR material support // -------------------- // Properties defining PBR rendering techniques #define AI_MATKEY_USE_COLOR_MAP "$mat.useColorMap", 0, 0 // Metallic/Roughness Workflow // --------------------------- // Base RGBA color factor. Will be multiplied by final base color texture values if extant // Note: Importers may choose to copy this into AI_MATKEY_COLOR_DIFFUSE for compatibility // with renderers and formats that do not support Metallic/Roughness PBR #define AI_MATKEY_BASE_COLOR "$clr.base", 0, 0 #define AI_MATKEY_BASE_COLOR_TEXTURE aiTextureType_BASE_COLOR, 0 #define AI_MATKEY_USE_METALLIC_MAP "$mat.useMetallicMap", 0, 0 // Metallic factor. 0.0 = Full Dielectric, 1.0 = Full Metal #define AI_MATKEY_METALLIC_FACTOR "$mat.metallicFactor", 0, 0 #define AI_MATKEY_METALLIC_TEXTURE aiTextureType_METALNESS, 0 #define AI_MATKEY_USE_ROUGHNESS_MAP "$mat.useRoughnessMap", 0, 0 // Roughness factor. 0.0 = Perfectly Smooth, 1.0 = Completely Rough #define AI_MATKEY_ROUGHNESS_FACTOR "$mat.roughnessFactor", 0, 0 #define AI_MATKEY_ROUGHNESS_TEXTURE aiTextureType_DIFFUSE_ROUGHNESS, 0 // Anisotropy factor. 0.0 = isotropic, 1.0 = anisotropy along tangent direction, // -1.0 = anisotropy along bitangent direction #define AI_MATKEY_ANISOTROPY_FACTOR "$mat.anisotropyFactor", 0, 0 // Specular/Glossiness Workflow // --------------------------- // Diffuse/Albedo Color. Note: Pure Metals have a diffuse of {0,0,0} // AI_MATKEY_COLOR_DIFFUSE // Specular Color. // Note: Metallic/Roughness may also have a Specular Color // AI_MATKEY_COLOR_SPECULAR #define AI_MATKEY_SPECULAR_FACTOR "$mat.specularFactor", 0, 0 // Glossiness factor. 0.0 = Completely Rough, 1.0 = Perfectly Smooth #define AI_MATKEY_GLOSSINESS_FACTOR "$mat.glossinessFactor", 0, 0 // Sheen // ----- // Sheen base RGB color. Default {0,0,0} #define AI_MATKEY_SHEEN_COLOR_FACTOR "$clr.sheen.factor", 0, 0 // Sheen Roughness Factor. #define AI_MATKEY_SHEEN_ROUGHNESS_FACTOR "$mat.sheen.roughnessFactor", 0, 0 #define AI_MATKEY_SHEEN_COLOR_TEXTURE aiTextureType_SHEEN, 0 #define AI_MATKEY_SHEEN_ROUGHNESS_TEXTURE aiTextureType_SHEEN, 1 // Clearcoat // --------- // Clearcoat layer intensity. 0.0 = none (disabled) #define AI_MATKEY_CLEARCOAT_FACTOR "$mat.clearcoat.factor", 0, 0 #define AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR "$mat.clearcoat.roughnessFactor", 0, 0 #define AI_MATKEY_CLEARCOAT_TEXTURE aiTextureType_CLEARCOAT, 0 #define AI_MATKEY_CLEARCOAT_ROUGHNESS_TEXTURE aiTextureType_CLEARCOAT, 1 #define AI_MATKEY_CLEARCOAT_NORMAL_TEXTURE aiTextureType_CLEARCOAT, 2 // Transmission // ------------ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission // Base percentage of light transmitted through the surface. 0.0 = Opaque, 1.0 = Fully transparent #define AI_MATKEY_TRANSMISSION_FACTOR "$mat.transmission.factor", 0, 0 // Texture defining percentage of light transmitted through the surface. // Multiplied by AI_MATKEY_TRANSMISSION_FACTOR #define AI_MATKEY_TRANSMISSION_TEXTURE aiTextureType_TRANSMISSION, 0 // Volume // ------------ // https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_volume // The thickness of the volume beneath the surface. If the value is 0 the material is thin-walled. Otherwise the material is a volume boundary. #define AI_MATKEY_VOLUME_THICKNESS_FACTOR "$mat.volume.thicknessFactor", 0, 0 // Texture that defines the thickness. // Multiplied by AI_MATKEY_THICKNESS_FACTOR #define AI_MATKEY_VOLUME_THICKNESS_TEXTURE aiTextureType_TRANSMISSION, 1 // Density of the medium given as the average distance that light travels in the medium before interacting with a particle. #define AI_MATKEY_VOLUME_ATTENUATION_DISTANCE "$mat.volume.attenuationDistance", 0, 0 // The color that white light turns into due to absorption when reaching the attenuation distance. #define AI_MATKEY_VOLUME_ATTENUATION_COLOR "$mat.volume.attenuationColor", 0, 0 // Emissive // -------- #define AI_MATKEY_USE_EMISSIVE_MAP "$mat.useEmissiveMap", 0, 0 #define AI_MATKEY_EMISSIVE_INTENSITY "$mat.emissiveIntensity", 0, 0 #define AI_MATKEY_USE_AO_MAP "$mat.useAOMap", 0, 0 // --------------------------------------------------------------------------- // Pure key names for all texture-related properties //! @cond MATS_DOC_FULL #define _AI_MATKEY_TEXTURE_BASE "$tex.file" #define _AI_MATKEY_UVWSRC_BASE "$tex.uvwsrc" #define _AI_MATKEY_TEXOP_BASE "$tex.op" #define _AI_MATKEY_MAPPING_BASE "$tex.mapping" #define _AI_MATKEY_TEXBLEND_BASE "$tex.blend" #define _AI_MATKEY_MAPPINGMODE_U_BASE "$tex.mapmodeu" #define _AI_MATKEY_MAPPINGMODE_V_BASE "$tex.mapmodev" #define _AI_MATKEY_TEXMAP_AXIS_BASE "$tex.mapaxis" #define _AI_MATKEY_UVTRANSFORM_BASE "$tex.uvtrafo" #define _AI_MATKEY_TEXFLAGS_BASE "$tex.flags" //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_TEXTURE(type, N) _AI_MATKEY_TEXTURE_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_TEXTURE_DIFFUSE(N) \ AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, N) #define AI_MATKEY_TEXTURE_SPECULAR(N) \ AI_MATKEY_TEXTURE(aiTextureType_SPECULAR, N) #define AI_MATKEY_TEXTURE_AMBIENT(N) \ AI_MATKEY_TEXTURE(aiTextureType_AMBIENT, N) #define AI_MATKEY_TEXTURE_EMISSIVE(N) \ AI_MATKEY_TEXTURE(aiTextureType_EMISSIVE, N) #define AI_MATKEY_TEXTURE_NORMALS(N) \ AI_MATKEY_TEXTURE(aiTextureType_NORMALS, N) #define AI_MATKEY_TEXTURE_HEIGHT(N) \ AI_MATKEY_TEXTURE(aiTextureType_HEIGHT, N) #define AI_MATKEY_TEXTURE_SHININESS(N) \ AI_MATKEY_TEXTURE(aiTextureType_SHININESS, N) #define AI_MATKEY_TEXTURE_OPACITY(N) \ AI_MATKEY_TEXTURE(aiTextureType_OPACITY, N) #define AI_MATKEY_TEXTURE_DISPLACEMENT(N) \ AI_MATKEY_TEXTURE(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_TEXTURE_LIGHTMAP(N) \ AI_MATKEY_TEXTURE(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_TEXTURE_REFLECTION(N) \ AI_MATKEY_TEXTURE(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_UVWSRC(type, N) _AI_MATKEY_UVWSRC_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_UVWSRC_DIFFUSE(N) \ AI_MATKEY_UVWSRC(aiTextureType_DIFFUSE, N) #define AI_MATKEY_UVWSRC_SPECULAR(N) \ AI_MATKEY_UVWSRC(aiTextureType_SPECULAR, N) #define AI_MATKEY_UVWSRC_AMBIENT(N) \ AI_MATKEY_UVWSRC(aiTextureType_AMBIENT, N) #define AI_MATKEY_UVWSRC_EMISSIVE(N) \ AI_MATKEY_UVWSRC(aiTextureType_EMISSIVE, N) #define AI_MATKEY_UVWSRC_NORMALS(N) \ AI_MATKEY_UVWSRC(aiTextureType_NORMALS, N) #define AI_MATKEY_UVWSRC_HEIGHT(N) \ AI_MATKEY_UVWSRC(aiTextureType_HEIGHT, N) #define AI_MATKEY_UVWSRC_SHININESS(N) \ AI_MATKEY_UVWSRC(aiTextureType_SHININESS, N) #define AI_MATKEY_UVWSRC_OPACITY(N) \ AI_MATKEY_UVWSRC(aiTextureType_OPACITY, N) #define AI_MATKEY_UVWSRC_DISPLACEMENT(N) \ AI_MATKEY_UVWSRC(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_UVWSRC_LIGHTMAP(N) \ AI_MATKEY_UVWSRC(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_UVWSRC_REFLECTION(N) \ AI_MATKEY_UVWSRC(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_TEXOP(type, N) _AI_MATKEY_TEXOP_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_TEXOP_DIFFUSE(N) \ AI_MATKEY_TEXOP(aiTextureType_DIFFUSE, N) #define AI_MATKEY_TEXOP_SPECULAR(N) \ AI_MATKEY_TEXOP(aiTextureType_SPECULAR, N) #define AI_MATKEY_TEXOP_AMBIENT(N) \ AI_MATKEY_TEXOP(aiTextureType_AMBIENT, N) #define AI_MATKEY_TEXOP_EMISSIVE(N) \ AI_MATKEY_TEXOP(aiTextureType_EMISSIVE, N) #define AI_MATKEY_TEXOP_NORMALS(N) \ AI_MATKEY_TEXOP(aiTextureType_NORMALS, N) #define AI_MATKEY_TEXOP_HEIGHT(N) \ AI_MATKEY_TEXOP(aiTextureType_HEIGHT, N) #define AI_MATKEY_TEXOP_SHININESS(N) \ AI_MATKEY_TEXOP(aiTextureType_SHININESS, N) #define AI_MATKEY_TEXOP_OPACITY(N) \ AI_MATKEY_TEXOP(aiTextureType_OPACITY, N) #define AI_MATKEY_TEXOP_DISPLACEMENT(N) \ AI_MATKEY_TEXOP(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_TEXOP_LIGHTMAP(N) \ AI_MATKEY_TEXOP(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_TEXOP_REFLECTION(N) \ AI_MATKEY_TEXOP(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_MAPPING(type, N) _AI_MATKEY_MAPPING_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_MAPPING_DIFFUSE(N) \ AI_MATKEY_MAPPING(aiTextureType_DIFFUSE, N) #define AI_MATKEY_MAPPING_SPECULAR(N) \ AI_MATKEY_MAPPING(aiTextureType_SPECULAR, N) #define AI_MATKEY_MAPPING_AMBIENT(N) \ AI_MATKEY_MAPPING(aiTextureType_AMBIENT, N) #define AI_MATKEY_MAPPING_EMISSIVE(N) \ AI_MATKEY_MAPPING(aiTextureType_EMISSIVE, N) #define AI_MATKEY_MAPPING_NORMALS(N) \ AI_MATKEY_MAPPING(aiTextureType_NORMALS, N) #define AI_MATKEY_MAPPING_HEIGHT(N) \ AI_MATKEY_MAPPING(aiTextureType_HEIGHT, N) #define AI_MATKEY_MAPPING_SHININESS(N) \ AI_MATKEY_MAPPING(aiTextureType_SHININESS, N) #define AI_MATKEY_MAPPING_OPACITY(N) \ AI_MATKEY_MAPPING(aiTextureType_OPACITY, N) #define AI_MATKEY_MAPPING_DISPLACEMENT(N) \ AI_MATKEY_MAPPING(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_MAPPING_LIGHTMAP(N) \ AI_MATKEY_MAPPING(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_MAPPING_REFLECTION(N) \ AI_MATKEY_MAPPING(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_TEXBLEND(type, N) _AI_MATKEY_TEXBLEND_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_TEXBLEND_DIFFUSE(N) \ AI_MATKEY_TEXBLEND(aiTextureType_DIFFUSE, N) #define AI_MATKEY_TEXBLEND_SPECULAR(N) \ AI_MATKEY_TEXBLEND(aiTextureType_SPECULAR, N) #define AI_MATKEY_TEXBLEND_AMBIENT(N) \ AI_MATKEY_TEXBLEND(aiTextureType_AMBIENT, N) #define AI_MATKEY_TEXBLEND_EMISSIVE(N) \ AI_MATKEY_TEXBLEND(aiTextureType_EMISSIVE, N) #define AI_MATKEY_TEXBLEND_NORMALS(N) \ AI_MATKEY_TEXBLEND(aiTextureType_NORMALS, N) #define AI_MATKEY_TEXBLEND_HEIGHT(N) \ AI_MATKEY_TEXBLEND(aiTextureType_HEIGHT, N) #define AI_MATKEY_TEXBLEND_SHININESS(N) \ AI_MATKEY_TEXBLEND(aiTextureType_SHININESS, N) #define AI_MATKEY_TEXBLEND_OPACITY(N) \ AI_MATKEY_TEXBLEND(aiTextureType_OPACITY, N) #define AI_MATKEY_TEXBLEND_DISPLACEMENT(N) \ AI_MATKEY_TEXBLEND(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_TEXBLEND_LIGHTMAP(N) \ AI_MATKEY_TEXBLEND(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_TEXBLEND_REFLECTION(N) \ AI_MATKEY_TEXBLEND(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_MAPPINGMODE_U(type, N) _AI_MATKEY_MAPPINGMODE_U_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_MAPPINGMODE_U_DIFFUSE(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_DIFFUSE, N) #define AI_MATKEY_MAPPINGMODE_U_SPECULAR(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_SPECULAR, N) #define AI_MATKEY_MAPPINGMODE_U_AMBIENT(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_AMBIENT, N) #define AI_MATKEY_MAPPINGMODE_U_EMISSIVE(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_EMISSIVE, N) #define AI_MATKEY_MAPPINGMODE_U_NORMALS(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_NORMALS, N) #define AI_MATKEY_MAPPINGMODE_U_HEIGHT(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_HEIGHT, N) #define AI_MATKEY_MAPPINGMODE_U_SHININESS(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_SHININESS, N) #define AI_MATKEY_MAPPINGMODE_U_OPACITY(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_OPACITY, N) #define AI_MATKEY_MAPPINGMODE_U_DISPLACEMENT(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_MAPPINGMODE_U_LIGHTMAP(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_MAPPINGMODE_U_REFLECTION(N) \ AI_MATKEY_MAPPINGMODE_U(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_MAPPINGMODE_V(type, N) _AI_MATKEY_MAPPINGMODE_V_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_MAPPINGMODE_V_DIFFUSE(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_DIFFUSE, N) #define AI_MATKEY_MAPPINGMODE_V_SPECULAR(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_SPECULAR, N) #define AI_MATKEY_MAPPINGMODE_V_AMBIENT(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_AMBIENT, N) #define AI_MATKEY_MAPPINGMODE_V_EMISSIVE(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_EMISSIVE, N) #define AI_MATKEY_MAPPINGMODE_V_NORMALS(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_NORMALS, N) #define AI_MATKEY_MAPPINGMODE_V_HEIGHT(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_HEIGHT, N) #define AI_MATKEY_MAPPINGMODE_V_SHININESS(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_SHININESS, N) #define AI_MATKEY_MAPPINGMODE_V_OPACITY(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_OPACITY, N) #define AI_MATKEY_MAPPINGMODE_V_DISPLACEMENT(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_MAPPINGMODE_V_LIGHTMAP(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_MAPPINGMODE_V_REFLECTION(N) \ AI_MATKEY_MAPPINGMODE_V(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_TEXMAP_AXIS(type, N) _AI_MATKEY_TEXMAP_AXIS_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_TEXMAP_AXIS_DIFFUSE(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_DIFFUSE, N) #define AI_MATKEY_TEXMAP_AXIS_SPECULAR(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_SPECULAR, N) #define AI_MATKEY_TEXMAP_AXIS_AMBIENT(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_AMBIENT, N) #define AI_MATKEY_TEXMAP_AXIS_EMISSIVE(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_EMISSIVE, N) #define AI_MATKEY_TEXMAP_AXIS_NORMALS(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_NORMALS, N) #define AI_MATKEY_TEXMAP_AXIS_HEIGHT(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_HEIGHT, N) #define AI_MATKEY_TEXMAP_AXIS_SHININESS(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_SHININESS, N) #define AI_MATKEY_TEXMAP_AXIS_OPACITY(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_OPACITY, N) #define AI_MATKEY_TEXMAP_AXIS_DISPLACEMENT(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_TEXMAP_AXIS_LIGHTMAP(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_TEXMAP_AXIS_REFLECTION(N) \ AI_MATKEY_TEXMAP_AXIS(aiTextureType_REFLECTION, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_UVTRANSFORM(type, N) _AI_MATKEY_UVTRANSFORM_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_UVTRANSFORM_DIFFUSE(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_DIFFUSE, N) #define AI_MATKEY_UVTRANSFORM_SPECULAR(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_SPECULAR, N) #define AI_MATKEY_UVTRANSFORM_AMBIENT(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_AMBIENT, N) #define AI_MATKEY_UVTRANSFORM_EMISSIVE(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_EMISSIVE, N) #define AI_MATKEY_UVTRANSFORM_NORMALS(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_NORMALS, N) #define AI_MATKEY_UVTRANSFORM_HEIGHT(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_HEIGHT, N) #define AI_MATKEY_UVTRANSFORM_SHININESS(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_SHININESS, N) #define AI_MATKEY_UVTRANSFORM_OPACITY(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_OPACITY, N) #define AI_MATKEY_UVTRANSFORM_DISPLACEMENT(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_UVTRANSFORM_LIGHTMAP(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_UVTRANSFORM_REFLECTION(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_REFLECTION, N) #define AI_MATKEY_UVTRANSFORM_UNKNOWN(N) \ AI_MATKEY_UVTRANSFORM(aiTextureType_UNKNOWN, N) //! @endcond // --------------------------------------------------------------------------- #define AI_MATKEY_TEXFLAGS(type, N) _AI_MATKEY_TEXFLAGS_BASE, type, N // For backward compatibility and simplicity //! @cond MATS_DOC_FULL #define AI_MATKEY_TEXFLAGS_DIFFUSE(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_DIFFUSE, N) #define AI_MATKEY_TEXFLAGS_SPECULAR(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_SPECULAR, N) #define AI_MATKEY_TEXFLAGS_AMBIENT(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_AMBIENT, N) #define AI_MATKEY_TEXFLAGS_EMISSIVE(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_EMISSIVE, N) #define AI_MATKEY_TEXFLAGS_NORMALS(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_NORMALS, N) #define AI_MATKEY_TEXFLAGS_HEIGHT(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_HEIGHT, N) #define AI_MATKEY_TEXFLAGS_SHININESS(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_SHININESS, N) #define AI_MATKEY_TEXFLAGS_OPACITY(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_OPACITY, N) #define AI_MATKEY_TEXFLAGS_DISPLACEMENT(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_DISPLACEMENT, N) #define AI_MATKEY_TEXFLAGS_LIGHTMAP(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_LIGHTMAP, N) #define AI_MATKEY_TEXFLAGS_REFLECTION(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_REFLECTION, N) #define AI_MATKEY_TEXFLAGS_UNKNOWN(N) \ AI_MATKEY_TEXFLAGS(aiTextureType_UNKNOWN, N) //! @endcond //! // --------------------------------------------------------------------------- /** @brief Retrieve a material property with a specific key from the material * * @param pMat Pointer to the input material. May not be NULL * @param pKey Key to search for. One of the AI_MATKEY_XXX constants. * @param type Specifies the type of the texture to be retrieved ( * e.g. diffuse, specular, height map ...) * @param index Index of the texture to be retrieved. * @param pPropOut Pointer to receive a pointer to a valid aiMaterialProperty * structure or NULL if the key has not been found. */ // --------------------------------------------------------------------------- ASSIMP_API C_ENUM aiReturn aiGetMaterialProperty( const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, const C_STRUCT aiMaterialProperty **pPropOut); // --------------------------------------------------------------------------- /** @brief Retrieve an array of float values with a specific key * from the material * * Pass one of the AI_MATKEY_XXX constants for the last three parameters (the * example reads the #AI_MATKEY_UVTRANSFORM property of the first diffuse texture) * @code * aiUVTransform trafo; * unsigned int max = sizeof(aiUVTransform); * if (AI_SUCCESS != aiGetMaterialFloatArray(mat, AI_MATKEY_UVTRANSFORM(aiTextureType_DIFFUSE,0), * (float*)&trafo, &max) || sizeof(aiUVTransform) != max) * { * // error handling * } * @endcode * * @param pMat Pointer to the input material. May not be NULL * @param pKey Key to search for. One of the AI_MATKEY_XXX constants. * @param pOut Pointer to a buffer to receive the result. * @param pMax Specifies the size of the given buffer, in float's. * Receives the number of values (not bytes!) read. * @param type (see the code sample above) * @param index (see the code sample above) * @return Specifies whether the key has been found. If not, the output * arrays remains unmodified and pMax is set to 0.*/ // --------------------------------------------------------------------------- ASSIMP_API C_ENUM aiReturn aiGetMaterialFloatArray( const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, ai_real *pOut, unsigned int *pMax); // --------------------------------------------------------------------------- /** @brief Retrieve a single float property with a specific key from the material. * * Pass one of the AI_MATKEY_XXX constants for the last three parameters (the * example reads the #AI_MATKEY_SHININESS_STRENGTH property of the first diffuse texture) * @code * float specStrength = 1.f; // default value, remains unmodified if we fail. * aiGetMaterialFloat(mat, AI_MATKEY_SHININESS_STRENGTH, * (float*)&specStrength); * @endcode * * @param pMat Pointer to the input material. May not be NULL * @param pKey Key to search for. One of the AI_MATKEY_XXX constants. * @param pOut Receives the output float. * @param type (see the code sample above) * @param index (see the code sample above) * @return Specifies whether the key has been found. If not, the output * float remains unmodified.*/ // --------------------------------------------------------------------------- inline aiReturn aiGetMaterialFloat(const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, ai_real *pOut) { return aiGetMaterialFloatArray(pMat, pKey, type, index, pOut, (unsigned int *)0x0); } // --------------------------------------------------------------------------- /** @brief Retrieve an array of integer values with a specific key * from a material * * See the sample for aiGetMaterialFloatArray for more information.*/ ASSIMP_API C_ENUM aiReturn aiGetMaterialIntegerArray(const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, int *pOut, unsigned int *pMax); // --------------------------------------------------------------------------- /** @brief Retrieve an integer property with a specific key from a material * * See the sample for aiGetMaterialFloat for more information.*/ // --------------------------------------------------------------------------- inline aiReturn aiGetMaterialInteger(const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, int *pOut) { return aiGetMaterialIntegerArray(pMat, pKey, type, index, pOut, (unsigned int *)0x0); } // --------------------------------------------------------------------------- /** @brief Retrieve a color value from the material property table * * See the sample for aiGetMaterialFloat for more information*/ // --------------------------------------------------------------------------- ASSIMP_API C_ENUM aiReturn aiGetMaterialColor(const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, C_STRUCT aiColor4D *pOut); // --------------------------------------------------------------------------- /** @brief Retrieve a aiUVTransform value from the material property table * * See the sample for aiGetMaterialFloat for more information*/ // --------------------------------------------------------------------------- ASSIMP_API C_ENUM aiReturn aiGetMaterialUVTransform(const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, C_STRUCT aiUVTransform *pOut); // --------------------------------------------------------------------------- /** @brief Retrieve a string from the material property table * * See the sample for aiGetMaterialFloat for more information.*/ // --------------------------------------------------------------------------- ASSIMP_API C_ENUM aiReturn aiGetMaterialString(const C_STRUCT aiMaterial *pMat, const char *pKey, unsigned int type, unsigned int index, C_STRUCT aiString *pOut); // --------------------------------------------------------------------------- /** Get the number of textures for a particular texture type. * @param[in] pMat Pointer to the input material. May not be NULL * @param type Texture type to check for * @return Number of textures for this type. * @note A texture can be easily queried using #aiGetMaterialTexture() */ // --------------------------------------------------------------------------- ASSIMP_API unsigned int aiGetMaterialTextureCount(const C_STRUCT aiMaterial *pMat, C_ENUM aiTextureType type); // --------------------------------------------------------------------------- /** @brief Helper function to get all values pertaining to a particular * texture slot from a material structure. * * This function is provided just for convenience. You could also read the * texture by parsing all of its properties manually. This function bundles * all of them in a huge function monster. * * @param[in] mat Pointer to the input material. May not be NULL * @param[in] type Specifies the texture stack to read from (e.g. diffuse, * specular, height map ...). * @param[in] index Index of the texture. The function fails if the * requested index is not available for this texture type. * #aiGetMaterialTextureCount() can be used to determine the number of * textures in a particular texture stack. * @param[out] path Receives the output path * If the texture is embedded, receives a '*' followed by the id of * the texture (for the textures stored in the corresponding scene) which * can be converted to an int using a function like atoi. * This parameter must be non-null. * @param mapping The texture mapping mode to be used. * Pass NULL if you're not interested in this information. * @param[out] uvindex For UV-mapped textures: receives the index of the UV * source channel. Unmodified otherwise. * Pass NULL if you're not interested in this information. * @param[out] blend Receives the blend factor for the texture * Pass NULL if you're not interested in this information. * @param[out] op Receives the texture blend operation to be perform between * this texture and the previous texture. * Pass NULL if you're not interested in this information. * @param[out] mapmode Receives the mapping modes to be used for the texture. * Pass NULL if you're not interested in this information. Otherwise, * pass a pointer to an array of two aiTextureMapMode's (one for each * axis, UV order). * @param[out] flags Receives the the texture flags. * @return AI_SUCCESS on success, otherwise something else. Have fun.*/ // --------------------------------------------------------------------------- #ifdef __cplusplus ASSIMP_API aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial *mat, aiTextureType type, unsigned int index, aiString *path, aiTextureMapping *mapping = NULL, unsigned int *uvindex = NULL, ai_real *blend = NULL, aiTextureOp *op = NULL, aiTextureMapMode *mapmode = NULL, unsigned int *flags = NULL); #else C_ENUM aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial *mat, C_ENUM aiTextureType type, unsigned int index, C_STRUCT aiString *path, C_ENUM aiTextureMapping *mapping /*= NULL*/, unsigned int *uvindex /*= NULL*/, ai_real *blend /*= NULL*/, C_ENUM aiTextureOp *op /*= NULL*/, C_ENUM aiTextureMapMode *mapmode /*= NULL*/, unsigned int *flags /*= NULL*/); #endif // !#ifdef __cplusplus #ifdef __cplusplus } #include "material.inl" #endif //!__cplusplus #endif //!!AI_MATERIAL_H_INC
61,056
C
35.300238
143
0.640805
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/mesh.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2023, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ /** @file mesh.h * @brief Declares the data structures in which the imported geometry is returned by ASSIMP: aiMesh, aiFace and aiBone data structures. */ #pragma once #ifndef AI_MESH_H_INC #define AI_MESH_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #ifdef _MSC_VER #pragma warning(disable : 4351) #endif // _MSC_VER #include <assimp/aabb.h> #include <assimp/types.h> #ifdef __cplusplus #include <unordered_set> extern "C" { #endif // --------------------------------------------------------------------------- // Limits. These values are required to match the settings Assimp was // compiled against. Therefore, do not redefine them unless you build the // library from source using the same definitions. // --------------------------------------------------------------------------- /** @def AI_MAX_FACE_INDICES * Maximum number of indices per face (polygon). */ #ifndef AI_MAX_FACE_INDICES #define AI_MAX_FACE_INDICES 0x7fff #endif /** @def AI_MAX_BONE_WEIGHTS * Maximum number of indices per face (polygon). */ #ifndef AI_MAX_BONE_WEIGHTS #define AI_MAX_BONE_WEIGHTS 0x7fffffff #endif /** @def AI_MAX_VERTICES * Maximum number of vertices per mesh. */ #ifndef AI_MAX_VERTICES #define AI_MAX_VERTICES 0x7fffffff #endif /** @def AI_MAX_FACES * Maximum number of faces per mesh. */ #ifndef AI_MAX_FACES #define AI_MAX_FACES 0x7fffffff #endif /** @def AI_MAX_NUMBER_OF_COLOR_SETS * Supported number of vertex color sets per mesh. */ #ifndef AI_MAX_NUMBER_OF_COLOR_SETS #define AI_MAX_NUMBER_OF_COLOR_SETS 0x8 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS /** @def AI_MAX_NUMBER_OF_TEXTURECOORDS * Supported number of texture coord sets (UV(W) channels) per mesh */ #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS #define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8 #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS // --------------------------------------------------------------------------- /** * @brief A single face in a mesh, referring to multiple vertices. * * If mNumIndices is 3, we call the face 'triangle', for mNumIndices > 3 * it's called 'polygon' (hey, that's just a definition!). * <br> * aiMesh::mPrimitiveTypes can be queried to quickly examine which types of * primitive are actually present in a mesh. The #aiProcess_SortByPType flag * executes a special post-processing algorithm which splits meshes with * *different* primitive types mixed up (e.g. lines and triangles) in several * 'clean' sub-meshes. Furthermore there is a configuration option ( * #AI_CONFIG_PP_SBP_REMOVE) to force #aiProcess_SortByPType to remove * specific kinds of primitives from the imported scene, completely and forever. * In many cases you'll probably want to set this setting to * @code * aiPrimitiveType_LINE|aiPrimitiveType_POINT * @endcode * Together with the #aiProcess_Triangulate flag you can then be sure that * #aiFace::mNumIndices is always 3. * @note Take a look at the @link data Data Structures page @endlink for * more information on the layout and winding order of a face. */ struct aiFace { //! Number of indices defining this face. //! The maximum value for this member is #AI_MAX_FACE_INDICES. unsigned int mNumIndices; //! Pointer to the indices array. Size of the array is given in numIndices. unsigned int *mIndices; #ifdef __cplusplus //! @brief Default constructor. aiFace() AI_NO_EXCEPT : mNumIndices(0), mIndices(nullptr) { // empty } //! @brief Default destructor. Delete the index array ~aiFace() { delete[] mIndices; } //! @brief Copy constructor. Copy the index array aiFace(const aiFace &o) : mNumIndices(0), mIndices(nullptr) { *this = o; } //! @brief Assignment operator. Copy the index array aiFace &operator=(const aiFace &o) { if (&o == this) { return *this; } delete[] mIndices; mNumIndices = o.mNumIndices; if (mNumIndices) { mIndices = new unsigned int[mNumIndices]; ::memcpy(mIndices, o.mIndices, mNumIndices * sizeof(unsigned int)); } else { mIndices = nullptr; } return *this; } //! @brief Comparison operator. Checks whether the index array of two faces is identical. bool operator==(const aiFace &o) const { if (mIndices == o.mIndices) { return true; } if (nullptr != mIndices && mNumIndices != o.mNumIndices) { return false; } if (nullptr == mIndices) { return false; } for (unsigned int i = 0; i < this->mNumIndices; ++i) { if (mIndices[i] != o.mIndices[i]) { return false; } } return true; } //! @brief Inverse comparison operator. Checks whether the index //! array of two faces is NOT identical bool operator!=(const aiFace &o) const { return !(*this == o); } #endif // __cplusplus }; // struct aiFace // --------------------------------------------------------------------------- /** @brief A single influence of a bone on a vertex. */ struct aiVertexWeight { //! Index of the vertex which is influenced by the bone. unsigned int mVertexId; //! The strength of the influence in the range (0...1). //! The influence from all bones at one vertex amounts to 1. ai_real mWeight; #ifdef __cplusplus //! @brief Default constructor aiVertexWeight() AI_NO_EXCEPT : mVertexId(0), mWeight(0.0f) { // empty } //! @brief Initialization from a given index and vertex weight factor //! \param pID ID //! \param pWeight Vertex weight factor aiVertexWeight(unsigned int pID, float pWeight) : mVertexId(pID), mWeight(pWeight) { // empty } bool operator==(const aiVertexWeight &rhs) const { return (mVertexId == rhs.mVertexId && mWeight == rhs.mWeight); } bool operator!=(const aiVertexWeight &rhs) const { return (*this == rhs); } #endif // __cplusplus }; // Forward declare aiNode (pointer use only) struct aiNode; // --------------------------------------------------------------------------- /** @brief A single bone of a mesh. * * A bone has a name by which it can be found in the frame hierarchy and by * which it can be addressed by animations. In addition it has a number of * influences on vertices, and a matrix relating the mesh position to the * position of the bone at the time of binding. */ struct aiBone { /** * The name of the bone. */ C_STRUCT aiString mName; /** * The number of vertices affected by this bone. * The maximum value for this member is #AI_MAX_BONE_WEIGHTS. */ unsigned int mNumWeights; #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS /** * The bone armature node - used for skeleton conversion * you must enable aiProcess_PopulateArmatureData to populate this */ C_STRUCT aiNode *mArmature; /** * The bone node in the scene - used for skeleton conversion * you must enable aiProcess_PopulateArmatureData to populate this */ C_STRUCT aiNode *mNode; #endif /** * The influence weights of this bone, by vertex index. */ C_STRUCT aiVertexWeight *mWeights; /** * Matrix that transforms from mesh space to bone space in bind pose. * * This matrix describes the position of the mesh * in the local space of this bone when the skeleton was bound. * Thus it can be used directly to determine a desired vertex position, * given the world-space transform of the bone when animated, * and the position of the vertex in mesh space. * * It is sometimes called an inverse-bind matrix, * or inverse bind pose matrix. */ C_STRUCT aiMatrix4x4 mOffsetMatrix; #ifdef __cplusplus /// @brief Default constructor aiBone() AI_NO_EXCEPT : mName(), mNumWeights(0), #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS mArmature(nullptr), mNode(nullptr), #endif mWeights(nullptr), mOffsetMatrix() { // empty } /// @brief Copy constructor aiBone(const aiBone &other) : mName(other.mName), mNumWeights(other.mNumWeights), #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS mArmature(nullptr), mNode(nullptr), #endif mWeights(nullptr), mOffsetMatrix(other.mOffsetMatrix) { copyVertexWeights(other); } void copyVertexWeights( const aiBone &other ) { if (other.mWeights == nullptr || other.mNumWeights == 0) { mWeights = nullptr; mNumWeights = 0; return; } mNumWeights = other.mNumWeights; if (mWeights) { delete[] mWeights; } mWeights = new aiVertexWeight[mNumWeights]; ::memcpy(mWeights, other.mWeights, mNumWeights * sizeof(aiVertexWeight)); } //! @brief Assignment operator aiBone &operator = (const aiBone &other) { if (this == &other) { return *this; } mName = other.mName; mNumWeights = other.mNumWeights; mOffsetMatrix = other.mOffsetMatrix; copyVertexWeights(other); return *this; } /// @brief Compare operator. bool operator==(const aiBone &rhs) const { if (mName != rhs.mName || mNumWeights != rhs.mNumWeights ) { return false; } for (size_t i = 0; i < mNumWeights; ++i) { if (mWeights[i] != rhs.mWeights[i]) { return false; } } return true; } //! @brief Destructor - deletes the array of vertex weights ~aiBone() { delete[] mWeights; } #endif // __cplusplus }; // --------------------------------------------------------------------------- /** @brief Enumerates the types of geometric primitives supported by Assimp. * * @see aiFace Face data structure * @see aiProcess_SortByPType Per-primitive sorting of meshes * @see aiProcess_Triangulate Automatic triangulation * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types. */ enum aiPrimitiveType { /** * @brief A point primitive. * * This is just a single vertex in the virtual world, * #aiFace contains just one index for such a primitive. */ aiPrimitiveType_POINT = 0x1, /** * @brief A line primitive. * * This is a line defined through a start and an end position. * #aiFace contains exactly two indices for such a primitive. */ aiPrimitiveType_LINE = 0x2, /** * @brief A triangular primitive. * * A triangle consists of three indices. */ aiPrimitiveType_TRIANGLE = 0x4, /** * @brief A higher-level polygon with more than 3 edges. * * A triangle is a polygon, but polygon in this context means * "all polygons that are not triangles". The "Triangulate"-Step * is provided for your convenience, it splits all polygons in * triangles (which are much easier to handle). */ aiPrimitiveType_POLYGON = 0x8, /** * @brief A flag to determine whether this triangles only mesh is NGON encoded. * * NGON encoding is a special encoding that tells whether 2 or more consecutive triangles * should be considered as a triangle fan. This is identified by looking at the first vertex index. * 2 consecutive triangles with the same 1st vertex index are part of the same * NGON. * * At the moment, only quads (concave or convex) are supported, meaning that polygons are 'seen' as * triangles, as usual after a triangulation pass. * * To get an NGON encoded mesh, please use the aiProcess_Triangulate post process. * * @see aiProcess_Triangulate * @link https://github.com/KhronosGroup/glTF/pull/1620 */ aiPrimitiveType_NGONEncodingFlag = 0x10, /** * This value is not used. It is just here to force the * compiler to map this enum to a 32 Bit integer. */ #ifndef SWIG _aiPrimitiveType_Force32Bit = INT_MAX #endif }; //! enum aiPrimitiveType // Get the #aiPrimitiveType flag for a specific number of face indices #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \ ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1))) // --------------------------------------------------------------------------- /** @brief An AnimMesh is an attachment to an #aiMesh stores per-vertex * animations for a particular frame. * * You may think of an #aiAnimMesh as a `patch` for the host mesh, which * replaces only certain vertex data streams at a particular time. * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes). * The actual relationship between the time line and anim meshes is * established by #aiMeshAnim, which references singular mesh attachments * by their ID and binds them to a time offset. */ struct aiAnimMesh { /**Anim Mesh name */ C_STRUCT aiString mName; /** Replacement for aiMesh::mVertices. If this array is non-nullptr, * it *must* contain mNumVertices entries. The corresponding * array in the host mesh must be non-nullptr as well - animation * meshes may neither add or nor remove vertex components (if * a replacement array is nullptr and the corresponding source * array is not, the source data is taken instead)*/ C_STRUCT aiVector3D *mVertices; /** Replacement for aiMesh::mNormals. */ C_STRUCT aiVector3D *mNormals; /** Replacement for aiMesh::mTangents. */ C_STRUCT aiVector3D *mTangents; /** Replacement for aiMesh::mBitangents. */ C_STRUCT aiVector3D *mBitangents; /** Replacement for aiMesh::mColors */ C_STRUCT aiColor4D *mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; /** Replacement for aiMesh::mTextureCoords */ C_STRUCT aiVector3D *mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; /** The number of vertices in the aiAnimMesh, and thus the length of all * the member arrays. * * This has always the same value as the mNumVertices property in the * corresponding aiMesh. It is duplicated here merely to make the length * of the member arrays accessible even if the aiMesh is not known, e.g. * from language bindings. */ unsigned int mNumVertices; /** * Weight of the AnimMesh. */ float mWeight; #ifdef __cplusplus /// @brief The class constructor. aiAnimMesh() AI_NO_EXCEPT : mVertices(nullptr), mNormals(nullptr), mTangents(nullptr), mBitangents(nullptr), mColors {nullptr}, mTextureCoords{nullptr}, mNumVertices(0), mWeight(0.0f) { // empty } /// @brief The class destructor. ~aiAnimMesh() { delete[] mVertices; delete[] mNormals; delete[] mTangents; delete[] mBitangents; for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) { delete[] mTextureCoords[a]; } for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) { delete[] mColors[a]; } } /** * @brief Check whether the anim-mesh overrides the vertex positions * of its host mesh. * @return true if positions are stored, false if not. */ bool HasPositions() const { return mVertices != nullptr; } /** * @brief Check whether the anim-mesh overrides the vertex normals * of its host mesh * @return true if normals are stored, false if not. */ bool HasNormals() const { return mNormals != nullptr; } /** * @brief Check whether the anim-mesh overrides the vertex tangents * and bitangents of its host mesh. As for aiMesh, * tangents and bitangents always go together. * @return true if tangents and bi-tangents are stored, false if not. */ bool HasTangentsAndBitangents() const { return mTangents != nullptr; } /** * @brief Check whether the anim mesh overrides a particular * set of vertex colors on his host mesh. * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS * @return true if vertex colors are stored, false if not. */ bool HasVertexColors(unsigned int pIndex) const { return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != nullptr; } /** * @brief Check whether the anim mesh overrides a particular * set of texture coordinates on his host mesh. * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS * @return true if texture coordinates are stored, false if not. */ bool HasTextureCoords(unsigned int pIndex) const { return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != nullptr; } #endif }; // --------------------------------------------------------------------------- /** @brief Enumerates the methods of mesh morphing supported by Assimp. */ enum aiMorphingMethod { /** Morphing method to be determined */ aiMorphingMethod_UNKNOWN = 0x0, /** Interpolation between morph targets */ aiMorphingMethod_VERTEX_BLEND = 0x1, /** Normalized morphing between morph targets */ aiMorphingMethod_MORPH_NORMALIZED = 0x2, /** Relative morphing between morph targets */ aiMorphingMethod_MORPH_RELATIVE = 0x3, /** This value is not used. It is just here to force the * compiler to map this enum to a 32 Bit integer. */ #ifndef SWIG _aiMorphingMethod_Force32Bit = INT_MAX #endif }; //! enum aiMorphingMethod // --------------------------------------------------------------------------- /** @brief A mesh represents a geometry or model with a single material. * * It usually consists of a number of vertices and a series of primitives/faces * referencing the vertices. In addition there might be a series of bones, each * of them addressing a number of vertices with a certain weight. Vertex data * is presented in channels with each channel containing a single per-vertex * information such as a set of texture coordinates or a normal vector. * If a data pointer is non-null, the corresponding data stream is present. * From C++-programs you can also use the comfort functions Has*() to * test for the presence of various data streams. * * A Mesh uses only a single material which is referenced by a material ID. * @note The mPositions member is usually not optional. However, vertex positions * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in * @code * aiScene::mFlags * @endcode */ struct aiMesh { /** * Bitwise combination of the members of the #aiPrimitiveType enum. * This specifies which types of primitives are present in the mesh. * The "SortByPrimitiveType"-Step can be used to make sure the * output meshes consist of one primitive type each. */ unsigned int mPrimitiveTypes; /** * The number of vertices in this mesh. * This is also the size of all of the per-vertex data arrays. * The maximum value for this member is #AI_MAX_VERTICES. */ unsigned int mNumVertices; /** * The number of primitives (triangles, polygons, lines) in this mesh. * This is also the size of the mFaces array. * The maximum value for this member is #AI_MAX_FACES. */ unsigned int mNumFaces; /** * @brief Vertex positions. * * This array is always present in a mesh. The array is * mNumVertices in size. */ C_STRUCT aiVector3D *mVertices; /** * @brief Vertex normals. * * The array contains normalized vectors, nullptr if not present. * The array is mNumVertices in size. Normals are undefined for * point and line primitives. A mesh consisting of points and * lines only may not have normal vectors. Meshes with mixed * primitive types (i.e. lines and triangles) may have normals, * but the normals for vertices that are only referenced by * point or line primitives are undefined and set to QNaN (WARN: * qNaN compares to inequal to *everything*, even to qNaN itself. * Using code like this to check whether a field is qnan is: * @code * #define IS_QNAN(f) (f != f) * @endcode * still dangerous because even 1.f == 1.f could evaluate to false! ( * remember the subtleties of IEEE754 artithmetics). Use stuff like * @c fpclassify instead. * @note Normal vectors computed by Assimp are always unit-length. * However, this needn't apply for normals that have been taken * directly from the model file. */ C_STRUCT aiVector3D *mNormals; /** * @brief Vertex tangents. * * The tangent of a vertex points in the direction of the positive * X texture axis. The array contains normalized vectors, nullptr if * not present. The array is mNumVertices in size. A mesh consisting * of points and lines only may not have normal vectors. Meshes with * mixed primitive types (i.e. lines and triangles) may have * normals, but the normals for vertices that are only referenced by * point or line primitives are undefined and set to qNaN. See * the #mNormals member for a detailed discussion of qNaNs. * @note If the mesh contains tangents, it automatically also * contains bitangents. */ C_STRUCT aiVector3D *mTangents; /** * @brief Vertex bitangents. * * The bitangent of a vertex points in the direction of the positive * Y texture axis. The array contains normalized vectors, nullptr if not * present. The array is mNumVertices in size. * @note If the mesh contains tangents, it automatically also contains * bitangents. */ C_STRUCT aiVector3D *mBitangents; /** * @brief Vertex color sets. * * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex * colors per vertex. nullptr if not present. Each array is * mNumVertices in size if present. */ C_STRUCT aiColor4D *mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; /** * @brief Vertex texture coordinates, also known as UV channels. * * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per * vertex. nullptr if not present. The array is mNumVertices in size. */ C_STRUCT aiVector3D *mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; /** * @brief Specifies the number of components for a given UV channel. * * Up to three channels are supported (UVW, for accessing volume * or cube maps). If the value is 2 for a given channel n, the * component p.z of mTextureCoords[n][p] is set to 0.0f. * If the value is 1 for a given channel, p.y is set to 0.0f, too. * @note 4D coordinates are not supported */ unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS]; /** * @brief The faces the mesh is constructed from. * * Each face refers to a number of vertices by their indices. * This array is always present in a mesh, its size is given * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT * is NOT set each face references an unique set of vertices. */ C_STRUCT aiFace *mFaces; /** * The number of bones this mesh contains. Can be 0, in which case the mBones array is nullptr. */ unsigned int mNumBones; /** * @brief The bones of this mesh. * * A bone consists of a name by which it can be found in the * frame hierarchy and a set of vertex weights. */ C_STRUCT aiBone **mBones; /** * @brief The material used by this mesh. * * A mesh uses only a single material. If an imported model uses * multiple materials, the import splits up the mesh. Use this value * as index into the scene's material list. */ unsigned int mMaterialIndex; /** * Name of the mesh. Meshes can be named, but this is not a * requirement and leaving this field empty is totally fine. * There are mainly three uses for mesh names: * - some formats name nodes and meshes independently. * - importers tend to split meshes up to meet the * one-material-per-mesh requirement. Assigning * the same (dummy) name to each of the result meshes * aids the caller at recovering the original mesh * partitioning. * - Vertex animations refer to meshes by their names. */ C_STRUCT aiString mName; /** * The number of attachment meshes. * Currently known to work with loaders: * - Collada * - gltf */ unsigned int mNumAnimMeshes; /** * Attachment meshes for this mesh, for vertex-based animation. * Attachment meshes carry replacement data for some of the * mesh'es vertex components (usually positions, normals). * Currently known to work with loaders: * - Collada * - gltf */ C_STRUCT aiAnimMesh **mAnimMeshes; /** * Method of morphing when anim-meshes are specified. * @see aiMorphingMethod to learn more about the provided morphing targets. */ enum aiMorphingMethod mMethod; /** * The bounding box. */ C_STRUCT aiAABB mAABB; /** * Vertex UV stream names. Pointer to array of size AI_MAX_NUMBER_OF_TEXTURECOORDS */ C_STRUCT aiString **mTextureCoordsNames; #ifdef __cplusplus //! The default class constructor. aiMesh() AI_NO_EXCEPT : mPrimitiveTypes(0), mNumVertices(0), mNumFaces(0), mVertices(nullptr), mNormals(nullptr), mTangents(nullptr), mBitangents(nullptr), mColors{nullptr}, mTextureCoords{nullptr}, mNumUVComponents{0}, mFaces(nullptr), mNumBones(0), mBones(nullptr), mMaterialIndex(0), mNumAnimMeshes(0), mAnimMeshes(nullptr), mMethod(aiMorphingMethod_UNKNOWN), mAABB(), mTextureCoordsNames(nullptr) { // empty } //! @brief The class destructor. ~aiMesh() { delete[] mVertices; delete[] mNormals; delete[] mTangents; delete[] mBitangents; for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) { delete[] mTextureCoords[a]; } if (mTextureCoordsNames) { for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) { delete mTextureCoordsNames[a]; } delete[] mTextureCoordsNames; } for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) { delete[] mColors[a]; } // DO NOT REMOVE THIS ADDITIONAL CHECK if (mNumBones && mBones) { std::unordered_set<const aiBone *> bones; for (unsigned int a = 0; a < mNumBones; a++) { if (mBones[a]) { bones.insert(mBones[a]); } } for (const aiBone *bone: bones) { delete bone; } delete[] mBones; } if (mNumAnimMeshes && mAnimMeshes) { for (unsigned int a = 0; a < mNumAnimMeshes; a++) { delete mAnimMeshes[a]; } delete[] mAnimMeshes; } delete[] mFaces; } //! @brief Check whether the mesh contains positions. Provided no special //! scene flags are set, this will always be true //! @return true, if positions are stored, false if not. bool HasPositions() const { return mVertices != nullptr && mNumVertices > 0; } //! @brief Check whether the mesh contains faces. If no special scene flags //! are set this should always return true //! @return true, if faces are stored, false if not. bool HasFaces() const { return mFaces != nullptr && mNumFaces > 0; } //! @brief Check whether the mesh contains normal vectors //! @return true, if normals are stored, false if not. bool HasNormals() const { return mNormals != nullptr && mNumVertices > 0; } //! @brief Check whether the mesh contains tangent and bitangent vectors. //! //! It is not possible that it contains tangents and no bitangents //! (or the other way round). The existence of one of them //! implies that the second is there, too. //! @return true, if tangents and bi-tangents are stored, false if not. bool HasTangentsAndBitangents() const { return mTangents != nullptr && mBitangents != nullptr && mNumVertices > 0; } //! @brief Check whether the mesh contains a vertex color set //! @param index Index of the vertex color set //! @return true, if vertex colors are stored, false if not. bool HasVertexColors(unsigned int index) const { if (index >= AI_MAX_NUMBER_OF_COLOR_SETS) { return false; } return mColors[index] != nullptr && mNumVertices > 0; } //! @brief Check whether the mesh contains a texture coordinate set //! @param index Index of the texture coordinates set //! @return true, if texture coordinates are stored, false if not. bool HasTextureCoords(unsigned int index) const { if (index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { return false; } return (mTextureCoords[index] != nullptr && mNumVertices > 0); } //! @brief Get the number of UV channels the mesh contains. //! @return the number of stored uv-channels. unsigned int GetNumUVChannels() const { unsigned int n(0); while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n]) { ++n; } return n; } //! @brief Get the number of vertex color channels the mesh contains. //! @return The number of stored color channels. unsigned int GetNumColorChannels() const { unsigned int n(0); while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) { ++n; } return n; } //! @brief Check whether the mesh contains bones. //! @return true, if bones are stored. bool HasBones() const { return mBones != nullptr && mNumBones > 0; } //! @brief Check whether the mesh contains a texture coordinate set name //! @param pIndex Index of the texture coordinates set //! @return true, if texture coordinates for the index exists. bool HasTextureCoordsName(unsigned int pIndex) const { if (mTextureCoordsNames == nullptr || pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { return false; } return mTextureCoordsNames[pIndex] != nullptr; } //! @brief Set a texture coordinate set name //! @param pIndex Index of the texture coordinates set //! @param texCoordsName name of the texture coordinate set void SetTextureCoordsName(unsigned int pIndex, const aiString &texCoordsName) { if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { return; } if (mTextureCoordsNames == nullptr) { // Construct and null-init array mTextureCoordsNames = new aiString *[AI_MAX_NUMBER_OF_TEXTURECOORDS]; for (size_t i=0; i<AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { mTextureCoordsNames[i] = nullptr; } } if (texCoordsName.length == 0) { delete mTextureCoordsNames[pIndex]; mTextureCoordsNames[pIndex] = nullptr; return; } if (mTextureCoordsNames[pIndex] == nullptr) { mTextureCoordsNames[pIndex] = new aiString(texCoordsName); return; } *mTextureCoordsNames[pIndex] = texCoordsName; } //! @brief Get a texture coordinate set name //! @param pIndex Index of the texture coordinates set //! @return The texture coordinate name. const aiString *GetTextureCoordsName(unsigned int index) const { if (mTextureCoordsNames == nullptr || index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { return nullptr; } return mTextureCoordsNames[index]; } #endif // __cplusplus }; /** * @brief A skeleton bone represents a single bone is a skeleton structure. * * Skeleton-Animations can be represented via a skeleton struct, which describes * a hierarchical tree assembled from skeleton bones. A bone is linked to a mesh. * The bone knows its parent bone. If there is no parent bone the parent id is * marked with -1. * The skeleton-bone stores a pointer to its used armature. If there is no * armature this value if set to nullptr. * A skeleton bone stores its offset-matrix, which is the absolute transformation * for the bone. The bone stores the locale transformation to its parent as well. * You can compute the offset matrix by multiplying the hierarchy like: * Tree: s1 -> s2 -> s3 * Offset-Matrix s3 = locale-s3 * locale-s2 * locale-s1 */ struct aiSkeletonBone { /// The parent bone index, is -1 one if this bone represents the root bone. int mParent; #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS /// @brief The bone armature node - used for skeleton conversion /// you must enable aiProcess_PopulateArmatureData to populate this C_STRUCT aiNode *mArmature; /// @brief The bone node in the scene - used for skeleton conversion /// you must enable aiProcess_PopulateArmatureData to populate this C_STRUCT aiNode *mNode; #endif /// @brief The number of weights unsigned int mNumnWeights; /// The mesh index, which will get influenced by the weight. C_STRUCT aiMesh *mMeshId; /// The influence weights of this bone, by vertex index. C_STRUCT aiVertexWeight *mWeights; /** Matrix that transforms from bone space to mesh space in bind pose. * * This matrix describes the position of the mesh * in the local space of this bone when the skeleton was bound. * Thus it can be used directly to determine a desired vertex position, * given the world-space transform of the bone when animated, * and the position of the vertex in mesh space. * * It is sometimes called an inverse-bind matrix, * or inverse bind pose matrix. */ C_STRUCT aiMatrix4x4 mOffsetMatrix; /// Matrix that transforms the locale bone in bind pose. C_STRUCT aiMatrix4x4 mLocalMatrix; #ifdef __cplusplus /// @brief The class constructor. aiSkeletonBone() : mParent(-1), #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS mArmature(nullptr), mNode(nullptr), #endif mNumnWeights(0), mMeshId(nullptr), mWeights(nullptr), mOffsetMatrix(), mLocalMatrix() { // empty } /// @brief The class constructor with its parent /// @param parent The parent node index. aiSkeletonBone(unsigned int parent) : mParent(parent), #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS mArmature(nullptr), mNode(nullptr), #endif mNumnWeights(0), mMeshId(nullptr), mWeights(nullptr), mOffsetMatrix(), mLocalMatrix() { // empty } /// @brief The class destructor. ~aiSkeletonBone() { delete[] mWeights; mWeights = nullptr; } #endif // __cplusplus }; /** * @brief A skeleton represents the bone hierarchy of an animation. * * Skeleton animations can be described as a tree of bones: * root * | * node1 * / \ * node3 node4 * If you want to calculate the transformation of node three you need to compute the * transformation hierarchy for the transformation chain of node3: * root->node1->node3 * Each node is represented as a skeleton instance. */ struct aiSkeleton { /** * @brief The name of the skeleton instance. */ C_STRUCT aiString mName; /** * @brief The number of bones in the skeleton. */ unsigned int mNumBones; /** * @brief The bone instance in the skeleton. */ C_STRUCT aiSkeletonBone **mBones; #ifdef __cplusplus /** * @brief The class constructor. */ aiSkeleton() AI_NO_EXCEPT : mName(), mNumBones(0), mBones(nullptr) { // empty } /** * @brief The class destructor. */ ~aiSkeleton() { delete[] mBones; } #endif // __cplusplus }; #ifdef __cplusplus } #endif //! extern "C" #endif // AI_MESH_H_INC
38,839
C
32.055319
103
0.623754
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/MathFunctions.h
/* --------------------------------------------------------------------------- Open Asset Import Library (assimp) --------------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ #pragma once #ifdef __GNUC__ # pragma GCC system_header #endif /** @file MathFunctions.h * @brief Implementation of math utility functions. * */ #include <limits> namespace Assimp { namespace Math { /// @brief Will return the greatest common divisor. /// @param a [in] Value a. /// @param b [in] Value b. /// @return The greatest common divisor. template <typename IntegerType> inline IntegerType gcd( IntegerType a, IntegerType b ) { const IntegerType zero = (IntegerType)0; while ( true ) { if ( a == zero ) { return b; } b %= a; if ( b == zero ) { return a; } a %= b; } } /// @brief Will return the greatest common divisor. /// @param a [in] Value a. /// @param b [in] Value b. /// @return The greatest common divisor. template < typename IntegerType > inline IntegerType lcm( IntegerType a, IntegerType b ) { const IntegerType t = gcd (a,b); if (!t) { return t; } return a / t * b; } /// @brief Will return the smallest epsilon-value for the requested type. /// @return The numercical limit epsilon depending on its type. template<class T> inline T getEpsilon() { return std::numeric_limits<T>::epsilon(); } /// @brief Will return the constant PI for the requested type. /// @return Pi template<class T> inline T aiPi() { return static_cast<T>(3.14159265358979323846); } } // namespace Math } // namespace Assimp
3,206
C
29.254717
75
0.677168
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/ColladaMetaData.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file ColladaMetaData.h * Declares common metadata constants used by Collada files */ #pragma once #ifndef AI_COLLADAMETADATA_H_INC #define AI_COLLADAMETADATA_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #define AI_METADATA_COLLADA_ID "Collada_id" #define AI_METADATA_COLLADA_SID "Collada_sid" #endif
2,038
C
34.771929
70
0.73896
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/NullLogger.hpp
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file NullLogger.hpp * @brief Dummy logger */ #pragma once #ifndef INCLUDED_AI_NULLLOGGER_H #define INCLUDED_AI_NULLLOGGER_H #ifdef __GNUC__ #pragma GCC system_header #endif #include "Logger.hpp" namespace Assimp { // --------------------------------------------------------------------------- /** @brief CPP-API: Empty logging implementation. * * Does nothing! Used by default if the application hasn't requested a * custom logger via #DefaultLogger::set() or #DefaultLogger::create(); */ class ASSIMP_API NullLogger : public Logger { public: /** @brief Logs a debug message */ void OnDebug(const char* message) { (void)message; //this avoids compiler warnings } /** @brief Logs a verbose debug message */ void OnVerboseDebug(const char *message) { (void)message; //this avoids compiler warnings } /** @brief Logs an info message */ void OnInfo(const char* message) { (void)message; //this avoids compiler warnings } /** @brief Logs a warning message */ void OnWarn(const char* message) { (void)message; //this avoids compiler warnings } /** @brief Logs an error message */ void OnError(const char* message) { (void)message; //this avoids compiler warnings } /** @brief Detach a still attached stream from logger */ bool attachStream(LogStream *pStream, unsigned int severity) { (void)pStream; (void)severity; //this avoids compiler warnings return false; } /** @brief Detach a still attached stream from logger */ bool detachStream(LogStream *pStream, unsigned int severity) { (void)pStream; (void)severity; //this avoids compiler warnings return false; } private: }; } #endif // !! AI_NULLLOGGER_H_INCLUDED
3,508
C++
30.9
78
0.68244
MomentFactory/Omniverse-MVR-GDTF-converter/src/usd-plugins/fileFormat/mvrFileFormat/assimp/include/assimp/ParsingUtils.h
/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- Copyright (c) 2006-2022, assimp team All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the assimp team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the assimp team. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ /** @file ParsingUtils.h * @brief Defines helper functions for text parsing */ #pragma once #ifndef AI_PARSING_UTILS_H_INC #define AI_PARSING_UTILS_H_INC #ifdef __GNUC__ #pragma GCC system_header #endif #include <assimp/StringComparison.h> #include <assimp/StringUtils.h> #include <assimp/defs.h> #include <vector> #include <algorithm> namespace Assimp { // NOTE: the functions below are mostly intended as replacement for // std::upper, std::lower, std::isupper, std::islower, std::isspace. // we don't bother of locales. We don't want them. We want reliable // (i.e. identical) results across all locales. // The functions below accept any character type, but know only // about ASCII. However, UTF-32 is the only safe ASCII superset to // use since it doesn't have multi-byte sequences. static const unsigned int BufferSize = 4096; // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool IsUpper(char_t in) { return (in >= (char_t)'A' && in <= (char_t)'Z'); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool IsLower(char_t in) { return (in >= (char_t)'a' && in <= (char_t)'z'); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool IsSpace(char_t in) { return (in == (char_t)' ' || in == (char_t)'\t'); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool IsLineEnd(char_t in) { return (in == (char_t)'\r' || in == (char_t)'\n' || in == (char_t)'\0' || in == (char_t)'\f'); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool IsSpaceOrNewLine(char_t in) { return IsSpace<char_t>(in) || IsLineEnd<char_t>(in); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool SkipSpaces(const char_t *in, const char_t **out) { while (*in == (char_t)' ' || *in == (char_t)'\t') { ++in; } *out = in; return !IsLineEnd<char_t>(*in); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool SkipSpaces(const char_t **inout) { return SkipSpaces<char_t>(*inout, inout); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool SkipLine(const char_t *in, const char_t **out) { while (*in != (char_t)'\r' && *in != (char_t)'\n' && *in != (char_t)'\0') { ++in; } // files are opened in binary mode. Ergo there are both NL and CR while (*in == (char_t)'\r' || *in == (char_t)'\n') { ++in; } *out = in; return *in != (char_t)'\0'; } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool SkipLine(const char_t **inout) { return SkipLine<char_t>(*inout, inout); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t *in, const char_t **out) { while (*in == (char_t)' ' || *in == (char_t)'\t' || *in == (char_t)'\r' || *in == (char_t)'\n') { ++in; } *out = in; return *in != '\0'; } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool SkipSpacesAndLineEnd(const char_t **inout) { return SkipSpacesAndLineEnd<char_t>(*inout, inout); } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool GetNextLine(const char_t *&buffer, char_t out[BufferSize]) { if ((char_t)'\0' == *buffer) { return false; } char *_out = out; char *const end = _out + BufferSize; while (!IsLineEnd(*buffer) && _out < end) { *_out++ = *buffer++; } *_out = (char_t)'\0'; while (IsLineEnd(*buffer) && '\0' != *buffer) { ++buffer; } return true; } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool IsNumeric(char_t in) { return (in >= '0' && in <= '9') || '-' == in || '+' == in; } // --------------------------------------------------------------------------------- template <class char_t> AI_FORCE_INLINE bool TokenMatch(char_t *&in, const char *token, unsigned int len) { if (!::strncmp(token, in, len) && IsSpaceOrNewLine(in[len])) { if (in[len] != '\0') { in += len + 1; } else { // If EOF after the token make sure we don't go past end of buffer in += len; } return true; } return false; } // --------------------------------------------------------------------------------- /** @brief Case-ignoring version of TokenMatch * @param in Input * @param token Token to check for * @param len Number of characters to check */ AI_FORCE_INLINE bool TokenMatchI(const char *&in, const char *token, unsigned int len) { if (!ASSIMP_strincmp(token, in, len) && IsSpaceOrNewLine(in[len])) { in += len + 1; return true; } return false; } // --------------------------------------------------------------------------------- AI_FORCE_INLINE void SkipToken(const char *&in) { SkipSpaces(&in); while (!IsSpaceOrNewLine(*in)) { ++in; } } // --------------------------------------------------------------------------------- AI_FORCE_INLINE std::string GetNextToken(const char *&in) { SkipSpacesAndLineEnd(&in); const char *cur = in; while (!IsSpaceOrNewLine(*in)) { ++in; } return std::string(cur, (size_t)(in - cur)); } // --------------------------------------------------------------------------------- /** @brief Will perform a simple tokenize. * @param str String to tokenize. * @param tokens Array with tokens, will be empty if no token was found. * @param delimiters Delimiter for tokenize. * @return Number of found token. */ template <class string_type> AI_FORCE_INLINE unsigned int tokenize(const string_type &str, std::vector<string_type> &tokens, const string_type &delimiters) { // Skip delimiters at beginning. typename string_type::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". typename string_type::size_type pos = str.find_first_of(delimiters, lastPos); while (string_type::npos != pos || string_type::npos != lastPos) { // Found a token, add it to the vector. string_type tmp = str.substr(lastPos, pos - lastPos); if (!tmp.empty() && ' ' != tmp[0]) tokens.push_back(tmp); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } return static_cast<unsigned int>(tokens.size()); } inline std::string ai_stdStrToLower(const std::string &str) { std::string out(str); for (size_t i = 0; i < str.size(); ++i) { out[i] = (char) tolower((unsigned char)out[i]); } return out; } } // namespace Assimp #endif // ! AI_PARSING_UTILS_H_INC
9,236
C
32.959559
101
0.529017