mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Refactor: Merge [IC]SkinnedMesh
into SkinnedMesh
(#15511)
This commit is contained in:
parent
810f39767c
commit
3e10d9ccf5
18 changed files with 326 additions and 646 deletions
|
@ -48,7 +48,7 @@ const c8 *const BoneAnimationModeNames[] = {
|
|||
};
|
||||
|
||||
//! Interface for bones used for skeletal animation.
|
||||
/** Used with ISkinnedMesh and IAnimatedMeshSceneNode. */
|
||||
/** Used with SkinnedMesh and IAnimatedMeshSceneNode. */
|
||||
class IBoneSceneNode : public ISceneNode
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "SColor.h"
|
||||
#include "ESceneNodeTypes.h"
|
||||
#include "SceneParameters.h" // IWYU pragma: export
|
||||
#include "ISkinnedMesh.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
|
@ -93,6 +92,7 @@ class IBillboardSceneNode;
|
|||
class ICameraSceneNode;
|
||||
class IDummyTransformationSceneNode;
|
||||
class IMesh;
|
||||
class SkinnedMesh;
|
||||
class IMeshBuffer;
|
||||
class IMeshCache;
|
||||
class ISceneCollisionManager;
|
||||
|
@ -121,189 +121,6 @@ public:
|
|||
//! Get pointer to an animatable mesh. Loads the file if not loaded already.
|
||||
/**
|
||||
* If you want to remove a loaded mesh from the cache again, use removeMesh().
|
||||
* Currently there are the following mesh formats supported:
|
||||
* <TABLE border="1" cellpadding="2" cellspacing="0">
|
||||
* <TR>
|
||||
* <TD>Format</TD>
|
||||
* <TD>Description</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>3D Studio (.3ds)</TD>
|
||||
* <TD>Loader for 3D-Studio files which lots of 3D packages
|
||||
* are able to export. Only static meshes are currently
|
||||
* supported by this importer.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>3D World Studio (.smf)</TD>
|
||||
* <TD>Loader for Leadwerks SMF mesh files, a simple mesh format
|
||||
* containing static geometry for games. The proprietary .STF texture format
|
||||
* is not supported yet. This loader was originally written by Joseph Ellis. </TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Bliz Basic B3D (.b3d)</TD>
|
||||
* <TD>Loader for blitz basic files, developed by Mark
|
||||
* Sibly. This is the ideal animated mesh format for game
|
||||
* characters as it is both rigidly defined and widely
|
||||
* supported by modeling and animation software.
|
||||
* As this format supports skeletal animations, an
|
||||
* ISkinnedMesh will be returned by this importer.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Cartography shop 4 (.csm)</TD>
|
||||
* <TD>Cartography Shop is a modeling program for creating
|
||||
* architecture and calculating lighting. Irrlicht can
|
||||
* directly import .csm files thanks to the IrrCSM library
|
||||
* created by Saurav Mohapatra which is now integrated
|
||||
* directly in Irrlicht.
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Delgine DeleD (.dmf)</TD>
|
||||
* <TD>DeleD (delgine.com) is a 3D editor and level-editor
|
||||
* combined into one and is specifically designed for 3D
|
||||
* game-development. With this loader, it is possible to
|
||||
* directly load all geometry is as well as textures and
|
||||
* lightmaps from .dmf files. To set texture and
|
||||
* material paths, see scene::DMF_USE_MATERIALS_DIRS.
|
||||
* It is also possible to flip the alpha texture by setting
|
||||
* scene::DMF_FLIP_ALPHA_TEXTURES to true and to set the
|
||||
* material transparent reference value by setting
|
||||
* scene::DMF_ALPHA_CHANNEL_REF to a float between 0 and
|
||||
* 1. The loader is based on Salvatore Russo's .dmf
|
||||
* loader, I just changed some parts of it. Thanks to
|
||||
* Salvatore for his work and for allowing me to use his
|
||||
* code in Irrlicht and put it under Irrlicht's license.
|
||||
* For newer and more enhanced versions of the loader,
|
||||
* take a look at delgine.com.
|
||||
* </TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>DirectX (.x)</TD>
|
||||
* <TD>Platform independent importer (so not D3D-only) for
|
||||
* .x files. Most 3D packages can export these natively
|
||||
* and there are several tools for them available, e.g.
|
||||
* the Maya exporter included in the DX SDK.
|
||||
* .x files can include skeletal animations and Irrlicht
|
||||
* is able to play and display them, users can manipulate
|
||||
* the joints via the ISkinnedMesh interface. Currently,
|
||||
* Irrlicht only supports uncompressed .x files.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Half-Life model (.mdl)</TD>
|
||||
* <TD>This loader opens Half-life 1 models, it was contributed
|
||||
* by Fabio Concas and adapted by Thomas Alten.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>LightWave (.lwo)</TD>
|
||||
* <TD>Native to NewTek's LightWave 3D, the LWO format is well
|
||||
* known and supported by many exporters. This loader will
|
||||
* import LWO2 models including lightmaps, bumpmaps and
|
||||
* reflection textures.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Maya (.obj)</TD>
|
||||
* <TD>Most 3D software can create .obj files which contain
|
||||
* static geometry without material data. The material
|
||||
* files .mtl are also supported. This importer for
|
||||
* Irrlicht can load them directly. </TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Milkshape (.ms3d)</TD>
|
||||
* <TD>.MS3D files contain models and sometimes skeletal
|
||||
* animations from the Milkshape 3D modeling and animation
|
||||
* software. Like the other skeletal mesh loaders, joints
|
||||
* are exposed via the ISkinnedMesh animated mesh type.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>My3D (.my3d)</TD>
|
||||
* <TD>.my3D is a flexible 3D file format. The My3DTools
|
||||
* contains plug-ins to export .my3D files from several
|
||||
* 3D packages. With this built-in importer, Irrlicht
|
||||
* can read and display those files directly. This
|
||||
* loader was written by Zhuck Dimitry who also created
|
||||
* the whole My3DTools package.
|
||||
* </TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>OCT (.oct)</TD>
|
||||
* <TD>The oct file format contains 3D geometry and
|
||||
* lightmaps and can be loaded directly by Irrlicht. OCT
|
||||
* files<br> can be created by FSRad, Paul Nette's
|
||||
* radiosity processor or exported from Blender using
|
||||
* OCTTools which can be found in the exporters/OCTTools
|
||||
* directory of the SDK. Thanks to Murphy McCauley for
|
||||
* creating all this.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>OGRE Meshes (.mesh)</TD>
|
||||
* <TD>Ogre .mesh files contain 3D data for the OGRE 3D
|
||||
* engine. Irrlicht can read and display them directly
|
||||
* with this importer. To define materials for the mesh,
|
||||
* copy a .material file named like the corresponding
|
||||
* .mesh file where the .mesh file is. (For example
|
||||
* ogrehead.material for ogrehead.mesh). Thanks to
|
||||
* Christian Stehno who wrote and contributed this
|
||||
* loader.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Pulsar LMTools (.lmts)</TD>
|
||||
* <TD>LMTools is a set of tools (Windows & Linux) for
|
||||
* creating lightmaps. Irrlicht can directly read .lmts
|
||||
* files thanks to<br> the importer created by Jonas
|
||||
* Petersen.
|
||||
* Notes for<br> this version of the loader:<br>
|
||||
* - It does not recognize/support user data in the
|
||||
* *.lmts files.<br>
|
||||
* - The TGAs generated by LMTools don't work in
|
||||
* Irrlicht for some reason (the textures are upside
|
||||
* down). Opening and resaving them in a graphics app
|
||||
* will solve the problem.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Quake 3 levels (.bsp)</TD>
|
||||
* <TD>Quake 3 is a popular game by IDSoftware, and .pk3
|
||||
* files contain .bsp files and textures/lightmaps
|
||||
* describing huge prelighted levels. Irrlicht can read
|
||||
* .pk3 and .bsp files directly and thus render Quake 3
|
||||
* levels directly. Written by Nikolaus Gebhardt
|
||||
* enhanced by Dean P. Macri with the curved surfaces
|
||||
* feature. </TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Quake 2 models (.md2)</TD>
|
||||
* <TD>Quake 2 models are characters with morph target
|
||||
* animation. Irrlicht can read, display and animate
|
||||
* them directly with this importer. </TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Quake 3 models (.md3)</TD>
|
||||
* <TD>Quake 3 models are characters with morph target
|
||||
* animation, they contain mount points for weapons and body
|
||||
* parts and are typically made of several sections which are
|
||||
* manually joined together.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Stanford Triangle (.ply)</TD>
|
||||
* <TD>Invented by Stanford University and known as the native
|
||||
* format of the infamous "Stanford Bunny" model, this is a
|
||||
* popular static mesh format used by 3D scanning hardware
|
||||
* and software. This loader supports extremely large models
|
||||
* in both ASCII and binary format, but only has rudimentary
|
||||
* material support in the form of vertex colors and texture
|
||||
* coordinates.</TD>
|
||||
* </TR>
|
||||
* <TR>
|
||||
* <TD>Stereolithography (.stl)</TD>
|
||||
* <TD>The STL format is used for rapid prototyping and
|
||||
* computer-aided manufacturing, thus has no support for
|
||||
* materials.</TD>
|
||||
* </TR>
|
||||
* </TABLE>
|
||||
*
|
||||
* To load and display a mesh quickly, just do this:
|
||||
* \code
|
||||
* SceneManager->addAnimatedMeshSceneNode(
|
||||
* SceneManager->getMesh("yourmesh.3ds"));
|
||||
* \endcode
|
||||
* If you would like to implement and add your own file format loader to Irrlicht,
|
||||
* see addExternalMeshLoader().
|
||||
* \param file File handle of the mesh to load.
|
||||
|
@ -594,7 +411,7 @@ public:
|
|||
//! Get a skinned mesh, which is not available as header-only code
|
||||
/** Note: You need to drop() the pointer after use again, see IReferenceCounted::drop()
|
||||
for details. */
|
||||
virtual ISkinnedMesh *createSkinnedMesh() = 0;
|
||||
virtual SkinnedMesh *createSkinnedMesh() = 0;
|
||||
|
||||
//! Get current render pass.
|
||||
virtual E_SCENE_NODE_RENDER_PASS getCurrentRenderPass() const = 0;
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||
// This file is part of the "Irrlicht Engine".
|
||||
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "irrArray.h"
|
||||
#include "IAnimatedMesh.h"
|
||||
#include "SSkinMeshBuffer.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene
|
||||
{
|
||||
|
||||
enum E_INTERPOLATION_MODE
|
||||
{
|
||||
// constant does use the current key-values without interpolation
|
||||
EIM_CONSTANT = 0,
|
||||
|
||||
// linear interpolation
|
||||
EIM_LINEAR,
|
||||
|
||||
//! count of all available interpolation modes
|
||||
EIM_COUNT
|
||||
};
|
||||
|
||||
//! Interface for using some special functions of Skinned meshes
|
||||
class ISkinnedMesh : public IAnimatedMesh
|
||||
{
|
||||
public:
|
||||
//! Gets joint count.
|
||||
/** \return Amount of joints in the skeletal animated mesh. */
|
||||
virtual u32 getJointCount() const = 0;
|
||||
|
||||
//! Gets the name of a joint.
|
||||
/** \param number: Zero based index of joint. The last joint
|
||||
has the number getJointCount()-1;
|
||||
\return Name of joint and null if an error happened. */
|
||||
virtual const std::optional<std::string> &getJointName(u32 number) const = 0;
|
||||
|
||||
//! Gets a joint number from its name
|
||||
/** \param name: Name of the joint.
|
||||
\return Number of the joint or std::nullopt if not found. */
|
||||
virtual std::optional<u32> getJointNumber(const std::string &name) const = 0;
|
||||
|
||||
//! Use animation from another mesh
|
||||
/** The animation is linked (not copied) based on joint names
|
||||
so make sure they are unique.
|
||||
\return True if all joints in this mesh were
|
||||
matched up (empty names will not be matched, and it's case
|
||||
sensitive). Unmatched joints will not be animated. */
|
||||
virtual bool useAnimationFrom(const ISkinnedMesh *mesh) = 0;
|
||||
|
||||
//! Update Normals when Animating
|
||||
/** \param on If false don't animate, which is faster.
|
||||
Else update normals, which allows for proper lighting of
|
||||
animated meshes. */
|
||||
virtual void updateNormalsWhenAnimating(bool on) = 0;
|
||||
|
||||
//! Sets Interpolation Mode
|
||||
virtual void setInterpolationMode(E_INTERPOLATION_MODE mode) = 0;
|
||||
|
||||
//! Animates this mesh's joints based on frame input
|
||||
virtual void animateMesh(f32 frame, f32 blend) = 0;
|
||||
|
||||
//! Preforms a software skin on this mesh based of joint positions
|
||||
virtual void skinMesh() = 0;
|
||||
|
||||
//! converts the vertex type of all meshbuffers to tangents.
|
||||
/** E.g. used for bump mapping. */
|
||||
virtual void convertMeshToTangents() = 0;
|
||||
|
||||
//! Allows to enable hardware skinning.
|
||||
/* This feature is not implemented in Irrlicht yet */
|
||||
virtual bool setHardwareSkinning(bool on) = 0;
|
||||
|
||||
//! Refreshes vertex data cached in joints such as positions and normals
|
||||
virtual void refreshJointCache() = 0;
|
||||
|
||||
//! Moves the mesh into static position.
|
||||
virtual void resetAnimation() = 0;
|
||||
|
||||
//! A vertex weight
|
||||
struct SWeight
|
||||
{
|
||||
//! Index of the mesh buffer
|
||||
u16 buffer_id; // I doubt 32bits is needed
|
||||
|
||||
//! Index of the vertex
|
||||
u32 vertex_id; // Store global ID here
|
||||
|
||||
//! Weight Strength/Percentage (0-1)
|
||||
f32 strength;
|
||||
|
||||
private:
|
||||
//! Internal members used by CSkinnedMesh
|
||||
friend class CSkinnedMesh;
|
||||
char *Moved;
|
||||
core::vector3df StaticPos;
|
||||
core::vector3df StaticNormal;
|
||||
};
|
||||
|
||||
//! Animation keyframe which describes a new position
|
||||
struct SPositionKey
|
||||
{
|
||||
f32 frame;
|
||||
core::vector3df position;
|
||||
};
|
||||
|
||||
//! Animation keyframe which describes a new scale
|
||||
struct SScaleKey
|
||||
{
|
||||
f32 frame;
|
||||
core::vector3df scale;
|
||||
};
|
||||
|
||||
//! Animation keyframe which describes a new rotation
|
||||
struct SRotationKey
|
||||
{
|
||||
f32 frame;
|
||||
core::quaternion rotation;
|
||||
};
|
||||
|
||||
//! Joints
|
||||
struct SJoint
|
||||
{
|
||||
SJoint() :
|
||||
UseAnimationFrom(0), GlobalSkinningSpace(false),
|
||||
positionHint(-1), scaleHint(-1), rotationHint(-1)
|
||||
{
|
||||
}
|
||||
|
||||
//! The name of this joint
|
||||
std::optional<std::string> Name;
|
||||
|
||||
//! Local matrix of this joint
|
||||
core::matrix4 LocalMatrix;
|
||||
|
||||
//! List of child joints
|
||||
core::array<SJoint *> Children;
|
||||
|
||||
//! List of attached meshes
|
||||
core::array<u32> AttachedMeshes;
|
||||
|
||||
//! Animation keys causing translation change
|
||||
core::array<SPositionKey> PositionKeys;
|
||||
|
||||
//! Animation keys causing scale change
|
||||
core::array<SScaleKey> ScaleKeys;
|
||||
|
||||
//! Animation keys causing rotation change
|
||||
core::array<SRotationKey> RotationKeys;
|
||||
|
||||
//! Skin weights
|
||||
core::array<SWeight> Weights;
|
||||
|
||||
//! Unnecessary for loaders, will be overwritten on finalize
|
||||
core::matrix4 GlobalMatrix; // loaders may still choose to set this (temporarily) to calculate absolute vertex data.
|
||||
core::matrix4 GlobalAnimatedMatrix;
|
||||
core::matrix4 LocalAnimatedMatrix;
|
||||
|
||||
//! These should be set by loaders.
|
||||
core::vector3df Animatedposition;
|
||||
core::vector3df Animatedscale;
|
||||
core::quaternion Animatedrotation;
|
||||
|
||||
// The .x and .gltf formats pre-calculate this
|
||||
std::optional<core::matrix4> GlobalInversedMatrix;
|
||||
private:
|
||||
//! Internal members used by CSkinnedMesh
|
||||
friend class CSkinnedMesh;
|
||||
|
||||
SJoint *UseAnimationFrom;
|
||||
bool GlobalSkinningSpace;
|
||||
|
||||
s32 positionHint;
|
||||
s32 scaleHint;
|
||||
s32 rotationHint;
|
||||
};
|
||||
|
||||
// Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
|
||||
|
||||
// these functions will use the needed arrays, set values, etc to help the loaders
|
||||
|
||||
//! exposed for loaders: to add mesh buffers
|
||||
virtual core::array<SSkinMeshBuffer *> &getMeshBuffers() = 0;
|
||||
|
||||
//! exposed for loaders: joints list
|
||||
virtual core::array<SJoint *> &getAllJoints() = 0;
|
||||
|
||||
//! exposed for loaders: joints list
|
||||
virtual const core::array<SJoint *> &getAllJoints() const = 0;
|
||||
|
||||
//! loaders should call this after populating the mesh
|
||||
virtual void finalize() = 0;
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
virtual SSkinMeshBuffer *addMeshBuffer() = 0;
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
virtual void addMeshBuffer(SSkinMeshBuffer *meshbuf) = 0;
|
||||
|
||||
//! Adds a new joint to the mesh, access it as last one
|
||||
virtual SJoint *addJoint(SJoint *parent = 0) = 0;
|
||||
|
||||
//! Adds a new weight to the mesh, access it as last one
|
||||
virtual SWeight *addWeight(SJoint *joint) = 0;
|
||||
|
||||
//! Adds a new position key to the mesh, access it as last one
|
||||
virtual SPositionKey *addPositionKey(SJoint *joint) = 0;
|
||||
//! Adds a new scale key to the mesh, access it as last one
|
||||
virtual SScaleKey *addScaleKey(SJoint *joint) = 0;
|
||||
//! Adds a new rotation key to the mesh, access it as last one
|
||||
virtual SRotationKey *addRotationKey(SJoint *joint) = 0;
|
||||
|
||||
//! Check if the mesh is non-animated
|
||||
virtual bool isStatic() = 0;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
} // end namespace irr
|
339
irr/include/SkinnedMesh.h
Normal file
339
irr/include/SkinnedMesh.h
Normal file
|
@ -0,0 +1,339 @@
|
|||
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||
// This file is part of the "Irrlicht Engine".
|
||||
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IAnimatedMesh.h"
|
||||
#include "ISceneManager.h"
|
||||
#include "SMeshBuffer.h"
|
||||
#include "SSkinMeshBuffer.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene
|
||||
{
|
||||
|
||||
enum E_INTERPOLATION_MODE
|
||||
{
|
||||
// constant does use the current key-values without interpolation
|
||||
EIM_CONSTANT = 0,
|
||||
|
||||
// linear interpolation
|
||||
EIM_LINEAR,
|
||||
|
||||
//! count of all available interpolation modes
|
||||
EIM_COUNT
|
||||
};
|
||||
|
||||
class IAnimatedMeshSceneNode;
|
||||
class IBoneSceneNode;
|
||||
class ISceneManager;
|
||||
|
||||
class SkinnedMesh : public IAnimatedMesh
|
||||
{
|
||||
public:
|
||||
//! constructor
|
||||
SkinnedMesh();
|
||||
|
||||
//! destructor
|
||||
virtual ~SkinnedMesh();
|
||||
|
||||
//! If the duration is 0, it is a static (=non animated) mesh.
|
||||
f32 getMaxFrameNumber() const override;
|
||||
|
||||
//! Gets the default animation speed of the animated mesh.
|
||||
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
|
||||
f32 getAnimationSpeed() const override;
|
||||
|
||||
//! Gets the frame count of the animated mesh.
|
||||
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
|
||||
The actual speed is set in the scene node the mesh is instantiated in.*/
|
||||
void setAnimationSpeed(f32 fps) override;
|
||||
|
||||
//! returns the animated mesh for the given frame
|
||||
IMesh *getMesh(f32) override;
|
||||
|
||||
//! Animates this mesh's joints based on frame input
|
||||
//! blend: {0-old position, 1-New position}
|
||||
void animateMesh(f32 frame, f32 blend);
|
||||
|
||||
//! Performs a software skin on this mesh based of joint positions
|
||||
void skinMesh();
|
||||
|
||||
//! returns amount of mesh buffers.
|
||||
u32 getMeshBufferCount() const override;
|
||||
|
||||
//! returns pointer to a mesh buffer
|
||||
IMeshBuffer *getMeshBuffer(u32 nr) const override;
|
||||
|
||||
//! Returns pointer to a mesh buffer which fits a material
|
||||
/** \param material: material to search for
|
||||
\return Returns the pointer to the mesh buffer or
|
||||
NULL if there is no such mesh buffer. */
|
||||
IMeshBuffer *getMeshBuffer(const video::SMaterial &material) const override;
|
||||
|
||||
u32 getTextureSlot(u32 meshbufNr) const override;
|
||||
|
||||
void setTextureSlot(u32 meshbufNr, u32 textureSlot);
|
||||
|
||||
//! returns an axis aligned bounding box
|
||||
const core::aabbox3d<f32> &getBoundingBox() const override;
|
||||
|
||||
//! set user axis aligned bounding box
|
||||
void setBoundingBox(const core::aabbox3df &box) override;
|
||||
|
||||
//! set the hardware mapping hint, for driver
|
||||
void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override;
|
||||
|
||||
//! flags the meshbuffer as changed, reloads hardware buffers
|
||||
void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override;
|
||||
|
||||
//! Returns the type of the animated mesh.
|
||||
E_ANIMATED_MESH_TYPE getMeshType() const override;
|
||||
|
||||
//! Gets joint count.
|
||||
u32 getJointCount() const;
|
||||
|
||||
//! Gets the name of a joint.
|
||||
/** \param number: Zero based index of joint.
|
||||
\return Name of joint and null if an error happened. */
|
||||
const std::optional<std::string> &getJointName(u32 number) const;
|
||||
|
||||
//! Gets a joint number from its name
|
||||
/** \param name: Name of the joint.
|
||||
\return Number of the joint or std::nullopt if not found. */
|
||||
std::optional<u32> getJointNumber(const std::string &name) const;
|
||||
|
||||
//! Update Normals when Animating
|
||||
/** \param on If false don't animate, which is faster.
|
||||
Else update normals, which allows for proper lighting of
|
||||
animated meshes. */
|
||||
void updateNormalsWhenAnimating(bool on);
|
||||
|
||||
//! Sets Interpolation Mode
|
||||
void setInterpolationMode(E_INTERPOLATION_MODE mode);
|
||||
|
||||
//! converts the vertex type of all meshbuffers to tangents.
|
||||
/** E.g. used for bump mapping. */
|
||||
void convertMeshToTangents();
|
||||
|
||||
//! Does the mesh have no animation
|
||||
bool isStatic() const;
|
||||
|
||||
//! Allows to enable hardware skinning.
|
||||
/* This feature is not implemented in Irrlicht yet */
|
||||
bool setHardwareSkinning(bool on);
|
||||
|
||||
//! Refreshes vertex data cached in joints such as positions and normals
|
||||
void refreshJointCache();
|
||||
|
||||
//! Moves the mesh into static position.
|
||||
void resetAnimation();
|
||||
|
||||
virtual void updateBoundingBox();
|
||||
|
||||
//! Recovers the joints from the mesh
|
||||
void recoverJointsFromMesh(core::array<IBoneSceneNode *> &jointChildSceneNodes);
|
||||
|
||||
//! Transfers the joint data to the mesh
|
||||
void transferJointsToMesh(const core::array<IBoneSceneNode *> &jointChildSceneNodes);
|
||||
|
||||
//! Transfers the joint hints to the mesh
|
||||
void transferOnlyJointsHintsToMesh(const core::array<IBoneSceneNode *> &jointChildSceneNodes);
|
||||
|
||||
//! Creates an array of joints from this mesh as children of node
|
||||
void addJoints(core::array<IBoneSceneNode *> &jointChildSceneNodes,
|
||||
IAnimatedMeshSceneNode *node,
|
||||
ISceneManager *smgr);
|
||||
|
||||
//! A vertex weight
|
||||
struct SWeight
|
||||
{
|
||||
//! Index of the mesh buffer
|
||||
u16 buffer_id; // I doubt 32bits is needed
|
||||
|
||||
//! Index of the vertex
|
||||
u32 vertex_id; // Store global ID here
|
||||
|
||||
//! Weight Strength/Percentage (0-1)
|
||||
f32 strength;
|
||||
|
||||
private:
|
||||
//! Internal members used by SkinnedMesh
|
||||
friend class SkinnedMesh;
|
||||
char *Moved;
|
||||
core::vector3df StaticPos;
|
||||
core::vector3df StaticNormal;
|
||||
};
|
||||
|
||||
//! Animation keyframe which describes a new position
|
||||
struct SPositionKey
|
||||
{
|
||||
f32 frame;
|
||||
core::vector3df position;
|
||||
};
|
||||
|
||||
//! Animation keyframe which describes a new scale
|
||||
struct SScaleKey
|
||||
{
|
||||
f32 frame;
|
||||
core::vector3df scale;
|
||||
};
|
||||
|
||||
//! Animation keyframe which describes a new rotation
|
||||
struct SRotationKey
|
||||
{
|
||||
f32 frame;
|
||||
core::quaternion rotation;
|
||||
};
|
||||
|
||||
//! Joints
|
||||
struct SJoint
|
||||
{
|
||||
SJoint() :
|
||||
UseAnimationFrom(0), GlobalSkinningSpace(false),
|
||||
positionHint(-1), scaleHint(-1), rotationHint(-1)
|
||||
{
|
||||
}
|
||||
|
||||
//! The name of this joint
|
||||
std::optional<std::string> Name;
|
||||
|
||||
//! Local matrix of this joint
|
||||
core::matrix4 LocalMatrix;
|
||||
|
||||
//! List of child joints
|
||||
core::array<SJoint *> Children;
|
||||
|
||||
//! List of attached meshes
|
||||
core::array<u32> AttachedMeshes;
|
||||
|
||||
//! Animation keys causing translation change
|
||||
core::array<SPositionKey> PositionKeys;
|
||||
|
||||
//! Animation keys causing scale change
|
||||
core::array<SScaleKey> ScaleKeys;
|
||||
|
||||
//! Animation keys causing rotation change
|
||||
core::array<SRotationKey> RotationKeys;
|
||||
|
||||
//! Skin weights
|
||||
core::array<SWeight> Weights;
|
||||
|
||||
//! Unnecessary for loaders, will be overwritten on finalize
|
||||
core::matrix4 GlobalMatrix; // loaders may still choose to set this (temporarily) to calculate absolute vertex data.
|
||||
core::matrix4 GlobalAnimatedMatrix;
|
||||
core::matrix4 LocalAnimatedMatrix;
|
||||
|
||||
//! These should be set by loaders.
|
||||
core::vector3df Animatedposition;
|
||||
core::vector3df Animatedscale;
|
||||
core::quaternion Animatedrotation;
|
||||
|
||||
// The .x and .gltf formats pre-calculate this
|
||||
std::optional<core::matrix4> GlobalInversedMatrix;
|
||||
private:
|
||||
//! Internal members used by SkinnedMesh
|
||||
friend class SkinnedMesh;
|
||||
|
||||
SJoint *UseAnimationFrom;
|
||||
bool GlobalSkinningSpace;
|
||||
|
||||
s32 positionHint;
|
||||
s32 scaleHint;
|
||||
s32 rotationHint;
|
||||
};
|
||||
|
||||
// Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
|
||||
// these functions will use the needed arrays, set values, etc to help the loaders
|
||||
|
||||
//! exposed for loaders to add mesh buffers
|
||||
core::array<SSkinMeshBuffer *> &getMeshBuffers();
|
||||
|
||||
//! alternative method for adding joints
|
||||
core::array<SJoint *> &getAllJoints();
|
||||
|
||||
//! alternative method for reading joints
|
||||
const core::array<SJoint *> &getAllJoints() const;
|
||||
|
||||
//! loaders should call this after populating the mesh
|
||||
void finalize();
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
SSkinMeshBuffer *addMeshBuffer();
|
||||
|
||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||
void addMeshBuffer(SSkinMeshBuffer *meshbuf);
|
||||
|
||||
//! Adds a new joint to the mesh, access it as last one
|
||||
SJoint *addJoint(SJoint *parent = 0);
|
||||
|
||||
//! Adds a new position key to the mesh, access it as last one
|
||||
SPositionKey *addPositionKey(SJoint *joint);
|
||||
//! Adds a new rotation key to the mesh, access it as last one
|
||||
SRotationKey *addRotationKey(SJoint *joint);
|
||||
//! Adds a new scale key to the mesh, access it as last one
|
||||
SScaleKey *addScaleKey(SJoint *joint);
|
||||
|
||||
//! Adds a new weight to the mesh, access it as last one
|
||||
SWeight *addWeight(SJoint *joint);
|
||||
|
||||
private:
|
||||
void checkForAnimation();
|
||||
|
||||
void normalizeWeights();
|
||||
|
||||
void buildAllLocalAnimatedMatrices();
|
||||
|
||||
void buildAllGlobalAnimatedMatrices(SJoint *Joint = 0, SJoint *ParentJoint = 0);
|
||||
|
||||
void getFrameData(f32 frame, SJoint *Node,
|
||||
core::vector3df &position, s32 &positionHint,
|
||||
core::vector3df &scale, s32 &scaleHint,
|
||||
core::quaternion &rotation, s32 &rotationHint);
|
||||
|
||||
void calculateGlobalMatrices(SJoint *Joint, SJoint *ParentJoint);
|
||||
|
||||
void skinJoint(SJoint *Joint, SJoint *ParentJoint);
|
||||
|
||||
void calculateTangents(core::vector3df &normal,
|
||||
core::vector3df &tangent, core::vector3df &binormal,
|
||||
const core::vector3df &vt1, const core::vector3df &vt2, const core::vector3df &vt3,
|
||||
const core::vector2df &tc1, const core::vector2df &tc2, const core::vector2df &tc3);
|
||||
|
||||
core::array<SSkinMeshBuffer *> *SkinningBuffers; // Meshbuffer to skin, default is to skin localBuffers
|
||||
|
||||
core::array<SSkinMeshBuffer *> LocalBuffers;
|
||||
//! Mapping from meshbuffer number to bindable texture slot
|
||||
std::vector<u32> TextureSlots;
|
||||
|
||||
core::array<SJoint *> AllJoints;
|
||||
core::array<SJoint *> RootJoints;
|
||||
|
||||
// bool can't be used here because std::vector<bool>
|
||||
// doesn't allow taking a reference to individual elements.
|
||||
core::array<core::array<char>> Vertices_Moved;
|
||||
|
||||
core::aabbox3d<f32> BoundingBox;
|
||||
|
||||
f32 EndFrame;
|
||||
f32 FramesPerSecond;
|
||||
|
||||
f32 LastAnimatedFrame;
|
||||
bool SkinnedLastFrame;
|
||||
|
||||
E_INTERPOLATION_MODE InterpolationMode : 8;
|
||||
|
||||
bool HasAnimation;
|
||||
bool PreparedForSkinning;
|
||||
bool AnimateNormals;
|
||||
bool HardwareSkinning;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
} // end namespace irr
|
Loading…
Add table
Add a link
Reference in a new issue