panda3d.core.Geom

class Geom

Bases: CopyOnWriteObject, GeomEnums

A container for geometry primitives. This class associates one or more GeomPrimitive objects with a table of vertices defined by a GeomVertexData object. All of the primitives stored in a particular Geom are drawn from the same set of vertices (each primitive uses a subset of all of the vertices in the table), and all of them must be rendered at the same time, in the same graphics state.

Inheritance diagram

Inheritance diagram of Geom

__init__(data: GeomVertexData) → None
addPrimitive(primitive: GeomPrimitive) → None

Inserts a new GeomPrimitive structure to the Geom object. This specifies a particular subset of vertices that are used to define geometric primitives of the indicated type.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

assign(copy: Geom) → Geom
Return type

Geom

property bounds_type
Getter

Returns the bounding volume type set with setBoundsType().

Setter

Specifies the desired type of bounding volume that will be created for this Geom. This is normally BoundingVolume::BT_default, which means to set the type according to the config variable “bounds-type”.

If this is BT_sphere or BT_box, a BoundingSphere or BoundingBox is explicitly created. If it is BT_best, a BoundingBox is created.

This affects the implicit bounding volume only. If an explicit bounding volume is set on the Geom with setBounds(), that bounding volume type is used. (This is different behavior from the similar method on PandaNode.)

Return type

BoundsType

checkValid() → bool

Verifies that the all of the primitives within the geom reference vertices that actually exist within the geom’s GeomVertexData. Returns true if the geom appears to be valid, false otherwise.

checkValid(vertex_data: GeomVertexData) → bool

Verifies that the all of the primitives within the geom reference vertices that actually exist within the indicated GeomVertexData. Returns true if the geom appears to be valid, false otherwise.

clearBounds() → None

Reverses the effect of a previous call to setBounds(), and allows the bounding volume to be automatically computed once more based on the vertices.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

clearCache() → None

Removes all of the previously-cached results of munge_geom().

This blows away the entire cache, upstream and downstream the pipeline. Use clearCacheStage() instead if you only want to blow away the cache at the current stage and upstream.

clearCacheStage(current_thread: Thread) → None

Removes all of the previously-cached results of munge_geom(), at the current pipeline stage and upstream. Does not affect the downstream cache.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

clearPrimitives() → None

Removes all the primitives from the Geom object (but keeps the same table of vertices). You may then re-add primitives one at a time via calls to addPrimitive().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

copyPrimitivesFrom(other: Geom) → bool

Copies the primitives from the indicated Geom into this one. This does require that both Geoms contain the same fundamental type primitives, both have a compatible shade model, and both use the same GeomVertexData. Both Geoms must also be the same specific class type (i.e. if one is a GeomTextGlyph, they both must be.)

Returns true if the copy is successful, or false otherwise (because the Geoms were mismatched).

decompose() → Geom

Decomposes all of the primitives within this Geom, returning the result. See GeomPrimitive.decompose().

Return type

Geom

decomposeInPlace() → None

Decomposes all of the primitives within this Geom, leaving the results in place. See GeomPrimitive.decompose().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

doubleside() → Geom

Doublesides all of the primitives within this Geom, returning the result. See GeomPrimitive.doubleside().

Return type

Geom

doublesideInPlace() → None

Doublesides all of the primitives within this Geom, leaving the results in place. See GeomPrimitive.doubleside().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

property geom_rendering

Returns the set of GeomRendering bits that represent the rendering properties required to properly render this Geom.

Return type

int

getAnimatedVertexData(force: bool, current_thread: Thread) → GeomVertexData

Returns a GeomVertexData that represents the results of computing the vertex animation on the CPU for this Geom’s vertex data.

If there is no CPU-defined vertex animation on this object, this just returns the original object.

If there is vertex animation, but the VertexTransform values have not changed since last time, this may return the same pointer it returned previously. Even if the VertexTransform values have changed, it may still return the same pointer, but with its contents modified (this is preferred, since it allows the graphics backend to update vertex buffers optimally).

If force is false, this method may return immediately with stale data, if the vertex data is not completely resident. If force is true, this method will never return stale data, but may block until the data is available.

Return type

GeomVertexData

getBounds(current_thread: Thread) → BoundingVolume

Returns the bounding volume for the Geom.

Return type

BoundingVolume

getBoundsType() → BoundsType

Returns the bounding volume type set with setBoundsType().

Return type

BoundsType

static getClassType() → TypeHandle
Return type

TypeHandle

getGeomRendering() → int

Returns the set of GeomRendering bits that represent the rendering properties required to properly render this Geom.

getModified(current_thread: Thread) → UpdateSeq

Returns a sequence number which is guaranteed to change at least every time any of the primitives in the Geom is modified, or the set of primitives is modified. However, this does not include modifications to the vertex data, which should be tested separately.

Return type

UpdateSeq

getNestedVertices(current_thread: Thread) → int

Returns the number of vertices rendered by all primitives within the Geom.

getNumBytes() → int

Returns the number of bytes consumed by the geom and its primitives (but not including its vertex table).

getNumPrimitives() → size_t

Returns the number of GeomPrimitive objects stored within the Geom, each of which represents a number of primitives of a particular type.

Return type

size_t

getPrimitive(i: size_t) → GeomPrimitive

Returns a const pointer to the ith GeomPrimitive object stored within the Geom. Use this call only to inspect the ith object; use modifyPrimitive() or setPrimitive() if you want to modify it.

Return type

GeomPrimitive

getPrimitiveType() → PrimitiveType

Returns the fundamental primitive type that is common to all GeomPrimitives added within the Geom. All nested primitives within a particular Geom must be the same type (that is, you can mix triangles and tristrips, because they are both the same fundamental type PT_polygons, but you cannot mix triangles and points withn the same Geom).

Return type

PrimitiveType

getPrimitives() → list
getShadeModel() → ShadeModel

Returns the shade model common to all of the individual GeomPrimitives that have been added to the geom.

Return type

ShadeModel

getUsageHint() → UsageHint

Returns the minimum (i.e. most dynamic) usage_hint among all of the individual GeomPrimitives that have been added to the geom.

Deprecated: This is no longer very useful.

Return type

UsageHint

getVertexData(current_thread: Thread) → GeomVertexData

Returns a const pointer to the GeomVertexData, for application code to directly examine (but not modify) the geom’s underlying data.

Return type

GeomVertexData

insertPrimitive(i: size_t, primitive: GeomPrimitive) → None

Inserts a new GeomPrimitive structure to the Geom object. This specifies a particular subset of vertices that are used to define geometric primitives of the indicated type.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

isEmpty() → bool

Returns true if there appear to be no vertices to be rendered by this Geom, false if has some actual data.

isPrepared(prepared_objects: PreparedGraphicsObjects) → bool

Returns true if the geom has already been prepared or enqueued for preparation on the indicated GSG, false otherwise.

makeAdjacency() → Geom

Returns a new Geom with each primitive converted into a corresponding version with adjacency information.

New in version 1.10.0.

Return type

Geom

makeAdjacencyInPlace() → None

Replaces the GeomPrimitives within this Geom with corresponding versions with adjacency information. See GeomPrimitive.makeAdjacency().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

New in version 1.10.0.

makeCopy() → Geom

Returns a newly-allocated Geom that is a shallow copy of this one. It will be a different Geom pointer, but its internal data may or may not be shared with that of the original Geom.

Return type

Geom

makeLines() → Geom

Returns a new Geom with lines at all the edges. See GeomPrimitive.makeLines().

Return type

Geom

makeLinesInPlace() → None

Replaces the GeomPrimitives within this Geom with corresponding GeomLines, representing a wireframe of the primitives. See GeomPrimitive.makeLines().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

makeNonindexed(composite_only: bool) → int

Converts the geom from indexed to nonindexed by duplicating vertices as necessary. If composite_only is true, then only composite primitives such as trifans and tristrips are converted. Returns the number of GeomPrimitive objects converted.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

makePatches() → Geom

Returns a new Geom with each primitive converted into a patch. Calls decompose() first.

Return type

Geom

makePatchesInPlace() → None

Replaces the GeomPrimitives within this Geom with corresponding GeomPatches. See GeomPrimitive.makePatches().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

makePoints() → Geom

Returns a new Geom with points at all the vertices. See GeomPrimitive.makePoints().

Return type

Geom

makePointsInPlace() → None

Replaces the GeomPrimitives within this Geom with corresponding GeomPoints. See GeomPrimitive.makePoints().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

markBoundsStale() → None

Marks the bounding volume of the Geom as stale so that it should be recomputed. Usually it is not necessary to call this explicitly.

property modified

Returns a sequence number which is guaranteed to change at least every time any of the primitives in the Geom is modified, or the set of primitives is modified. However, this does not include modifications to the vertex data, which should be tested separately.

Return type

UpdateSeq

modifyPrimitive(i: size_t) → GeomPrimitive

Returns a modifiable pointer to the ith GeomPrimitive object stored within the Geom, so application code can directly manipulate the properties of this primitive.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

Return type

GeomPrimitive

modifyVertexData() → GeomVertexData

Returns a modifiable pointer to the GeomVertexData, so that application code may directly maniuplate the geom’s underlying data.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

Return type

GeomVertexData

property num_bytes

Returns the number of bytes consumed by the geom and its primitives (but not including its vertex table).

Return type

int

offsetVertices(data: GeomVertexData, offset: int) → None

Replaces a Geom’s vertex table with a new table, and simultaneously adds the indicated offset to all vertex references within the Geom’s primitives. This is intended to be used to combine multiple GeomVertexDatas from different Geoms into a single big buffer, with each Geom referencing a subset of the vertices in the buffer.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

operatorNew(size: size_t) → None
output(out: ostream) → None
prepare(prepared_objects: PreparedGraphicsObjects) → None

Indicates that the geom should be enqueued to be prepared in the indicated prepared_objects at the beginning of the next frame. This will ensure the geom is already loaded into geom memory if it is expected to be rendered soon.

Use this function instead of prepareNow() to preload geoms from a user interface standpoint.

prepareNow(prepared_objects: PreparedGraphicsObjects, gsg: GraphicsStateGuardianBase) → GeomContext

Creates a context for the geom on the particular GSG, if it does not already exist. Returns the new (or old) GeomContext. This assumes that the GraphicsStateGuardian is the currently active rendering context and that it is ready to accept new geoms. If this is not necessarily the case, you should use prepare() instead.

Normally, this is not called directly except by the GraphicsStateGuardian; a geom does not need to be explicitly prepared by the user before it may be rendered.

Return type

GeomContext

property primitive_type

Returns the fundamental primitive type that is common to all GeomPrimitives added within the Geom. All nested primitives within a particular Geom must be the same type (that is, you can mix triangles and tristrips, because they are both the same fundamental type PT_polygons, but you cannot mix triangles and points withn the same Geom).

Return type

PrimitiveType

property primitives
Getter

Returns a const pointer to the ith GeomPrimitive object stored within the Geom. Use this call only to inspect the ith object; use modifyPrimitive() or setPrimitive() if you want to modify it.

Setter

Replaces the ith GeomPrimitive object stored within the Geom with the new object.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

Return type

Sequence[ConstPointerTo_GeomPrimitive]

release(prepared_objects: PreparedGraphicsObjects) → bool

Frees the geom context only on the indicated object, if it exists there. Returns true if it was released, false if it had not been prepared.

releaseAll() → int

Frees the context allocated on all objects for which the geom has been declared. Returns the number of contexts which have been freed.

removePrimitive(i: size_t) → None

Removes the ith primitive from the list.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

requestResident() → bool

Returns true if all the primitive arrays are currently resident in memory. If this returns false, the data will be brought back into memory shortly; try again later.

This does not also test the Geom’s associated GeomVertexData. That must be tested separately.

reverse() → Geom

Reverses all of the primitives within this Geom, returning the result. See GeomPrimitive.reverse().

Return type

Geom

reverseInPlace() → None

Reverses all of the primitives within this Geom, leaving the results in place. See GeomPrimitive.reverse().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

rotate() → Geom

Rotates all of the primitives within this Geom, returning the result. See GeomPrimitive.rotate().

Return type

Geom

rotateInPlace() → None

Rotates all of the primitives within this Geom, leaving the results in place. See GeomPrimitive.rotate().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

setBounds(volume: BoundingVolume) → None

Resets the bounding volume so that it is the indicated volume. When it is explicitly set, the bounding volume will no longer be automatically computed; call clearBounds() if you would like to return the bounding volume to its default behavior.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

setBoundsType(bounds_type: BoundsType) → None

Specifies the desired type of bounding volume that will be created for this Geom. This is normally BoundingVolume::BT_default, which means to set the type according to the config variable “bounds-type”.

If this is BT_sphere or BT_box, a BoundingSphere or BoundingBox is explicitly created. If it is BT_best, a BoundingBox is created.

This affects the implicit bounding volume only. If an explicit bounding volume is set on the Geom with setBounds(), that bounding volume type is used. (This is different behavior from the similar method on PandaNode.)

setPrimitive(i: size_t, primitive: GeomPrimitive) → None

Replaces the ith GeomPrimitive object stored within the Geom with the new object.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

setUsageHint(usage_hint: UsageHint) → None

Changes the UsageHint hint for all of the primitives on this Geom to the same value. See getUsageHint().

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

setVertexData(data: GeomVertexData) → None

Replaces the Geom’s underlying vertex data table with a completely new table.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

property shade_model

Returns the shade model common to all of the individual GeomPrimitives that have been added to the geom.

Return type

ShadeModel

transformVertices(mat: LMatrix4) → None

Applies the indicated transform to all of the vertices in the Geom. If the Geom happens to share a vertex table with another Geom, this operation will duplicate the vertex table instead of breaking the other Geom; however, if multiple Geoms with shared tables are transformed by the same matrix, they will no longer share tables after the operation. Consider using the GeomTransformer if you will be applying the same transform to multiple Geoms.

unify(max_indices: int, preserve_order: bool) → Geom

Unifies all of the primitives contained within this Geom into a single (or as few as possible, within the constraints of max_indices) primitive objects. This may require decomposing the primitives if, for instance, the Geom contains both triangle strips and triangle fans.

max_indices represents the maximum number of indices that will be put in any one GeomPrimitive. If preserve_order is true, then the primitives will not be reordered during the operation, even if this results in a suboptimal result.

Return type

Geom

unifyInPlace(max_indices: int, preserve_order: bool) → None

Unifies all of the primitives contained within this Geom into a single (or as few as possible, within the constraints of max_indices) primitive objects. This may require decomposing the primitives if, for instance, the Geom contains both triangle strips and triangle fans.

max_indices represents the maximum number of indices that will be put in any one GeomPrimitive. If preserve_order is true, then the primitives will not be reordered during the operation, even if this results in a suboptimal result.

Don’t call this in a downstream thread unless you don’t mind it blowing away other changes you might have recently made in an upstream thread.

write(out: ostream, indent_level: int) → None