Logo   Home Table of Contents    News  Dev Blogs  Gallery  Timeline  Legend  Tags  Sponsors 
Join us on... 
Banner

Current: Month Day, Year

9.1.3 Code of obj3d/object3d.py

obj3d/object3d provides all common global elements and functions to work with 3d objects (meshes). The file contains only one class:

Class object3d

This class is used to work with 3d objects (meshes). Methods are used for loading, setting materials, hiding vertices, triangularization etc.

Variables

namedescription
glob reference to globalObjects
env reference to environment (class programInfo)
eqtype Equipment-type, like "teeth".
openGL Reference to openGL functions.
filename filename of the loaded object.
name object name used in Makehuman.
npGrpNames ordered list of groupnames numpy format.
prim number of primitives (triangles).
n_origverts number of vertices after loading
n_verts number of vertices
n_faces number of faces
n_fuvs number of uv-faces
n_groups number of groups
z_depth z_depth used for sorting 3d objects.
coord list of positions of vertices, array of float32 for openGL.
uvs list of coordinates for uvs.
fverts list of vertices per face, [verts, 3] array of uint32 for openGL >. 2.
n_fverts number of vertices for openGL.
loadedgroups contains the group after loading from file (also for hidden geometry).
group list of references to group per face.
overflow list of vertices or double used vertices [source, dest].
gl_coord list of flattened gl-Buffer (these are coordinates to be changed by program).
gl_coord_o list of unchanged positions
gl_coord_w list of unchanged positions (working mode with targets) and for posing.
gl_coord_mn list of coordinates to work with macro buffers, (all changes except the macros).
gl_coord_mm list of coordinates to work with macro buffers, (all changes of the macros).
gl_uvcoord list of flattened gluv-Buffer.
gl_norm list of flattended normal buffer.
n_glnorm number of normals for openGL.
gl_icoord list of openGL-Drawarray Index.
gl_hicoord list of openGL-Drawarray used when parts are hidden.
min_index list of 3 elements containing the index number for lowest value in each direction.
max_index list of 3 elements containing the index number for highest value in each direction.
minpose_index list of 3 elements containing the index number for lowest value in each direction in pose-mode.
maxpose_index list of 3 elements containing the index number for highest value in each direction in pose-mode.
material reference to material.
visible contains visible groups for baseinfo, otherwise None.
is_base boolean set to true in case of basemesh.

Methods:

nameparametersreturnsdescription
load path
use_obj (boolean)
success (boolean)
text
loads an object using importObjFromFile. Intializes material.
setZDepth z_depthNone Setter for z-depth.
initMaterial filename or NoneNone Uses self.filename if filename is None and creates a material for the object.
listAllMaterials Nonelist of materials calls materials.listAllMaterials() with filename and return list, returns empty list if no material is available.
getMaterialPath filenamematerialpath Uses material.class function to get an existent path. Returns None when not successful.
loadMaterial pathnamesuccess (boolean) Load a material witm material.loadMatFile and return success (True also when no material is available)
newMaterial pathnameNone free an old material if existent (freeTextures) and call material.loadMatFile
getMaterialFilename Nonefilename returns the current material filename or None
exportBinary NoneNone calculates binary filename from self.filename and calls exportObj3dBinary
setName nameNone If name is None it creates generic_type. This function is the setter for name.
setGroupNames list of namesNone packs the group names to fit for numpy arrays. (sets npGrpNames and n_groups)
getOpenGLIndex Nonegindex returns either gl_hicoord or gl_icoord as index depending on hidden vertices.
notHidden NoneNone set gl_hicoord to None to mark no hidden vertices.
createGLVertPos pos
uvs
overflow
orig
None creates self.coord from pos and self.uvs from uvs and sets numberes values, also sets overflow.
overflowCorrection overflow bufferNone handle overflow buffer after main mesh is corrected.
calcNormals Nonevalid (boolean) calculates face-normals and then vertex normals. Returns if geometry is valid (invalid: normal vector cannot be calculated)
calcFaceBufSize mask
overrideignore (boolean)
numind
numfaces
create buffersizes for vertsperface, faceverts buffer. The mask calculates if faces are used. overrideignore: normaly used when the helper as invisible group should also be considered. Returns number of indices and faces.
highestVisibleVert Nonehighest vertex Checks all visible groups and returns highest visible vertex number. Also works for assets without extra groups (usually this is used to figure out, where the helper begins for bone reduction).
fillFaceBuffers vertsperface
faceverts
mask
overrideignore
highest fill vertsperface, faceverts buffer. vertsperface is the buffer to put the vertices per face, faceverts is the buffer for the face vertex numbers. mask calculates if faces are used and overrideignore is used when the helper as invisible group should also be considered. returns highest vertex number.
unUsedVerts faceindmask creates a table of used vertices (the elements are set to one) like a mask.
shortenOverflow mappingnewoberflow buffer shortens the overflow table leaving out the non-mapped elements.
getVisGeometry displayhidden (boolean)
helper (boolean)
coord
norm
gl_uvcoord
vertsperface
faceverts
overflow
mapping
return flattened vectors with coordinates, norms, uvcoords, vertex-per-face, faces and overflow. All values are deduplicated, this function is used for exports.
createGLFaces nfaces
ufaces
prim
groups
boolean Creates fverts, gl_icoord, gl_coord, gl_coord_o (gl_coord_w for base) and gl_uvcoord. Then calculates normals. Also sets loadedgroups, prim, n_faces, n_fuvs and group and n_fverts
getPosition numx, y, z values get position of vertex num based on gl_coord
getMeanPosition arrx, y, z list used for skeleton mainly, mean postion of an array, based on gl_coord
resetMesh NoneNone get back the copy from gl_coord_o
createWCopy NoneNone create the working copy gl_coord_w
resetFromCopy NoneNone reset form gl_coord from gl_coord_w
hideVertices vertsNone calculate new index gl_hicoord from gl_icoord
hideApproxVertices asset
base
verts
None hide vertices (recalulate gl_hicoord) by testing reference verts
hiddenMask Nonemask returns a mask what should be hidden or None if nothing should be deleted.
createMapping maskmapping
fill
creates a mapping index reduced by hidden coords, also returns highest value
optimizeHiddenMesh bweightsgl_index
gl_coord
gl_uvcoord
gl_norm
nweights
overflow
mapping
duplicate the mesh for effective saving without hidden vertices, used e.g. for glTF, returns all necessary values. None if nothing is hidden
getInitialCopyForSlider factor
targetlower
targetupper
None called when starting work with one slider, a copy without the value of this slider is created. So this target is substracted. The proportial part of the slider is than added to the initial copy.
updateByTarget factor
targetlower
targetupper
None updates the mesh when slider is moved. Not used for macro targets.
setTarget factor
targetlower
targetupper
None updates from file (all done on basemesh directly, no overflow correction)
resetToNonMacroTargets NoneNone reset to original mesh + add all changes of non-macrotargets, preparation to deal with macro targets. result is in self.gl_coord_mn
prepareMacroBuffer NoneNone copy original mesh + add all changes of non-macrotargets. It uses gl_coord_mn and sets gl_coord_mm to zero.
addTargetToMacroBuffer factor
target
None add target to gl_coord_mm
addMacroBuffer NoneNone after changing a macro it will be added make sure to write in same buffer (out will avoid to get a new one)
approxToBasemesh asset
base
None updates the mesh, barycentric approximation (assets). Uses weights and offsets from mhclo file and bases gl_coord.
precalculateApproxInRestPose asset
base
None calls approxToBasemesh and copies values to gl_coord_w
_getMinMaxValues coordmin
max
calculate numbers of vertices, which are on the outside for later use do that only for visible groups. In case of an empty object None is returned.
precalculateDimension NoneNone sets min_index and max_index with the help of _getMinMaxValues
precalculatePosedDimension NoneNone sets minpose_index, maxpose_index with the help of _getMinMaxValues for posed position.
boundingBox NoneAx
Ay
Az
Bx
By
Bz
calculate bounding box of an object. sets self.min_index and self.max_index, can be None in case of empty object even after precalculation. and returns Ax, Ay, Az, Bx, By, Bz, if none it returns all values set to 0.0.
getCenterWidth Nonecenter width returns value center (width), 0.0 if min_index is None.
getCenterHeight Nonecenter height returns value center (height), 0.0 if min_index is None.
getCenterDepth Nonecenter depth returns value center (depth), 0.0 if min_index is None.
getCenter Nonelist of center width, height, depth returns value center (widht, height, depth).
getLowestPos posed (boolean)lowest value Used for floor calculation. returns lowest value either in pose mode or standard mode.
setNoPose NoneNone set minpose_index, maxpose_index to None.
getHeightInUnits NoneNone returns height in units (0.0 if min_index is None)
getMeasure vindex (list)measure
coords
create a measurement, results in an array of vertices for presentation and the result (length). Length is simply calculated by distances. The coords are filled with the coordinates and measure contains total distance.
calculateAttachedGeom facesattachedFaces
attachedEdges
borderneighbour
get a dictionary of attached facenumbers and edgenumbers per vertex for borders, get the next border neighbours (used in loop subdivision)