CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::scene2::MeshNode Class Reference

#include <CUMeshNode.h>

Inheritance diagram for cugl::scene2::MeshNode:
cugl::scene2::TexturedNode cugl::scene2::SceneNode

Public Member Functions

 MeshNode ()
 
 ~MeshNode ()
 
virtual void dispose () override
 
virtual bool init () override
 
bool initWithMesh (const Mesh< SpriteVertex2 > &mesh)
 
bool initWithPoly (const Poly2 &poly)
 
bool initWithPoly (const Poly2 &poly, const std::vector< Color4 > &colors)
 
virtual bool initWithFile (const std::string filename) override
 
bool initWithFileMesh (const std::string filename, const Mesh< SpriteVertex2 > &mesh)
 
bool initWithFilePoly (const std::string filename, const Poly2 &poly)
 
bool initWithFilePoly (const std::string filename, const Poly2 &poly, const std::vector< Color4 > &colors)
 
virtual bool initWithTexture (const std::shared_ptr< Texture > &texture) override
 
bool initWithTextureMesh (const std::shared_ptr< Texture > &texture, const Mesh< SpriteVertex2 > &mesh)
 
bool initWithTexturePoly (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
bool initWithTexturePoly (const std::shared_ptr< Texture > &texture, const Poly2 &poly, const std::vector< Color4 > &colors)
 
virtual bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const override
 
void setMesh (const Mesh< SpriteVertex2 > &mesh)
 
const Mesh< SpriteVertex2 > & getMesh () const
 
Mesh< SpriteVertex2 > & getMesh ()
 
const SpriteVertex2getVertex (size_t index) const
 
SpriteVertex2getVertex (size_t index)
 
void setVertexColors (const std::vector< Color4 > &colors)
 
void setVertexTexCoords (const std::vector< Vec2 > &coords)
 
void setVertexGradCoords (const std::vector< Vec2 > &coords)
 
const Rect getBoundingRect () const
 
void setPolygon (const Poly2 &poly)
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) override
 
- Public Member Functions inherited from cugl::scene2::TexturedNode
 TexturedNode ()
 
 ~TexturedNode ()
 
virtual void dispose () override
 
virtual bool init () override
 
virtual bool initWithFile (const std::string filename)
 
virtual bool initWithTexture (const std::shared_ptr< Texture > &texture)
 
virtual bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const override
 
void setTexture (const std::string &filename)
 
void setTexture (const std::shared_ptr< Texture > &texture)
 
std::shared_ptr< Texture > & getTexture ()
 
const std::shared_ptr< Texture > & getTexture () const
 
const std::shared_ptr< Gradient > & getGradient () const
 
void setGradient (const std::shared_ptr< Gradient > &gradient)
 
void shiftTexture (float dx, float dy)
 
void setBlendFunc (GLenum srcFactor, GLenum dstFactor)
 
GLenum getSourceBlendFactor () const
 
GLenum getDestinationBlendFactor () const
 
void setBlendEquation (GLenum equation)
 
GLenum getBlendEquation () const
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual std::string toString (bool verbose=false) const override
 
bool isAbsolute () const
 
void setAbsolute (bool flag)
 
virtual void setAnchor (const Vec2 anchor) override
 
virtual void setAnchor (float x, float y) override
 
virtual void setContentSize (const Size size) override
 
virtual void setContentSize (float width, float height) override
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) override=0
 
void refresh ()
 
- Public Member Functions inherited from cugl::scene2::SceneNode
 SceneNode ()
 
 ~SceneNode ()
 
virtual void dispose ()
 
virtual bool init ()
 
virtual bool initWithPosition (const Vec2 pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size size)
 
virtual bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect rect)
 
virtual bool initWithBounds (float x, float y, float width, float height)
 
virtual bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const
 
unsigned int getTag () const
 
void setTag (unsigned int tag)
 
const std::string getName () const
 
void setName (const std::string name)
 
const std::string getClassName () const
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Vec2 getPosition () const
 
void setPosition (const Vec2 &position)
 
void setPosition (float x, float y)
 
float getPositionX (void) const
 
void setPositionX (float x)
 
float getPositionY (void) const
 
void setPositionY (float y)
 
Vec2 getWorldPosition () const
 
const Size getContentSize () const
 
virtual void setContentSize (const Size size)
 
virtual void setContentSize (float width, float height)
 
float getContentWidth () const
 
void setContentWidth (float width)
 
float getContentHeight () const
 
void setContentHeight (float height)
 
virtual Rect getLayoutBounds () const
 
Size getSize () const
 
float getWidth () const
 
float getHeight () const
 
Rect getBoundingBox () const
 
virtual bool inContentBounds (const Vec2 point)
 
bool inContentBounds (float x, float y)
 
virtual void setAnchor (const Vec2 anchor)
 
virtual void setAnchor (float x, float y)
 
const Vec2 getAnchor () const
 
Vec2 getAnchorInPixels ()
 
Color4 getColor () const
 
virtual void setColor (Color4 color)
 
Color4 getAbsoluteColor ()
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool hasRelativeColor () const
 
void setRelativeColor (bool flag)
 
std::shared_ptr< ScissorgetScissor () const
 
void setScissor (const std::shared_ptr< Scissor > &scissor)
 
void setScissor ()
 
const Vec2 getScale () const
 
float getScaleX () const
 
float getScaleY () const
 
void setScale (float scale)
 
void setScale (const Vec2 vec)
 
void setScale (float sx, float sy)
 
float getAngle ()
 
void setAngle (float angle)
 
const Affine2getTransform () const
 
const Affine2getAlternateTransform () const
 
void setAlternateTransform (const Affine2 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Affine2getNodeToParentTransform () const
 
Affine2 getParentToNodeTransform () const
 
virtual Affine2 getNodeToWorldTransform () const
 
Affine2 getWorldToNodeTransform () const
 
Vec2 screenToNodeCoords (const Vec2 screenPoint) const
 
Vec2 worldToNodeCoords (const Vec2 worldPoint) const
 
Vec2 nodeToScreenCoords (const Vec2 nodePoint) const
 
Vec2 nodeToWorldCoords (const Vec2 nodePoint) const
 
Vec2 parentToNodeCoords (const Vec2 parentPoint) const
 
Vec2 nodeToParentCoords (const Vec2 nodePoint) const
 
size_t getChildCount () const
 
std::shared_ptr< SceneNodegetChild (unsigned int pos)
 
const std::shared_ptr< SceneNode > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< TgetChild (unsigned int pos) const
 
std::shared_ptr< SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< TgetChildByTag (unsigned int tag) const
 
std::shared_ptr< SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< TgetChildByName (const std::string name) const
 
std::vector< std::shared_ptr< SceneNode > > getChildren ()
 
const std::vector< std::shared_ptr< SceneNode > > & getChildren () const
 
void addChild (const std::shared_ptr< SceneNode > &child)
 
void addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag)
 
void addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string name)
 
void swapChild (const std::shared_ptr< SceneNode > &child1, const std::shared_ptr< SceneNode > &child2, bool inherit=false)
 
SceneNodegetParent ()
 
const SceneNodegetParent () const
 
Scene2getScene ()
 
const Scene2getScene () const
 
void removeFromParent ()
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< SceneNode > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string name)
 
virtual void removeAllChildren ()
 
void setPriority (float priority)
 
float getPriority ()
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint)
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch)
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint)
 
const std::shared_ptr< Layout > & getLayout () const
 
void setLayout (const std::shared_ptr< Layout > &layout)
 
virtual void doLayout ()
 

Static Public Member Functions

static std::shared_ptr< MeshNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithMesh (const Mesh< SpriteVertex2 > &mesh)
 
static std::shared_ptr< SceneNodeallocWithPoly (const Poly2 &poly, const std::vector< Color4 > colors)
 
static std::shared_ptr< SceneNodeallocWithFile (const std::string filename)
 
static std::shared_ptr< SceneNodeallocWithFileMesh (const std::string filename, const Mesh< SpriteVertex2 > &mesh)
 
static std::shared_ptr< SceneNodeallocWithFilePoly (const std::string filename, const Poly2 &poly)
 
static std::shared_ptr< SceneNodeallocWithFilePoly (const std::string filename, const Poly2 &poly, std::vector< Color4 > colors)
 
static std::shared_ptr< SceneNodeallocWithTexture (const std::shared_ptr< Texture > &texture)
 
static std::shared_ptr< SceneNodeallocWithTextureMesh (const std::shared_ptr< Texture > &texture, const Mesh< SpriteVertex2 > &mesh)
 
static std::shared_ptr< SceneNodeallocWithTexturePoly (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
static std::shared_ptr< SceneNodeallocWithTexturePoly (const std::shared_ptr< Texture > &texture, const Poly2 &poly, std::vector< Color4 > colors)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 
- Static Public Member Functions inherited from cugl::scene2::SceneNode
static std::shared_ptr< SceneNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithPosition (const Vec2 pos)
 
static std::shared_ptr< SceneNodeallocWithPosition (float x, float y)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Size size)
 
static std::shared_ptr< SceneNodeallocWithBounds (float width, float height)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Rect rect)
 
static std::shared_ptr< SceneNodeallocWithBounds (float x, float y, float width, float height)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 

Protected Attributes

int _flipFlags
 
- Protected Attributes inherited from cugl::scene2::TexturedNode
std::shared_ptr< Texture_texture
 
std::shared_ptr< Gradient_gradient
 
bool _absolute
 
Vec2 _offset
 
bool _rendered
 
Mesh< SpriteVertex2_mesh
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
bool _flipHorizontal
 
bool _flipVertical
 
- Protected Attributes inherited from cugl::scene2::SceneNode
Vec2 _position
 
Vec2 _anchor
 
Size _contentSize
 
Color4 _tintColor
 
bool _hasParentColor
 
bool _isVisible
 
std::shared_ptr< Scissor_scissor
 
Vec2 _scale
 
float _angle
 
Affine2 _transform
 
bool _useTransform
 
Affine2 _combined
 
std::vector< std::shared_ptr< SceneNode > > _children
 
SceneNode_parent
 
Scene2_graph
 
std::shared_ptr< Layout_layout
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
std::string _classname
 
float _priority
 
std::shared_ptr< JsonValue_json
 

Additional Inherited Members

- Protected Member Functions inherited from cugl::scene2::TexturedNode
virtual void generateRenderData ()=0
 
virtual void updateTextureCoords ()=0
 
virtual void clearRenderData ()
 
 CU_DISALLOW_COPY_AND_ASSIGN (TexturedNode)
 

Detailed Description

This is a scene graph node to support mesh manipulation

The API for this class is very similar to PolygonNode, except that the use specifies a mesh directly (instead of inferring it from the shape). This allows the user direct control over the interior vertices, and the individual vertex colors.

Unlike polgon nodes, all mesh nodes use absolute positioning by default.

Constructor & Destructor Documentation

◆ MeshNode()

cugl::scene2::MeshNode::MeshNode ( )
inline

Creates an empty mesh with the degenerate texture.

You must initialize this MeshNode before use.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.

◆ ~MeshNode()

cugl::scene2::MeshNode::~MeshNode ( )
inline

Releases all resources allocated with this node.

This will release, but not necessarily delete the associated texture. However, the polygon and drawing commands will be deleted and no longer safe to use.

Member Function Documentation

◆ alloc()

static std::shared_ptr< MeshNode > cugl::scene2::MeshNode::alloc ( )
inlinestatic

Returns a default mesh node.

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes. The vertex colors will be blue, red, and yellow.

Returns
a newly allocated default mesh node.

◆ allocWithData()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
inlinestatic

Returns a newly allocated mesh node with the given JSON specification.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:

"mesh":  A JSON object defining a mesh of SpriteVertex2

This JSON object for mesh is required. It is similar to the json for Poly2, but with the attributes for SpriteVertex2. That is, it consist of the following attributes:

"positions":     An (even) list of floats, representing the vertex positions
"colors":        A list of colors (strings or four element tuples of 0..255)
"texcoords":     An (even) list of floats, representing the vertex texture coords
"gradcoords":    An (even) list of floats, representing the vertex gradient coords
"indices":       An intenger list of triangle indices (in multiples of 3)

In this JSON, only positions and indices are required. The others have default value. The lists positions, texcoords, and colors, should all have the same length. The list colors should be half the size of the others.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
a newly allocated mesh node with the given JSON specification.

◆ allocWithFile()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithFile ( const std::string  filename)
inlinestatic

Returns a newly allocated mesh node from the image filename.

After creation, the mesh will be a rectangle. The vertices of this mesh will be the corners of the image. The rectangle will be triangulated with the standard two triangles. The colors of all the vertices will be white.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithFileMesh()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithFileMesh ( const std::string  filename,
const Mesh< SpriteVertex2 > &  mesh 
)
inlinestatic

Returns a newly allocated mesh node from the image filename and mesh

The texture coordinates in the mesh will determine how to interpret the texture.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
meshThe mesh data
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithFilePoly() [1/2]

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithFilePoly ( const std::string  filename,
const Poly2 poly 
)
inlinestatic

Returns a newly allocated mesh node from the image filename and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices will all have color white

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
polyThe polygon to define the mesh
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithFilePoly() [2/2]

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithFilePoly ( const std::string  filename,
const Poly2 poly,
std::vector< Color4 colors 
)
inlinestatic

Returns a newly allocated mesh node from the image filename and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices are assigned the respective colors from the colors vector, in the order that they are specified in the polygon.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
polyThe polygon to define the mesh
colorsThe vertex colors
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithMesh()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithMesh ( const Mesh< SpriteVertex2 > &  mesh)
inlinestatic

Intializes a mesh node from the current mesh

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes.

Parameters
meshThe mesh data
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithPoly()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithPoly ( const Poly2 poly,
const std::vector< Color4 colors 
)
inlinestatic

Returns a newly allocated mesh node using from a polygon and set of colors.

This method uses the polygon to construct a mesh for the mesh node. The vertices are assigned the respective colors from the colors vector, in the order that they are specified in the polygon.

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes.

Parameters
polyThe polygon to define the mesh
colorsThe vertex colors
Returns
a newly allocated mesh node using from a polygon and set of colors.

◆ allocWithTexture()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithTexture ( const std::shared_ptr< Texture > &  texture)
inlinestatic

Returns a newly allocated mesh node from a Texture object.

After creation, the mesh will be a rectangle. The vertices of this mesh will be the corners of the image. The rectangle will be triangulated with the standard two triangles. The colors of all the vertices will be white.

Parameters
textureA shared pointer to a Texture object.
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithTextureMesh()

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithTextureMesh ( const std::shared_ptr< Texture > &  texture,
const Mesh< SpriteVertex2 > &  mesh 
)
inlinestatic

Returns a newly allocated mesh node from the Texture object and mesh

The texture coordinates in the mesh will determine how to interpret the texture.

Parameters
textureA shared pointer to a Texture object.
meshThe mesh data
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithTexturePoly() [1/2]

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly 
)
inlinestatic

Returns a newly allocated mesh node from the Texture object and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices will all have color white

Parameters
textureA shared pointer to a Texture object.
polyThe polygon to define the mesh
Returns
true if the sprite is initialized properly, false otherwise.

◆ allocWithTexturePoly() [2/2]

static std::shared_ptr< SceneNode > cugl::scene2::MeshNode::allocWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly,
std::vector< Color4 colors 
)
inlinestatic

Returns a newly allocated mesh node from the Texture object and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices are assigned the respective colors from the colors vector, in the order that they are specified in the polygon.

Parameters
textureA shared pointer to a Texture object.
polyThe polygon to define the mesh
colorsThe vertex colors
Returns
true if the sprite is initialized properly, false otherwise.

◆ copy()

virtual std::shared_ptr< SceneNode > cugl::scene2::MeshNode::copy ( const std::shared_ptr< SceneNode > &  dst) const
overridevirtual

Performs a shallow copy of this Node into dst.

No children from this node are copied, and no children of dst are modified. In addition, the parents of both Nodes are unchanged. However, all other attributes of this node are copied.

Parameters
dstThe Node to copy into
Returns
A reference to dst for chaining.

Reimplemented from cugl::scene2::TexturedNode.

◆ dispose()

virtual void cugl::scene2::MeshNode::dispose ( )
overridevirtual

Disposes all of the resources used by this node.

A disposed Node can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them.

It is unsafe to call this on a Node that is still currently inside of a scene graph.

Reimplemented from cugl::scene2::TexturedNode.

◆ draw()

virtual void cugl::scene2::MeshNode::draw ( const std::shared_ptr< SpriteBatch > &  batch,
const Affine2 transform,
Color4  tint 
)
overridevirtual

Draws this mesh node via the given SpriteBatch.

This method only worries about drawing the current node. It does not attempt to render the children.

Parameters
batchThe SpriteBatch to draw with.
transformThe global transformation matrix.
tintThe tint to blend with the Node color.

Implements cugl::scene2::TexturedNode.

◆ getBoundingRect()

const Rect cugl::scene2::MeshNode::getBoundingRect ( ) const

Returns the rect of the mesh node in points

The bounding rect is the smallest rectangle containing all of the points in the mesh.

This value also defines the content size of the node. The mesh will be shifted so that its bounding rect is centered at the node center.

◆ getMesh() [1/2]

Mesh< SpriteVertex2 > & cugl::scene2::MeshNode::getMesh ( )
inline

Returns a reference to the underlying mesh.

Returns
a reference to the underlying mesh.

◆ getMesh() [2/2]

const Mesh< SpriteVertex2 > & cugl::scene2::MeshNode::getMesh ( ) const
inline

Returns a reference to the underlying mesh.

Returns
a reference to the underlying mesh.

◆ getVertex() [1/2]

SpriteVertex2 * cugl::scene2::MeshNode::getVertex ( size_t  index)

Returns a pointer to the sprite vertex as the given index

This sprite vertex can be updated to change the vertex position, color, texture coordinates, or gradient coordinates. If there is not vertex as that index, this method returns nullptr.

Parameters
indexThe sprite index
Returns
a pointer to the sprite vertex as the given index

◆ getVertex() [2/2]

const SpriteVertex2 * cugl::scene2::MeshNode::getVertex ( size_t  index) const

Returns a pointer to the sprite vertex as the given index

This sprite vertex can be updated to change the vertex position, color, texture coordinates, or gradient coordinates. If there is not vertex as that index, this method returns nullptr.

Parameters
indexThe sprite index
Returns
a pointer to the sprite vertex as the given index

◆ init()

virtual bool cugl::scene2::MeshNode::init ( )
overridevirtual

Initializes a mesh node as a default equilateral triangle mesh.

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes. The vertex colors will be blue, red, and yellow.

Returns
true if the mesh node is initialized properly, false otherwise.

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithData()

virtual bool cugl::scene2::MeshNode::initWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
overridevirtual

Initializes a mesh node with the given JSON specification.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:

"mesh":  A JSON object defining a mesh of SpriteVertex2

This JSON object for mesh is required. It is similar to the json for Poly2, but with the attributes for SpriteVertex2. That is, it consist of the following attributes:

"positions":     An (even) list of floats, representing the vertex positions
"colors":        A list of colors (strings or four element tuples of 0..255)
"texcoords":     An (even) list of floats, representing the vertex texture coords
"gradcoords":    An (even) list of floats, representing the vertex gradient coords
"indices":       An intenger list of triangle indices (in multiples of 3)

In this JSON, only positions and indices are required. The others have default value. The lists positions, texcoords, and colors, should all have the same length. The list colors should be half the size of the others.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithFile()

virtual bool cugl::scene2::MeshNode::initWithFile ( const std::string  filename)
overridevirtual

Initializes a mesh node from the image filename.

After creation, the mesh will be a rectangle. The vertices of this mesh will be the corners of the image. The rectangle will be triangulated with the standard two triangles. The colors of all the vertices will be white.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
Returns
true if the sprite is initialized properly, false otherwise.

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithFileMesh()

bool cugl::scene2::MeshNode::initWithFileMesh ( const std::string  filename,
const Mesh< SpriteVertex2 > &  mesh 
)

Initializes a mesh node from the image filename and mesh

The texture coordinates in the mesh will determine how to interpret the texture.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
meshThe mesh data
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithFilePoly() [1/2]

bool cugl::scene2::MeshNode::initWithFilePoly ( const std::string  filename,
const Poly2 poly 
)

Initializes a mesh node from the image filename and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices will all have color white

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
polyThe polygon to define the mesh
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithFilePoly() [2/2]

bool cugl::scene2::MeshNode::initWithFilePoly ( const std::string  filename,
const Poly2 poly,
const std::vector< Color4 > &  colors 
)

Initializes a mesh node from the image filename and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices are assigned the respective colors from the colors vector, in the order that they are specified in the polygon.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
polyThe polygon to define the mesh
colorsThe vertex colors
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithMesh()

bool cugl::scene2::MeshNode::initWithMesh ( const Mesh< SpriteVertex2 > &  mesh)
inline

Initializes a mesh node from the current mesh

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes.

Parameters
meshThe mesh data
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithPoly() [1/2]

bool cugl::scene2::MeshNode::initWithPoly ( const Poly2 poly)
inline

Initializes a mesh node using from a polygon.

This method uses the polygon to construct a mesh for the mesh node. The colors of all the vertices will be white.

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes.

Parameters
polyThe polygon to define the mesh
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithPoly() [2/2]

bool cugl::scene2::MeshNode::initWithPoly ( const Poly2 poly,
const std::vector< Color4 > &  colors 
)
inline

Initializes a mesh node using from a polygon and set of colors.

This method uses the polygon to construct a mesh for the mesh node. The vertices are assigned the respective colors from the colors vector, in the order that they are specified in the polygon.

The mesh will use the texture Texture#getBlank, which is suitable for drawing solid shapes.

Parameters
polyThe polygon to define the mesh
colorsThe vertex colors
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithTexture()

virtual bool cugl::scene2::MeshNode::initWithTexture ( const std::shared_ptr< Texture > &  texture)
overridevirtual

Initializes a mesh node from a Texture object.

After creation, the mesh will be a rectangle. The vertices of this mesh will be the corners of the image. The rectangle will be triangulated with the standard two triangles. The colors of all the vertices will be white.

Parameters
textureA shared pointer to a Texture object.
Returns
true if the sprite is initialized properly, false otherwise.

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithTextureMesh()

bool cugl::scene2::MeshNode::initWithTextureMesh ( const std::shared_ptr< Texture > &  texture,
const Mesh< SpriteVertex2 > &  mesh 
)

Initializes a mesh node from the Texture object and mesh

The texture coordinates in the mesh will determine how to interpret the texture.

Parameters
textureA shared pointer to a Texture object.
meshThe mesh data
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithTexturePoly() [1/2]

bool cugl::scene2::MeshNode::initWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly 
)

Initializes a mesh node from the Texture object and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices will all have color white

Parameters
textureA shared pointer to a Texture object.
polyThe polygon to define the mesh
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithTexturePoly() [2/2]

bool cugl::scene2::MeshNode::initWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly,
const std::vector< Color4 > &  colors 
)

Initializes a mesh node from the Texture object and the given polygon.

This method uses the polygon to construct a mesh for the mesh node. The vertices are assigned the respective colors from the colors vector, in the order that they are specified in the polygon.

Parameters
textureA shared pointer to a Texture object.
polyThe polygon to define the mesh
colorsThe vertex colors
Returns
true if the sprite is initialized properly, false otherwise.

◆ setMesh()

void cugl::scene2::MeshNode::setMesh ( const Mesh< SpriteVertex2 > &  mesh)

Sets the mesh for the mesh node.

Parameters
meshThe updated mesh.

◆ setPolygon()

void cugl::scene2::MeshNode::setPolygon ( const Poly2 poly)

Sets the mesh to match the given polygon.

The mesh textures and colors will be recomputed as if this were a PolygonNode.

Parameters
polyThe new poly2 object.

◆ setVertexColors()

void cugl::scene2::MeshNode::setVertexColors ( const std::vector< Color4 > &  colors)

Sets the colors of the mesh vertices.

The parameter vector should have a size equal to the number of vertices. If it is too long, extra colors are ignored. If it is too short, the the final color will be used for all remaining vertices.

Parameters
colorsThe vertex colors

◆ setVertexGradCoords()

void cugl::scene2::MeshNode::setVertexGradCoords ( const std::vector< Vec2 > &  coords)

Sets the gradient coordinates of the mesh vertices.

The parameter vector should have a size equal to the number of vertices. If it is too long, extra coordinates are ignored. If it is too short, the the final texture coordinate will be used for all remaining vertices.

Parameters
coordsThe gradient coordinates

◆ setVertexTexCoords()

void cugl::scene2::MeshNode::setVertexTexCoords ( const std::vector< Vec2 > &  coords)

Sets the texture coordinates of the mesh vertices.

The parameter vector should have a size equal to the number of vertices. If it is too long, extra coordinates are ignored. If it is too short, the the final texture coordinate will be used for all remaining vertices.

Parameters
coordsThe texture coordinates

Member Data Documentation

◆ _flipFlags

int cugl::scene2::MeshNode::_flipFlags
protected

Used to keep track of the current flip state


The documentation for this class was generated from the following file: