osg.Geometry

class osg.Geometry
Represents

c++ class

Wraps

osg::Geometry

Bases

osg.Drawable

-- Example of Geometry object creation.

-- Creates regular polygon with <verticesCount> vertices and adds it to HUD.
-- The resulting polygon is inscribed in a circle with a radius of <radius>.

local verticesCount     = 6
local radius            = 0.2
local color             = osg.Vec4(1.0, 1.0, 1.0, 1.0)
local lineWidth         = 3     -- NOTE: Ignored on macOS (not supported in OpenGL Core Profile)
local z                 = 0.0

local vertexArray = osg.Vec3Array(verticesCount)
local drawElements = osg.DrawElementsUShort(osg.PrimitiveSet.LINE_LOOP, verticesCount)

local geometry = osg.Geometry()
geometry:setUseVertexBufferObjects(true)
geometry:setVertexArray(vertexArray)
geometry:addPrimitiveSet(drawElements)

-- NOTE: Must be marked as DYNAMIC if you need to change vertexArray later
-- geometry:setDataVariance(osg.Object.DYNAMIC)

local uniform = osg.Uniform.Vec4f("ev_MaterialDiffuse", color)
-- NOTE: Should be marked as DYNAMIC (for optimization purposes)
uniform:setDataVariance(osg.Object.DYNAMIC)

local stateSet = geometry:getOrCreateStateSet()
stateSet:setAttributeAndModes(osg.LineWidth(lineWidth))
stateSet:addUniform(uniform)
stateSet:setMode(GLenum.GL_LIGHTING, osg.StateAttribute.OFF)    -- Disable lighting

local step = 2*math.pi/verticesCount
for i = 0, verticesCount - 1 do
    local x = radius*math.cos(math.pi*0.5 + step*i)
    local y = radius*math.sin(math.pi*0.5 + step*i)

    loginfo(string.format("i = %d, deg = %f %.f %.f", i, math.deg(math.pi*0.5 + step*i), x, y))

    drawElements:addElement(i)
    vertexArray:set(i, osg.Vec3(x, y, z))
end

-- geometry:setNodeMask(0xffffffff) -- mask can be changed
-- coreProfileNode(geometry)        -- no need (will be called before first Viewer's frame)

local hud = reactorController:getReactorByName("HeadUpDisplay") -- must be presented in the project
hud.node:addChild(geometry)

return geometry

Constructors:

osg.Geometry()

Methods:

:setVertexArray(osg.Array array)

Параметры

array (osg.Array) –

:setNormalArray(osg.Array array)

Параметры

array (osg.Array) –

:setColorArray(osg.Array array)

Параметры

array (osg.Array) –

:setSecondaryColorArray(osg.Array array)

Параметры

array (osg.Array) –

:setFogCoordArray(osg.Array array)

Параметры

array (osg.Array) –

:setTexCoordArray(unsigned unit, osg.Array array)

Параметры
:getVertexArray()

Тип результата

osg.Array

:getNormalArray()

Тип результата

osg.Array

:getColorArray()

Тип результата

osg.Array

:getSecondaryColorArray()

Тип результата

osg.Array

:getFogCoordArray()

Тип результата

osg.Array

:getTexCoordArray(unsigned unit)

Параметры

unit (unsigned) –

Тип результата

osg.Array

:setVertexAttribArray(unsigned index, osg.Array array)

Параметры
:getVertexAttribArray(unsigned index)

Параметры

index (unsigned) –

Тип результата

osg.Array

:setVertexAttribNormalize(unsigned index, bool norm)

Deprecated, use array->set*Normalize(..).

Параметры
  • index (unsigned) –

  • norm (bool) –

:getVertexAttribNormalize(unsigned index)

Deprecated, use array->get*Normalize(..).

Параметры

index (unsigned) –

Тип результата

bool

:getNumPrimitiveSets()

Тип результата

unsigned

:addPrimitiveSet(osg.PrimitiveSet set)

Add a primitive set to the geometry.

Параметры

set (osg.PrimitiveSet) –

Тип результата

bool

:insertPrimitiveSet(unsigned i, osg.PrimitiveSet set)

Insert a primitive set to the specified position in geometry’s primitive set list.

Параметры
Тип результата

bool

:removePrimitiveSet(unsigned i, unsigned numElementsToRemove)

Remove primitive set(s) from the specified position in geometry’s primitive set list.

Параметры
  • i (unsigned) –

  • numElementsToRemove (unsigned) –

Тип результата

bool

:getPrimitiveSetIndex(osg.PrimitiveSet set)

Get the index number of a primitive set, return a value between 0 and osg.Geometry.getNumPrimitiveSets()-1 if found, if not found then return osg.Geometry.getNumPrimitiveSets(). When checking for a valid find value use if ((value = geometry:getPrimitiveSetIndex(primitive)) ~= geometry:getNumPrimitiveSet()).

Параметры

set (osg.PrimitiveSet) –

Тип результата

unsigned