//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- PrimitiveSetIndexedUInt::PrimitiveSetIndexedUInt(PrimitiveType primitiveType, UIntArray* indices) : PrimitiveSet(primitiveType), m_minIndex(0), m_maxIndex(0) { setIndices(indices); }
Heightmap::Heightmap(int columns, int rows) { setColumns(columns); setRows(rows); vector<vec3> vertices; vector<unsigned int> indices; vector<vec2> texcoords; for(int z = 0; z <= rows; z++) { for(int x = 0; x <= columns; x++) { vertices.push_back(vec3(x*(1.0f/columns), 0, z*(1.0f/rows))); texcoords.push_back(vec2(x*0.5f, z*0.5f)); } } for(int row = 0; row < rows; row++) { for(int column = 0; column < columns; column++) { indices.push_back(column + row * (columns + 1)); indices.push_back(column + (row + 1) * (columns + 1)); indices.push_back(column + 1 + row * (columns + 1)); indices.push_back(column + 1 + row * (columns + 1)); indices.push_back(column + (row + 1) * (columns + 1)); indices.push_back(column + 1 + (row + 1) * (columns + 1)); } } setVertices(vertices); setIndices(indices); setTexcoords(texcoords); material.setSpecularReflectance(0.05f); material.setShininess(1.0f); material.setAmbientReflectance(0.5f); init(); calculateNormals(); }
KDbRelationship::KDbRelationship(KDbIndexSchema* masterIndex, KDbIndexSchema* detailsIndex) : m_masterIndex(0) , m_detailsIndex(0) , m_masterIndexOwned(false) , m_detailsIndexOwned(false) { (void)setIndices(masterIndex, detailsIndex); }
/** * \brief Constructor. * \param[in] adapter Visitor holding bearing vector correspondences etc. * \param[in] indices A vector of indices to be used from all available * correspondences. */ TranslationOnlySacProblem( adapter_t & adapter, const std::vector<int> & indices) : SampleConsensusProblem<model_t> (), _adapter(adapter) { setIndices(indices); };
/** * \brief Constructor. * \param[in] adapter Visitor holding bearing vector correspondences etc. * \param[in] indices A vector of multi-indices to be used from all available * correspondences. * \param[in] asCentral Solve problem with only one camera? */ MultiNoncentralRelativePoseSacProblem( adapter_t & adapter, const std::vector<std::vector<int> > & indices, bool asCentral = false) : MultiSampleConsensusProblem<model_t> (), _adapter(adapter), _asCentral(asCentral) { setIndices(indices); };
void NarfDescriptor::setRangeImage (const RangeImage* range_image, const std::vector<int>* indices) { range_image_ = range_image; if (indices != NULL) { IndicesPtr indicesptr (new std::vector<int> (*indices)); setIndices (indicesptr); } }
/** * \brief Constructor. * \param[in] adapter Visitor holding bearing vector correspondences etc. * \param[in] indices A vector of multi-indices to be used from all available * correspondences. * \param[in] sampleSize The number of samples for each "sub"-hypothesis. */ MultiCentralRelativePoseSacProblem( adapter_t & adapter, const std::vector<std::vector<int> > & indices, int sampleSize) : MultiSampleConsensusProblem<model_t> (), _adapter(adapter), _sampleSize(sampleSize) { setIndices(indices); };
/** * \brief Constructor. * \param[in] adapter Visitor holding bearing vectors, world points, etc. * \param[in] algorithm The algorithm we want to use. * \param[in] indices A vector of indices to be used from all available * correspondences. * \param[in] randomSeed Whether to seed the random number generator with * the current time. */ AbsolutePoseSacProblem( adapter_t & adapter, algorithm_t algorithm, const std::vector<int> & indices, bool randomSeed = true) : sac::SampleConsensusProblem<model_t> (randomSeed), _adapter(adapter), _algorithm(algorithm) { setIndices(indices); };
/** * \brief Constructor. * \param[in] adapter Visitor holding bearing vector correspondences etc. * \param[in] sampleSize Number of correspondences used for generating hypotheses. * \param[in] indices A vector of indices to be used from all available * correspondences. * \param[in] randomSeed Whether to seed the random number generator with * the current time. */ EigensolverSacProblem( adapter_t & adapter, size_t sampleSize, const std::vector<int> & indices, bool randomSeed = true) : sac::SampleConsensusProblem<model_t> (randomSeed), _adapter(adapter), _sampleSize(sampleSize) { setIndices(indices); };
/** * \brief Constructor. * \param[in] adapter Visitor holding bearing vector correspondences etc. * \param[in] algorithm The algorithm to use * \param[in] indices A vector of indices to be used from all available * correspondences. * \param[in] asCentral Solve problem with only one camera? */ NoncentralRelativePoseSacProblem( adapter_t & adapter, algorithm_t algorithm, const std::vector<int> & indices, bool asCentral = false ) : SampleConsensusProblem<model_t> (), _adapter(adapter), _algorithm(algorithm), _asCentral(asCentral) { setIndices(indices); };
STDMETHODIMP CVisComplexObj::put_indices(VARIANT newVal) { double *data; if (VariantToDoubleArray(&data, &newVal)) return E_INVALIDARG; if (data) { int len = GetLength(data); for (int i=0; i<len; ++i) ((unsigned int *)data)[i] = (unsigned int)data[i]; } setIndices(data); return S_OK; }
void CPUSideTriangleMesh::generatePhongNormals() { assert( haveFaceNormals() && haveSmoothingGroups() && "Mesh should have smoothing groups - use generateSmoothingGroups"); // vertex normals math::vector_of_vector3f normals(attributeArrays[0].count); // vertex normals indices std::vector<unsigned> indices(indicesArrays[0].indices.get(), indicesArrays[0].indices.get() + indicesArrays[0].count); // vertex smoothing groups std::vector<int> vertexSMGroup(attributeArrays[0].count, -1); // average normals against faces sharing same smoothing group for (size_t iFace = 0; iFace < faceNormals.size(); ++iFace) { for (size_t iVertInd = iFace * 3; iVertInd < iFace * 3 + 3; ++iVertInd) { unsigned iVert = indices[iVertInd]; if (vertexSMGroup[iVert] == -1) { vertexSMGroup[iVert] = get_first_nonzero_bit(smoothingGroups[iFace]); normals[iVert] = faceNormals[iFace]; } else if ( (smoothingGroups[iFace] != 0) && (smoothingGroups[iFace] & (1 << (vertexSMGroup[iVert] - 1))) ) { normals[iVert] += faceNormals[iFace]; } else { indices[iVertInd] = normals.size(); normals.push_back(faceNormals[iFace]); vertexSMGroup.push_back( get_first_nonzero_bit(smoothingGroups[iFace]) ); } } } // normalize all for (size_t i = 0; i<normals.size(); ++i) { normals[i] = math::normalize(normals[i]); } // find attribute slot for normals int normalAttrIndex = getAttributeIndex("normal"); if (normalAttrIndex == -1) { normalAttrIndex = getFreeAttributeIndex(); } assert(normalAttrIndex != -1 && "No free slot for normals"); // setup normals setAttributes("normal", normalAttrIndex, 3, normals.size(), sgl::FLOAT, &normals[0]); setIndices(normalAttrIndex, indices.size(), &indices[0]); }
CubeGeometry::CubeGeometry(): Geometry() { setAttribute("Position", std::vector<float> { -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f }); setIndices(std::vector<GLushort> { 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 6, 3, 6, 7, 0, 3, 7, 0, 7, 4, 4, 5, 7, 5, 7, 6, 0, 1, 2, 0, 2, 3 }); setAttribute("Color", std::vector<float> { 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }); uploadAll(); }
void test(int testCaseCount){ int count; int endIndex; int startIndex; for (count = 0; count < testCaseCount; ++count){ startIndex = 0; endIndex = 0; setIndices(tests[count].numbers, tests[count].length, &startIndex, &endIndex); if (tests[count].startIndex == startIndex && tests[count].endIndex == endIndex) printf("\nPass"); else printf("\nFail"); } }
deliberation::Draw createDraw() { auto program = context().createProgram({ deliberation::dataPath("Data/Examples/BasicSceneExample.vert"), deliberation::dataPath("Data/Examples/BasicSceneExample.frag") }); deliberation::UVSphere sphere(7, 7); auto mesh = sphere.generateMesh(); deliberation::MeshCompiler compiler; auto compilation = compiler.compile(mesh); auto draw = context().createDraw(program, gl::GL_TRIANGLES); draw.addVertices(compilation.vertices); draw.setIndices(compilation.indices); return draw; }
int TriangleMeshData::setDataProperty(int property, void const* value, int numElements) { if (property == NUM_VERTICES) { return setNumVertices(*((unsigned int const*) value)); } else if (property == NUM_INDICES) { return setNumIndices(*((unsigned int const*) value)); } else if (property == X_COORDINATES) { setDataX((double const*) value, numElements); } else if (property == Y_COORDINATES) { setDataY((double const*) value, numElements); } else if (property == Z_COORDINATES) { setDataZ((double const*) value, numElements); } else if (property == COORDINATES) { setVertices((double const*) value, numElements); } else if (property == INDICES) { setIndices((unsigned int const*) value, numElements); } else if (property == VALUES) { setValues((double const*) value, numElements); } else { return Data3D::setDataProperty(property, value, numElements); } return 1; }
/** * Initialize mapper for the given network and the current mode. Create global * arrays that contain offsets that will be used to create vector from the * network component objects * @param network network that will generate vector */ GenVectorMap(boost::shared_ptr<_network> network) : p_network(network) { p_Offsets = NULL; p_timer = NULL; //p_timer = gridpack::utility::CoarseTimer::instance(); p_GAgrp = network->communicator().getGroup(); p_me = GA_Pgroup_nodeid(p_GAgrp); p_nNodes = GA_Pgroup_nnodes(p_GAgrp); p_Offsets = new int[p_nNodes]; p_nBuses = p_network->numBuses(); p_nBranches = p_network->numBranches(); getDimensions(); setOffsets(); setIndices(); GA_Pgroup_sync(p_GAgrp); }
/* ChapelArray.chpl:32 */ _domain_1_SingleLocaleArithmeticDomain_1_int32_t_0 _build_domain(range_int32_t_bounded_0* const _e0_ranges, int32_t _ln, _string _fn) { range_int32_t_bounded_0 T1; _tuple_1_range_int32_t_bounded_0 T2; _domain_1_SingleLocaleArithmeticDomain_1_int32_t_0 T8; //SingleLocaleDistribution T3 = NULL; _domain_1_SingleLocaleArithmeticDomain_1_int32_t_0 T6; _domain_1_SingleLocaleArithmeticDomain_1_int32_t_0 T4; SingleLocaleArithmeticDomain_1_int32_t_0 T5 = NULL; _domain_1_SingleLocaleArithmeticDomain_1_int32_t_0 T7; T1 = _copy(&((*_e0_ranges))); T2.x1 = T1; //T3 = (SingleLocaleDistribution)chpl_alloc(sizeof(_SingleLocaleDistribution), "instance of class _unknown", _ln, _fn); //((object)T3)->_cid = _e_SingleLocaleDistribution; //_construct_SingleLocaleDistribution(T3, _ln, _fn); T4._value = nil; T5 = ((SingleLocaleArithmeticDomain_1_int32_t_0)(nil)); T4._value = T5; T6 = _construct__domain(1, T5, _ln, _fn); T7 = T6; setIndices(&(T7), &(T2)); T8 = T6; return T8; }
JNIEXPORT jintArray JNICALL Java_mpi_Request_testSome( JNIEnv *env, jclass clazz, jlongArray requests) { int incount = (*env)->GetArrayLength(env, requests); jlong* jReq; MPI_Request *cReq; ompi_java_getPtrArray(env, requests, &jReq, (void***)&cReq); int *indices = (int*)calloc(incount, sizeof(int)); int outcount; int rc = MPI_Testsome(incount, cReq, &outcount, indices, MPI_STATUSES_IGNORE); ompi_java_exceptionCheck(env, rc); ompi_java_releasePtrArray(env, requests, jReq, (void**)cReq); jintArray jindices = NULL; if(outcount != MPI_UNDEFINED) { jindices = (*env)->NewIntArray(env, outcount); setIndices(env, jindices, indices, outcount); } free(indices); return jindices; }
SpriteGeometry::SpriteGeometry(): Geometry() { setAttribute("Position", std::vector<float> { -0.5f, 0.5f, 0.f, 0.5, 0.5f, 0.f, 0.5f, -0.5f, 0.f, -0.5f, -0.5f, 0.f }); setIndices(std::vector<GLushort> { 0, 2, 1, 0, 3, 2 }); setAttribute("Color", std::vector<float> { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); setAttribute("Texture", std::vector<float> { 0, 0, 1, 0, 1, 1, 0, 1 }); // setAttribute("Normal", std::vector<float> { // 0.f, 0.f, 1.f, // 0.f, 0.f, 1.f, // 0.f, 0.f, 1.f, // 0.f, 0.f, 1.f // }); uploadAll(); }
void ReconstructorBase::loadModel (QString path) { clear(); Assimp::Importer importer; const aiScene* scene = importer.ReadFile(path.toStdString(), aiProcess_GenNormals | aiProcess_JoinIdenticalVertices | aiProcess_Triangulate); if(!scene) { qDebug()<<"Nie można otworzyć pliku z modelem: "; return; } aiMesh *mesh = scene->mMeshes[0]; setData(mesh); setIndices(mesh); emit modelChanged(data, indices); qDebug()<<"ReconstructorBase::loadModel::" "Załadowano model z pliku: "+path; }
bool KDbRelationship::setIndices(KDbIndexSchema* masterIndex, KDbIndexSchema* detailsIndex) { return setIndices(masterIndex, detailsIndex, true); }
void MorphGeometry::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); //Do not respond to changes that have a Sync origin if(origin & ChangedOrigin::Sync) { return; } if(whichField & BaseGeometryFieldMask) { if(getBaseGeometry() != NULL) { if(getBaseGeometry()->getTypes() != NULL) { GeoIntegralPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoIntegralProperty>(getBaseGeometry()->getTypes()->clone()); setTypes(Prop); } if(getBaseGeometry()->getLengths() != NULL) { GeoIntegralPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoIntegralProperty>(getBaseGeometry()->getLengths()->clone()); setLengths(Prop); } if(getBaseGeometry()->getIndices() != NULL) { GeoIntegralPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoIntegralProperty>(getBaseGeometry()->getIndices()->clone()); setIndices(Prop); } for(UInt16 i(0) ; i<Geometry::LastIndex ; ++i) { if(getBaseGeometry()->getProperty(i) != NULL) { GeoVectorPropertyUnrecPtr Prop = dynamic_pointer_cast<GeoVectorProperty>(getBaseGeometry()->getProperty(i)->clone()); setProperty(Prop, i); } else { setProperty(NULL, i); } } setMaterial(getBaseGeometry()->getMaterial()); } else { setTypes(NULL); setLengths(NULL); for(UInt16 i(0) ; i<Geometry::LastIndex ; ++i) { setProperty(NULL, i); } setIndices(NULL); setMaterial(NULL); } } if((whichField & InternalWeightsFieldMask) || (whichField & InternalTargetGeometriesFieldMask) || (whichField & BaseGeometryFieldMask) || (whichField & MorphPropertiesFieldMask)) { updateMorph(); } }
void KDbRelationship::createIndices(KDbQuerySchema *query, KDbField *field1, KDbField *field2) { if (!field1 || !field2 || !query) { kdbWarning() << "!masterField || !detailsField || !query"; return; } if (field1->isQueryAsterisk() || field2->isQueryAsterisk()) { kdbWarning() << "relationship's fields cannot be asterisks"; return; } if (field1->table() == field2->table()) { kdbWarning() << "fields cannot belong to the same table"; return; } if (!query->contains(field1->table()) || !query->contains(field2->table())) { kdbWarning() << "fields do not belong to this query"; return; } //! @todo: check more things: -types //! @todo: find existing global db relationships KDbField *masterField = 0, *detailsField = 0; bool p1 = field1->isPrimaryKey(), p2 = field2->isPrimaryKey(); if (p1 && p2) { //2 primary keys masterField = field1; m_masterIndex = masterField->table()->primaryKey(); detailsField = field2; m_detailsIndex = detailsField->table()->primaryKey(); } else if (!p1 && p2) { //foreign + primary: swap KDbField *tmp = field1; field1 = field2; field2 = tmp; p1 = !p1; p2 = !p2; } if (p1 && !p2) { //primary + foreign masterField = field1; m_masterIndex = masterField->table()->primaryKey(); detailsField = field2; //create foreign key //@todo: check if it already exists m_detailsIndex = new KDbIndexSchema; detailsField->table()->addIndex(m_detailsIndex); m_detailsIndexOwned = true; const bool ok = m_detailsIndex->addField(detailsField); Q_ASSERT(ok); m_detailsIndex->setForeignKey(true); } else if (!p1 && !p2) { masterField = field1; m_masterIndex = new KDbIndexSchema; masterField->table()->addIndex(m_masterIndex); m_masterIndexOwned = true; bool ok = m_masterIndex->addField(masterField); Q_ASSERT(ok); m_masterIndex->setForeignKey(true); detailsField = field2; m_detailsIndex = new KDbIndexSchema; detailsField->table()->addIndex(m_detailsIndex); m_detailsIndexOwned = true; ok = m_detailsIndex->addField(detailsField); Q_ASSERT(ok); m_detailsIndex->setForeignKey(true); } if (!m_masterIndex || !m_detailsIndex) return; //failed (void)setIndices(m_masterIndex, m_detailsIndex, false); }
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); //Do not respond to changes that have a Sync origin if(origin & ChangedOrigin::Sync) { return; } if((whichField & BaseGeometryFieldMask) && getBaseGeometry() != NULL) { if(getBaseGeometry()->getTypes() != NULL) { setTypes(getBaseGeometry()->getTypes()); } if(getBaseGeometry()->getLengths() != NULL) { setLengths(getBaseGeometry()->getLengths()); } if(getBaseGeometry()->getPositions() != NULL) { GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone()); setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos)); } if(getBaseGeometry()->getNormals() != NULL) { GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone()); setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm)); } if(getBaseGeometry()->getColors() != NULL) { setColors(getBaseGeometry()->getColors()); } if(getBaseGeometry()->getSecondaryColors() != NULL) { setSecondaryColors(getBaseGeometry()->getSecondaryColors()); } if(getBaseGeometry()->getTexCoords() != NULL) { setTexCoords(getBaseGeometry()->getTexCoords()); } if(getBaseGeometry()->getTexCoords1() != NULL) { setTexCoords1(getBaseGeometry()->getTexCoords1()); } if(getBaseGeometry()->getTexCoords2() != NULL) { setTexCoords2(getBaseGeometry()->getTexCoords2()); } if(getBaseGeometry()->getTexCoords3() != NULL) { setTexCoords3(getBaseGeometry()->getTexCoords3()); } if(getBaseGeometry()->getTexCoords4() != NULL) { setTexCoords4(getBaseGeometry()->getTexCoords4()); } if(getBaseGeometry()->getTexCoords5() != NULL) { setTexCoords5(getBaseGeometry()->getTexCoords5()); } if(getBaseGeometry()->getTexCoords6() != NULL) { setTexCoords6(getBaseGeometry()->getTexCoords6()); } if(getBaseGeometry()->getTexCoords7() != NULL) { setTexCoords7(getBaseGeometry()->getTexCoords7()); } if(getBaseGeometry()->getIndices() != NULL) { setIndices(getBaseGeometry()->getIndices()); } setMaterial(getBaseGeometry()->getMaterial()); } if(whichField & InternalJointsFieldMask) { _JointPoseTransforms.resize(getNumJoints()); } if( (whichField & BaseGeometryFieldMask) || (whichField & InternalJointsFieldMask) || (whichField & InternalWeightIndexesFieldMask) || (whichField & InternalWeightsFieldMask) || (whichField & BindTransformationFieldMask)) { if(getNumJoints() > 0) { _JointPoseTransforms.resize(getNumJoints()); calculatePositions(); } } }
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if((whichField & BaseGeometryFieldMask) && getBaseGeometry() != NULL) { if(getBaseGeometry()->getTypes() != NULL) { setTypes(getBaseGeometry()->getTypes()); } if(getBaseGeometry()->getLengths() != NULL) { setLengths(getBaseGeometry()->getLengths()); } if(getBaseGeometry()->getPositions() != NULL) { GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone()); setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos)); } if(getBaseGeometry()->getNormals() != NULL) { GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone()); setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm)); } if(getBaseGeometry()->getColors() != NULL) { setColors(getBaseGeometry()->getColors()); } if(getBaseGeometry()->getSecondaryColors() != NULL) { setSecondaryColors(getBaseGeometry()->getSecondaryColors()); } if(getBaseGeometry()->getTexCoords() != NULL) { setTexCoords(getBaseGeometry()->getTexCoords()); } if(getBaseGeometry()->getTexCoords1() != NULL) { setTexCoords1(getBaseGeometry()->getTexCoords1()); } if(getBaseGeometry()->getTexCoords2() != NULL) { setTexCoords2(getBaseGeometry()->getTexCoords2()); } if(getBaseGeometry()->getTexCoords3() != NULL) { setTexCoords3(getBaseGeometry()->getTexCoords3()); } if(getBaseGeometry()->getTexCoords4() != NULL) { setTexCoords4(getBaseGeometry()->getTexCoords4()); } if(getBaseGeometry()->getTexCoords5() != NULL) { setTexCoords5(getBaseGeometry()->getTexCoords5()); } if(getBaseGeometry()->getTexCoords6() != NULL) { setTexCoords6(getBaseGeometry()->getTexCoords6()); } if(getBaseGeometry()->getTexCoords7() != NULL) { setTexCoords7(getBaseGeometry()->getTexCoords7()); } if(getBaseGeometry()->getIndices() != NULL) { setIndices(getBaseGeometry()->getIndices()); } setMaterial(getBaseGeometry()->getMaterial()); } if((whichField & JointsFieldMask) || (whichField & PositionIndexesFieldMask) || (whichField & BlendAmountsFieldMask)) { calculatePositions(); } if(whichField & SkeletonsFieldMask) { for(std::vector<EventConnection>::iterator Itor(_SkeletonListenerConnections.begin()) ; Itor != _SkeletonListenerConnections.end() ; ++Itor) { Itor->disconnect(); } _SkeletonListenerConnections.clear(); for(UInt32 i(0) ; i<getMFSkeletons()->size() ; ++i) { _SkeletonListenerConnections.push_back(getSkeletons(i)->addSkeletonListener(this)); } } }
void SkeletonBlendedGeometry::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if((whichField & BaseGeometryFieldMask) && getBaseGeometry() != NULL) { if(getBaseGeometry()->getTypes() != NULL) { setTypes(getBaseGeometry()->getTypes()); } if(getBaseGeometry()->getLengths() != NULL) { setLengths(getBaseGeometry()->getLengths()); } if(getBaseGeometry()->getPositions() != NULL) { GeoPropertyUnrecPtr Pos(getBaseGeometry()->getPositions()->clone()); setPositions(dynamic_pointer_cast<GeoVectorProperty>(Pos)); } if(getBaseGeometry()->getNormals() != NULL) { GeoPropertyUnrecPtr Norm(getBaseGeometry()->getNormals()->clone()); setNormals(dynamic_pointer_cast<GeoVectorProperty>(Norm)); } if(getBaseGeometry()->getColors() != NULL) { setColors(getBaseGeometry()->getColors()); } if(getBaseGeometry()->getSecondaryColors() != NULL) { setSecondaryColors(getBaseGeometry()->getSecondaryColors()); } if(getBaseGeometry()->getTexCoords() != NULL) { setTexCoords(getBaseGeometry()->getTexCoords()); } if(getBaseGeometry()->getTexCoords1() != NULL) { setTexCoords1(getBaseGeometry()->getTexCoords1()); } if(getBaseGeometry()->getTexCoords2() != NULL) { setTexCoords2(getBaseGeometry()->getTexCoords2()); } if(getBaseGeometry()->getTexCoords3() != NULL) { setTexCoords3(getBaseGeometry()->getTexCoords3()); } if(getBaseGeometry()->getTexCoords4() != NULL) { setTexCoords4(getBaseGeometry()->getTexCoords4()); } if(getBaseGeometry()->getTexCoords5() != NULL) { setTexCoords5(getBaseGeometry()->getTexCoords5()); } if(getBaseGeometry()->getTexCoords6() != NULL) { setTexCoords6(getBaseGeometry()->getTexCoords6()); } if(getBaseGeometry()->getTexCoords7() != NULL) { setTexCoords7(getBaseGeometry()->getTexCoords7()); } if(getBaseGeometry()->getIndices() != NULL) { setIndices(getBaseGeometry()->getIndices()); } setMaterial(getBaseGeometry()->getMaterial()); } if( (whichField & InternalJointsFieldMask) || (whichField & InternalWeightIndexesFieldMask) || (whichField & InternalWeightsFieldMask)) { calculatePositions(); } }
void ModelAM::loadModel (const char* filename) { FILE *file; int r, i, j; int version = 0; int mesh_num = 0; int vertex_num = 0; int uv_num = 0; int triangle_num = 0; int temp = 0; int material_num = 0; float specular_level, glossiness; char mesh_name[32]; float box; float *vertices = NULL; float *uvs = NULL; short *indices = NULL; printf ("loadModel %s.\n", filename); file = fopen (filename, "r"); if (file == NULL) return; r = fscanf (file, "SimpleMeshFormat %d\n", &version); printf ("verson = %d.\n", version); r = fscanf (file, "%d\n", &mesh_num); printf ("mesh_num = %d.\n", mesh_num); setMeshCount (mesh_num); for (i = 0; i < mesh_num; i++) { r = fscanf (file, "%s\n", mesh_name); printf ("mesh_name = %s.\n", mesh_name); r = fscanf (file, "%d\n", &vertex_num); printf ("vertex_num = %d.\n", vertex_num); vertices = (float*)malloc (vertex_num * 3 * sizeof (float)); if (!vertices) { //Fixme: free sth if needed. return; } for (j = 0; j < vertex_num; j++) { r = fscanf (file, "%g %g %g\n", &vertices[j*3], &vertices[j*3+1], &vertices[j*3+2]); } setVertices (vertices, vertex_num * 3 * sizeof (float), i); FREEANDNULL (vertices); r = fscanf (file, "%d\n", &uv_num); uvs = (float*)malloc (uv_num * 2 * sizeof (float)); if (!uvs) { //Fixme: free sth if needed. return; } for (j = 0; j < uv_num; j++) { r = fscanf (file, "%g %g\n", &uvs[j*2], &uvs[j*2+1]); } setUvs(uvs, uv_num * 2 * sizeof (float), i); FREEANDNULL (uvs); r = fscanf (file, "%d\n", &triangle_num); printf ("triangle_num = %d.\n", triangle_num); setTriangleNums(triangle_num, i); indices = (short *)malloc (triangle_num * 3 * sizeof (short)); if (!indices) { //Fixme: free sth if needed. return; } for (j = 0; j < triangle_num; j++) { r = fscanf (file, "%d %hd %hd %hd %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n", &temp, //nSmoothGroup &indices[j*3], &indices[j*3+1], &indices[j*3+2], &box, &box, &box, &box, &box, &box, &box, &box, &box, &box, &box, &box, &box, &box, &box); } setIndices (indices, triangle_num * 3 * sizeof (short), i); FREEANDNULL (indices); // setMaterialAmbient (0.9, 0.6, 0.6, 0); // setMaterialDiffuse (0.9, 0.6, 0.6, 0); float ambient [3]; float diffuse [3]; float specular [3]; float emission [3]; float shininess; r = fscanf (file, "%d\n", &material_num); //_M3D_PRINTF ("material_num = %d.\n", material_num); //FIXME: handle only one material //Basicly, diffuse decide mesh color in white light r = fscanf (file, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g\n", &specular_level, &glossiness, &ambient[0], &ambient[1], &ambient[2], &diffuse[0], &diffuse[1], &diffuse[2], &specular[0], &specular[1], &specular[2], &emission[0], &emission[1], &emission[2]); if (specular_level > 0) shininess = glossiness; else shininess = -1; /* _M3D_PRINTF ("loadAmModel: %g %g %g %g %g %g %g %g %g %g\n", shininess, ambient[0], ambient[1], ambient[2], diffuse[0], diffuse[1], diffuse[2], specular[0], specular[1], specular[2]); } */ setMaterialAmbient (ambient[0], ambient[1], ambient[2], i); setMaterialDiffuse (diffuse[0], diffuse[1], diffuse[2], i); setMaterialEmission (emission[0], emission[1], emission[2], i); if (shininess > 0) { setMaterialShininess (shininess, i); setMaterialSpecular (specular[0], specular[1], specular[2], i); } } fclose (file); return; }