void display(void) { OSG::Real32 time = glutGet(GLUT_ELAPSED_TIME); updateMesh(time); // we extract the core out of the root node // as we now this is a geometry node OSG::GeometryRecPtr geo = dynamic_cast<OSG::Geometry *>(scene->getCore()); //now modify it's content // first we need a pointer to the position data field OSG::GeoPnt3fPropertyRecPtr pos = dynamic_cast<OSG::GeoPnt3fProperty *>(geo->getPositions()); //get the data field the pointer is pointing at OSG::GeoPnt3fProperty::StoredFieldType *posfield = pos->editFieldPtr(); //get some iterators OSG::GeoPnt3fProperty::StoredFieldType::iterator last, it; // set the iterator to the first data it = posfield->begin(); //now simply run over all entires in the array for (int x = 0; x < N; x++) { for (int z = 0; z < N; z++) { (*it) = OSG::Pnt3f(x, wMesh[x][z], z); it++; } } mgr->redraw(); }
//------------------------------------------------ void ofxBox2dRect::setup(b2World * b2dworld, float x, float y, float w, float h) { if(b2dworld == NULL) { ofLog(OF_LOG_NOTICE, "- must have a valid world -"); return; } w /= 2; h /= 2; width = w; height = h; b2PolygonShape shape; shape.SetAsBox(width/OFX_BOX2D_SCALE, height/OFX_BOX2D_SCALE); fixture.shape = &shape; fixture.density = density; fixture.friction = friction; fixture.restitution = bounce; //b2BodyDef bodyDef; // nm: already have one of these in our base class if (!bodyTypeSet) { if (density == 0.f) bodyDef.type = b2_staticBody; else bodyDef.type = b2_dynamicBody; } bodyDef.position.Set(x/OFX_BOX2D_SCALE, y/OFX_BOX2D_SCALE); body = b2dworld->CreateBody(&bodyDef); body->CreateFixture(&fixture); updateMesh(); alive = true; }
int VertexTreeWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QTreeWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: redraw(); break; case 1: updateMesh(); break; case 2: addEdgeBetweenFaces((*reinterpret_cast< Vertex*(*)>(_a[1]))); break; case 3: sendX((*reinterpret_cast< double(*)>(_a[1]))); break; case 4: sendY((*reinterpret_cast< double(*)>(_a[1]))); break; case 5: sendZ((*reinterpret_cast< double(*)>(_a[1]))); break; case 6: enableXYZ((*reinterpret_cast< bool(*)>(_a[1]))); break; case 7: enableRGB((*reinterpret_cast< bool(*)>(_a[1]))); break; case 8: sendVertex((*reinterpret_cast< Vertex*(*)>(_a[1]))); break; case 9: acceptMesh((*reinterpret_cast< Mesh*(*)>(_a[1]))); break; case 10: setX((*reinterpret_cast< double(*)>(_a[1]))); break; case 11: setY((*reinterpret_cast< double(*)>(_a[1]))); break; case 12: setZ((*reinterpret_cast< double(*)>(_a[1]))); break; case 13: deleteVertex(); break; case 14: addVertexToEdge(); break; case 15: addEdgeBetweenFaces(); break; case 16: activated(); break; default: ; } _id -= 17; } return _id; }
void MovingMeshFB::moveMesh() { int i, j, k, m; double epsilon = 0.2; double error = 1.; double area, h, l[3], d[3]; while (error > epsilon) { getMoveDirection(); error = 0; for (i = 0;i < n_geometry(2);i ++) { const Point<2>& x0 = point(geometry(2,i).vertex(0)); const Point<2>& x1 = point(geometry(2,i).vertex(1)); const Point<2>& x2 = point(geometry(2,i).vertex(2)); l[0] = (x2[0] - x1[0])*(x2[0] - x1[0]) + (x2[1] - x1[1])*(x2[1] - x1[1]); l[1] = (x0[0] - x2[0])*(x0[0] - x2[0]) + (x0[1] - x2[1])*(x0[1] - x2[1]); l[2] = (x1[0] - x0[0])*(x1[0] - x0[0]) + (x1[1] - x0[1])*(x1[1] - x0[1]); area = (x1[0] - x0[0])*(x2[1] - x0[1]) - (x2[0] - x0[0])*(x1[1] - x0[1]); h = 0.5*area/sqrt(*std::max_element(&l[0], &l[3])); for (k = 0;k < 3;++ k) { m = geometry(2,i).vertex(k); for (d[k] = 0.0, j = 0;j < 2;j ++) { d[k] += move_direction[m][j]*move_direction[m][j]; } } h = sqrt(*std::max_element(&d[0], &d[3]))/h; if (error < h) error = h; } std::cerr << "mesh moving error = " << error << std::endl; getMoveStepLength(); for (i = 0;i < n_move_step;i ++) { updateSolution(); updateMesh(); }; }; }
MeshEditor::MeshEditor(SharedResources *shared, Editor *editor, QWidget *parent) : QWidget(parent) { this->shared = shared; this->editor = editor; setFocusPolicy(Qt::StrongFocus); QVBoxLayout *columns = new QVBoxLayout(this); columns->setSizeConstraint(QLayout::SetMinimumSize); columns->setSpacing(0); columns->setMargin(0); QHBoxLayout *topRow = new QHBoxLayout(); topRow->setSizeConstraint(QLayout::SetMinimumSize); topRow->setSpacing(0); topRow->setMargin(0); initTopRow(topRow); columns->addLayout(topRow); meshViewer = new MeshViewer(shared, this); columns->addWidget(meshViewer); QVBoxLayout *layout = new QVBoxLayout(); layout->setMargin(10); layout->setSpacing(3); initFields(layout); columns->addLayout(layout); columns->addStretch(1); connect(this, SIGNAL(meshChanged(pg::Geometry)), meshViewer, SLOT(updateMesh(pg::Geometry))); connect(meshViewer, SIGNAL(ready()), this, SLOT(addMesh())); }
// ----------- udpate void Plant::update(){ rig.update(); updatePolylines(); updateAnimators(); updateMesh(); updateAge(); }
void display(void) { Real32 time = glutGet(GLUT_ELAPSED_TIME); updateMesh(time); // we extract the core out of the root node // as we now this is a geometry node GeometryPtr geo = GeometryPtr::dcast(scene->getChild(0)->getCore()); //now modify it's content // first we need a pointer to the position data field GeoPositions3fPtr pos = GeoPositions3fPtr::dcast(geo->getPositions()); //get the data field the pointer is pointing at GeoPositions3f::StoredFieldType *posfield = pos->getFieldPtr(); //get some iterators GeoPositions3f::StoredFieldType::iterator last, it; // set the iterator to the first data it = posfield->begin(); beginEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); //now simply run over all entires in the array for (int x = 0; x < N; x++) for (int z = 0; z < N; z++){ (*it) = Pnt3f(x, wMesh[x][z], z); it++; } endEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); mgr->redraw(); }
Foam::patchInjectionBase::patchInjectionBase ( const polyMesh& mesh, const word& patchName ) : patchName_(patchName), patchId_(mesh.boundaryMesh().findPatchID(patchName_)), patchArea_(0.0), patchNormal_(), cellOwners_(), triFace_(), triToFace_(), triCumulativeMagSf_(), sumTriMagSf_(Pstream::nProcs() + 1, 0.0) { if (patchId_ < 0) { FatalErrorInFunction << "Requested patch " << patchName_ << " not found" << nl << "Available patches are: " << mesh.boundaryMesh().names() << nl << exit(FatalError); } updateMesh(mesh); }
void reactingOneDimRPvol2::solveContinuity() { if (debug) { InfoInFunction << endl; } const scalarField mass0 = rho_*regionMesh().V(); fvScalarMatrix rhoEqn ( fvm::ddt(rho_) + fvc::div(phiPyrolysis_) == - solidChemistry_->RRg() ); if (regionMesh().moving()) { surfaceScalarField phiRhoMesh ( fvc::interpolate(rho_)*regionMesh().phi() ); rhoEqn += fvc::div(phiRhoMesh); } rhoEqn.solve(); updateMesh(mass0); }
void CtinyWingsTerrainSprite::reGenerateShape(int insertControlPointCount){ m_insertControlPointCount=insertControlPointCount; vector<CCPoint>&pointList=m_pointMat[0]; //generate controlPoints CCPoint startPoint=pointList[0]; CCPoint endPoint=pointList[(int)pointList.size()-1]; float len=endPoint.x-startPoint.x; float stepLen=len/(insertControlPointCount+1); vector<CCPoint> controlPointList; controlPointList.push_back(CCPoint(startPoint.x,m_height));//start control point for(int i=0;i<insertControlPointCount;i++){ float x=(i+1)*stepLen; float y=m_height; controlPointList.push_back(CCPoint(x,y)); } controlPointList.push_back(CCPoint(endPoint.x,m_height));//end control point. now got controlPointList //random y for each control point int nControlPoint=(int)controlPointList.size(); for(int i=0;i<nControlPoint;i++){ CCPoint&controlPoint=controlPointList[i]; float dy=(random01()*2-1)*MIN(m_height*0.8,stepLen*0.7); if(i>0&&dy*(controlPointList[i-1].y-m_height)>0){ dy=-dy; } controlPoint.y=m_height+dy; } //reshape pointList int controlPointIndex=0; int nPoint=(int)pointList.size(); for(int i=0;i<nPoint;i++){ CCPoint&point=pointList[i]; //find the first control point whose x is bigger than point.x while(controlPointIndex<(int)controlPointList.size()&&controlPointList[controlPointIndex].x<=point.x){ controlPointIndex++; } if(controlPointIndex>=(int)controlPointList.size()){//point is endPoint point=controlPointList[(int)controlPointList.size()-1]; }else{ assert(controlPointIndex>=1); CCPoint controlPoint=controlPointList[controlPointIndex-1]; CCPoint controlPointn=controlPointList[controlPointIndex]; //get point.y by sin interpolation const float dx=controlPointn.x-controlPoint.x; const float dy=controlPointn.y-controlPoint.y; point.y=controlPoint.y+dy/2*(1-cosf((M_PI/dx)*(point.x-controlPoint.x))); } int nRow=(int)m_pointMat.size(); for(int j=1;j<nRow;j++){ CCPoint&_point=m_pointMat[j][i]; _point.y=point.y*(1-pow((float)j/(nRow-1),1));//must convert j to float !!! } } //update mesh and submit updateMesh(); submit(); }
void GLReprojection::draw() { boost::mutex::scoped_lock lock(m_meshMutex); updateMesh(); CvMatSinkPol::sink(m_lorigin); m_mesh.draw(); }
void HeightField::update () { if ( !mesh ) { //meshGrid( 16, 12, 1 ); //meshGrid( 16, 12, 1 ); } updateMesh(); updateShader(); }
BulletHeightField::BulletHeightField(BulletWorld * _world, Texture * _heightMap, Shader * _shader, bool _tileUvs, glm::vec3 _scale, unsigned long int _upAxis) : BulletMeshEntity(_world, new TriMesh(true), _shader), heightMap(_heightMap), tileUvs(_tileUvs) { heightMap->incrementReferenceCount(); setColliderAsHeightMap(_heightMap, _scale, _upAxis); updateMesh(); }
void Foam::KinematicCloud<CloudType>::autoMap(const mapPolyMesh& mapper) { typedef typename particle::TrackingData<KinematicCloud<CloudType>> tdType; tdType td(*this); Cloud<parcelType>::template autoMap<tdType>(td, mapper); updateMesh(); }
void ofxVirtualCamera::update() { kinect.update(); if(kinect.isFrameNew()) { newFrame = true; updateSurface(); updateMesh(); renderCamera(); updatePixels(); } }
void update() { float abc_range = (abc.getMaxTime() - abc.getMinTime()); float t = fmodf(ofGetElapsedTimef(), abc_range) + abc.getMinTime(); abc.setTime(t); abc.get("ClonerShape", mesh); updateMesh(mesh); light0.orbit(ofGetElapsedTimef() * 10, 0, 2000); light1.orbit(ofGetElapsedTimef() * -20, 60, 2000); }
void TextDrawable::setText(const std::string& newText) { text = newText; if (text.empty()) { meshBuffer.reset(); } else { updateMesh(); } }
void Hub::MeshUpdate::updateHub (Hub& hub) { QMutexLocker _(&hub.impl->meshValuesMutex); mesh = hub.impl->meshValues[name]; _.unlock(); updateMesh(mesh); _.relock(); hub.impl->meshValues[name] = mesh; }
Foam::ReactingMultiphaseLookupTableInjection<CloudType>:: ReactingMultiphaseLookupTableInjection ( const dictionary& dict, CloudType& owner, const word& modelName ) : InjectionModel<CloudType>(dict, owner, modelName, typeName), inputFileName_(this->coeffDict().lookup("inputFile")), duration_(readScalar(this->coeffDict().lookup("duration"))), parcelsPerSecond_ ( readScalar(this->coeffDict().lookup("parcelsPerSecond")) ), injectors_ ( IOobject ( inputFileName_, owner.db().time().constant(), owner.db(), IOobject::MUST_READ, IOobject::NO_WRITE ) ), injectorCells_(0), injectorTetFaces_(0), injectorTetPts_(0) { duration_ = owner.db().time().userTimeToTime(duration_); // Set/cache the injector cells injectorCells_.setSize(injectors_.size()); injectorTetFaces_.setSize(injectors_.size()); injectorTetPts_.setSize(injectors_.size()); updateMesh(); // Determine volume of particles to inject this->volumeTotal_ = 0.0; forAll(injectors_, i) { this->volumeTotal_ += injectors_[i].mDot()/injectors_[i].rho(); } this->volumeTotal_ *= duration_; }
//recursively step trhough node hierarchy, updating meshes void updateMeshes(MODL *model, OBJ *obj, NODE *node, float parentOffset[3]) { //accumulate this node's offset to pass further on float nodeOffset[3]; for(int i=0; i<3; i++) nodeOffset[i] = parentOffset[i] + node->position[i]; //may not be needed, add the further mesh offset float meshOffset[3]; for(int i=0; i<3; i++) meshOffset[i] = nodeOffset[i] + node->pivot[i]; //if this has a mesh if(node->meshID != -1) { //if the OBJ structure has an equivalent, update the mesh MESH *mesh = model->meshes[node->meshID]; int found = 0; for(int i=0; i<obj->numGroups; i++) { GROUP *group = obj->groups[i]; //if the group name has the mesh name as a substring if(strstr(group->groupName, mesh->meshName) != NULL) { //update updateMesh(model, mesh, group, meshOffset); found = 1; //stop searching break; } } if(found == 0) fprintf(stderr, "Found no group corresponding to %s\n", mesh->meshName); } //recurse on any child nodes (if it has any) if(node->hasChildren != 0) { //just recurse on the first child, which itself will recurse on any siblings (see below) updateMeshes(model, obj, model->nodes[node->childID], nodeOffset); } //recurse on any sibling nodes (if it has any) if(node->hasSibling != 0) { //siblings share the same offset of their parents updateMeshes(model, obj, model->nodes[node->siblingID], parentOffset); } return; }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ if (key == 'c'){ for (int i = 0; i < NUM_FRAMES; i++){ fbo[i].begin(); ofClear(0,0,0,1); fbo[i].end(); } updateMesh(&mesh); } if (key == 'v'){ viewMode = (viewMode + 1) % maxViewModes; } if (key == 'm'){ mode = (mode + 1) % maxModes; } if (key == 'h'){ hideMenu = !hideMenu; } }
//-------------------------------------------------------------- void ofApp::update(){ sensel.update(); /* clear contact points */ for (unsigned int i=0; i<MAX_CONTACTS; i++){ ellipse[i].deactivate(); } /* get new contact points */ for (unsigned int i=0; i<sensel.getContacts().size(); i++) { int contactId = sensel.getContacts()[i].contactID; int x = ofMap(sensel.getContacts()[i].position.x,0,1,0,ofGetWidth()); int y = ofMap(sensel.getContacts()[i].position.y,0,1,0,ofGetHeight()); int h = sensel.getContacts()[i].majorAxis; int w = sensel.getContacts()[i].minorAxis; float f = sensel.getContacts()[i].force; int r = sensel.getContacts()[i].orientation; ofColor color; float opacity = ofMap(0.5 + atan(10*f-9)/(3.1415926535),0.0,.9,0.0,256.0,true); if (mode == 0){ color = ofColor(255, 255, 255, opacity); } else if (mode == 1){ color = ofColor(0, 0, 0, opacity); } else { return; } //string contactType = sensel.getContacts()[i].contactType; ellipse[contactId].set(x,y,w*20,h*20,r,f,color); } /* update our fbo */ if (drawingActive){ fbo[fboIndex].begin(); for (int i =0; i < MAX_CONTACTS; i++ ){ellipse[i].draw();} fbo[fboIndex].end(); } /* update mesh */ updateMesh(&mesh); fboIndex = (fboIndex + 1) % NUM_FRAMES; }
void SceneCloudView::renderScene(const cvpr_tum::TsdfVolume::TsdfVolumeConstPtr& volume, bool has_gpu) { cloud_viewer_->removeAllPointClouds(); if (has_gpu) { updateMesh(volume); cloud_viewer_->addPolygonMesh(*mesh_ptr_); } else { updateCellsCloud(volume); cloud_viewer_->addPointCloud<pcl17::PointXYZ> (current_cloud_ptr_, "current_frame_point_cloud"); } if (cam_added_) { cloud_viewer_->addPointCloud<pcl17::PointXYZ> (spheres_cloud_ptr_, "cam_poses");//addSphere(p, 0.05/*radius*/, 1.f, 0.f, 0.f, sp); cloud_viewer_->setPointCloudRenderingProperties(pcl17::visualization::PCL17_VISUALIZER_POINT_SIZE, 5, "cam_poses"); cloud_viewer_->setPointCloudRenderingProperties(pcl17::visualization::PCL17_VISUALIZER_COLOR, 1.0, 0.0, 0.0, "cam_poses"); } if (cur_view_added_) { //pcl17::visualization::PointCloudColorHandlerCustom<pcl17::PointXYZ> tgt_h (current_cloud_ptr_, 0, 255, 0); //cloud_viewer_->addPointCloud<pcl17::PointXYZ> (current_cloud_ptr_, tgt_h, "current_frame_point_cloud", vp_1); cloud_viewer_->addPointCloud<pcl17::PointXYZ> (current_cloud_ptr_, "current_frame_point_cloud"); cloud_viewer_->setPointCloudRenderingProperties(pcl17::visualization::PCL17_VISUALIZER_POINT_SIZE, 5, "current_frame_point_cloud"); cloud_viewer_->setPointCloudRenderingProperties(pcl17::visualization::PCL17_VISUALIZER_COLOR, 0.0, 0.0, 1.0, "current_frame_point_cloud"); } for(TrajectoryVisualizerMap::iterator it = trajectory_visualizers_.begin(); it != trajectory_visualizers_.end(); ++it) { it->second->updateVisualizer(cloud_viewer_); } cloud_viewer_->spinOnce(); }
void display(void) { OSG::Real32 time = glutGet(GLUT_ELAPSED_TIME); updateMesh(time); // we extract the core out of the root node // as we now this is a geometry node OSG::GeometryRecPtr geo = dynamic_cast<OSG::Geometry *>(scene->getCore()); //now modify it's content // first we need a pointer to the position data field OSG::GeoPnt3fPropertyRecPtr pos = dynamic_cast<OSG::GeoPnt3fProperty *>(geo->getPositions()); //this loop is similar to when we generted the data during createScenegraph() // here they all come for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) pos->setValue(OSG::Pnt3f(x, wMesh[x][z], z), N * x + z); mgr->redraw(); }
void SWFontRenderer::render( SWCamera* camera ) { if ( !getMesh() ) return; if ( !getMaterial() ) return; if ( !m_texture.isValid() ) return; if ( m_text.size() == 0 ) return; if ( m_textChanged ) { m_textChanged = false; updateMesh(); } SWTransform* transform = gameObject()->getComponent<SWTransform>(); const TMatrix4x4& model = transform->getWorldMatrix(); const TMatrix4x4& VPMat = camera->getVPMatrix(); SWMaterial* material = getMaterial(); material->setTexture( "TEXTURE_0", m_texture() ); material->setMatrix4x4( "MATRIX_MVP", ( model * VPMat ) ); material->apply(); getMesh()->draw(); }
triMeshT* a3dsCreateMesh(const a3dsDataT* a3ds, const string* object_name) { const a3dsObjectDataT* o = a3dsGetObjectData(a3ds, object_name); if (!o || !o->mesh) return (NULL); triMeshT* mesh = newMesh(o->mesh->num_tris*3, o->mesh->num_tris); triT* tris = meshTrisPtr (mesh); vertexT* verts = meshVertsPtr(mesh); // We separate the triangles so that none of them share the same vertices. for (int i = 0; i < o->mesh->num_tris; i++) { tris[i] = (triT) { i*3, i*3+1, i*3+2 }; int v0 = o->mesh->tris[i].v0, v1 = o->mesh->tris[i].v1, v2 = o->mesh->tris[i].v2; if (o->mesh->smoothing_groups) verts->k = o->mesh->smoothing_groups[i]; if (o->mesh->vert_uv) verts->uv = *(vec2*)&o->mesh->vert_uv[v0]; (verts++)->p = *(vec3*)&o->mesh->vert_pos[v0]; if (o->mesh->smoothing_groups) verts->k = o->mesh->smoothing_groups[i]; if (o->mesh->vert_uv) verts->uv = *(vec2*)&o->mesh->vert_uv[v1]; (verts++)->p = *(vec3*)&o->mesh->vert_pos[v1]; if (o->mesh->smoothing_groups) verts->k = o->mesh->smoothing_groups[i]; if (o->mesh->vert_uv) verts->uv = *(vec2*)&o->mesh->vert_uv[v2]; (verts++)->p = *(vec3*)&o->mesh->vert_pos[v2]; } calcSmoothNormals(mesh); updateMesh(mesh); return (mesh); }
void display(void) { Real32 time = glutGet(GLUT_ELAPSED_TIME); updateMesh(time); // we extract the core out of the root node // as we now this is a geometry node GeometryPtr geo = GeometryPtr::dcast(scene->getCore()); //now modify it's content // first we need a pointer to the position data field GeoPositions3fPtr pos = GeoPositions3fPtr::dcast(geo->getPositions()); //this loop is similar to when we generted the data during createScenegraph() beginEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); // here they all come for (int x = 0; x < N; x++) for (int z = 0; z < N; z++) pos->setValue(Pnt3f(x, wMesh[x][z], z), N*x+z); endEditCP(pos, GeoPositions3f::GeoPropDataFieldMask); mgr->redraw(); }
//-------------------------------------------------------------- void testApp::update(){ kinect.update(); updateMesh(); }
BOOL LLVOTree::updateGeometry(LLDrawable *drawable) { LLFastTimer ftm(LLFastTimer::FTM_UPDATE_TREE); if (mReferenceBuffer.isNull() || mDrawable->getFace(0)->mVertexBuffer.isNull()) { const F32 SRR3 = 0.577350269f; // sqrt(1/3) const F32 SRR2 = 0.707106781f; // sqrt(1/2) U32 i, j; U32 slices = MAX_SLICES; S32 max_indices = LEAF_INDICES; S32 max_vertices = LEAF_VERTICES; S32 lod; LLFace *face = drawable->getFace(0); face->mCenterAgent = getPositionAgent(); face->mCenterLocal = face->mCenterAgent; for (lod = 0; lod < 4; lod++) { slices = sLODSlices[lod]; sLODVertexOffset[lod] = max_vertices; sLODVertexCount[lod] = slices*slices; sLODIndexOffset[lod] = max_indices; sLODIndexCount[lod] = (slices-1)*(slices-1)*6; max_indices += sLODIndexCount[lod]; max_vertices += sLODVertexCount[lod]; } mReferenceBuffer = new LLVertexBuffer(LLDrawPoolTree::VERTEX_DATA_MASK, gSavedSettings.getBOOL("RenderAnimateTrees") ? GL_STATIC_DRAW_ARB : 0); mReferenceBuffer->allocateBuffer(max_vertices, max_indices, TRUE); LLStrider<LLVector3> vertices; LLStrider<LLVector3> normals; LLStrider<LLVector2> tex_coords; LLStrider<U16> indicesp; mReferenceBuffer->getVertexStrider(vertices); mReferenceBuffer->getNormalStrider(normals); mReferenceBuffer->getTexCoord0Strider(tex_coords); mReferenceBuffer->getIndexStrider(indicesp); S32 vertex_count = 0; S32 index_count = 0; // First leaf *(normals++) = LLVector3(-SRR2, -SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_BOTTOM); *(vertices++) = LLVector3(-0.5f*LEAF_WIDTH, 0.f, 0.f); vertex_count++; *(normals++) = LLVector3(SRR3, -SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_TOP); *(vertices++) = LLVector3(0.5f*LEAF_WIDTH, 0.f, 1.f); vertex_count++; *(normals++) = LLVector3(-SRR3, -SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_TOP); *(vertices++) = LLVector3(-0.5f*LEAF_WIDTH, 0.f, 1.f); vertex_count++; *(normals++) = LLVector3(SRR2, -SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_BOTTOM); *(vertices++) = LLVector3(0.5f*LEAF_WIDTH, 0.f, 0.f); vertex_count++; *(indicesp++) = 0; index_count++; *(indicesp++) = 1; index_count++; *(indicesp++) = 2; index_count++; *(indicesp++) = 0; index_count++; *(indicesp++) = 3; index_count++; *(indicesp++) = 1; index_count++; // Same leaf, inverse winding/normals *(normals++) = LLVector3(-SRR2, SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_BOTTOM); *(vertices++) = LLVector3(-0.5f*LEAF_WIDTH, 0.f, 0.f); vertex_count++; *(normals++) = LLVector3(SRR3, SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_TOP); *(vertices++) = LLVector3(0.5f*LEAF_WIDTH, 0.f, 1.f); vertex_count++; *(normals++) = LLVector3(-SRR3, SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_TOP); *(vertices++) = LLVector3(-0.5f*LEAF_WIDTH, 0.f, 1.f); vertex_count++; *(normals++) = LLVector3(SRR2, SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_BOTTOM); *(vertices++) = LLVector3(0.5f*LEAF_WIDTH, 0.f, 0.f); vertex_count++; *(indicesp++) = 4; index_count++; *(indicesp++) = 6; index_count++; *(indicesp++) = 5; index_count++; *(indicesp++) = 4; index_count++; *(indicesp++) = 5; index_count++; *(indicesp++) = 7; index_count++; // next leaf *(normals++) = LLVector3(SRR2, -SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_BOTTOM); *(vertices++) = LLVector3(0.f, -0.5f*LEAF_WIDTH, 0.f); vertex_count++; *(normals++) = LLVector3(SRR3, SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_TOP); *(vertices++) = LLVector3(0.f, 0.5f*LEAF_WIDTH, 1.f); vertex_count++; *(normals++) = LLVector3(SRR3, -SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_TOP); *(vertices++) = LLVector3(0.f, -0.5f*LEAF_WIDTH, 1.f); vertex_count++; *(normals++) = LLVector3(SRR2, SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_BOTTOM); *(vertices++) = LLVector3(0.f, 0.5f*LEAF_WIDTH, 0.f); vertex_count++; *(indicesp++) = 8; index_count++; *(indicesp++) = 9; index_count++; *(indicesp++) = 10; index_count++; *(indicesp++) = 8; index_count++; *(indicesp++) = 11; index_count++; *(indicesp++) = 9; index_count++; // other side of same leaf *(normals++) = LLVector3(-SRR2, -SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_BOTTOM); *(vertices++) = LLVector3(0.f, -0.5f*LEAF_WIDTH, 0.f); vertex_count++; *(normals++) = LLVector3(-SRR3, SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_TOP); *(vertices++) = LLVector3(0.f, 0.5f*LEAF_WIDTH, 1.f); vertex_count++; *(normals++) = LLVector3(-SRR3, -SRR3, SRR3); *(tex_coords++) = LLVector2(LEAF_LEFT, LEAF_TOP); *(vertices++) = LLVector3(0.f, -0.5f*LEAF_WIDTH, 1.f); vertex_count++; *(normals++) = LLVector3(-SRR2, SRR2, 0.f); *(tex_coords++) = LLVector2(LEAF_RIGHT, LEAF_BOTTOM); *(vertices++) = LLVector3(0.f, 0.5f*LEAF_WIDTH, 0.f); vertex_count++; *(indicesp++) = 12; index_count++; *(indicesp++) = 14; index_count++; *(indicesp++) = 13; index_count++; *(indicesp++) = 12; index_count++; *(indicesp++) = 13; index_count++; *(indicesp++) = 15; index_count++; // Generate geometry for the cylinders // Different LOD's // Generate the vertices // Generate the indices for (lod = 0; lod < 4; lod++) { slices = sLODSlices[lod]; F32 base_radius = 0.65f; F32 top_radius = base_radius * sSpeciesTable[mSpecies]->mTaper; //llinfos << "Species " << ((U32) mSpecies) << ", taper = " << sSpeciesTable[mSpecies].mTaper << llendl; //llinfos << "Droop " << mDroop << ", branchlength: " << mBranchLength << llendl; F32 angle = 0; F32 angle_inc = 360.f/(slices-1); F32 z = 0.f; F32 z_inc = 1.f; if (slices > 3) { z_inc = 1.f/(slices - 3); } F32 radius = base_radius; F32 x1,y1; F32 noise_scale = sSpeciesTable[mSpecies]->mNoiseMag; LLVector3 nvec; const F32 cap_nudge = 0.1f; // Height to 'peak' the caps on top/bottom of branch const S32 fractal_depth = 5; F32 nvec_scale = 1.f * sSpeciesTable[mSpecies]->mNoiseScale; F32 nvec_scalez = 4.f * sSpeciesTable[mSpecies]->mNoiseScale; F32 tex_z_repeat = sSpeciesTable[mSpecies]->mRepeatTrunkZ; F32 start_radius; F32 nangle = 0; F32 height = 1.f; F32 r0; for (i = 0; i < slices; i++) { if (i == 0) { z = - cap_nudge; r0 = 0.0; } else if (i == (slices - 1)) { z = 1.f + cap_nudge;//((i - 2) * z_inc) + cap_nudge; r0 = 0.0; } else { z = (i - 1) * z_inc; r0 = base_radius + (top_radius - base_radius)*z; } for (j = 0; j < slices; j++) { if (slices - 1 == j) { angle = 0.f; } else { angle = j*angle_inc; } nangle = angle; x1 = cos(angle * DEG_TO_RAD); y1 = sin(angle * DEG_TO_RAD); LLVector2 tc; // This isn't totally accurate. Should compute based on slope as well. start_radius = r0 * (1.f + 1.2f*fabs(z - 0.66f*height)/height); nvec.set( cos(nangle * DEG_TO_RAD)*start_radius*nvec_scale, sin(nangle * DEG_TO_RAD)*start_radius*nvec_scale, z*nvec_scalez); // First and last slice at 0 radius (to bring in top/bottom of structure) radius = start_radius + turbulence3((F32*)&nvec.mV, (F32)fractal_depth)*noise_scale; if (slices - 1 == j) { // Not 0.5 for slight slop factor to avoid edges on leaves tc = LLVector2(0.490f, (1.f - z/2.f)*tex_z_repeat); } else { tc = LLVector2((angle/360.f)*0.5f, (1.f - z/2.f)*tex_z_repeat); } *(vertices++) = LLVector3(x1*radius, y1*radius, z); *(normals++) = LLVector3(x1, y1, 0.f); *(tex_coords++) = tc; vertex_count++; } } for (i = 0; i < (slices - 1); i++) { for (j = 0; j < (slices - 1); j++) { S32 x1_offset = j+1; if ((j+1) == slices) { x1_offset = 0; } // Generate the matching quads *(indicesp) = j + (i*slices) + sLODVertexOffset[lod]; llassert(*(indicesp) < (U32)max_vertices); indicesp++; index_count++; *(indicesp) = x1_offset + ((i+1)*slices) + sLODVertexOffset[lod]; llassert(*(indicesp) < (U32)max_vertices); indicesp++; index_count++; *(indicesp) = j + ((i+1)*slices) + sLODVertexOffset[lod]; llassert(*(indicesp) < (U32)max_vertices); indicesp++; index_count++; *(indicesp) = j + (i*slices) + sLODVertexOffset[lod]; llassert(*(indicesp) < (U32)max_vertices); indicesp++; index_count++; *(indicesp) = x1_offset + (i*slices) + sLODVertexOffset[lod]; llassert(*(indicesp) < (U32)max_vertices); indicesp++; index_count++; *(indicesp) = x1_offset + ((i+1)*slices) + sLODVertexOffset[lod]; llassert(*(indicesp) < (U32)max_vertices); indicesp++; index_count++; } } slices /= 2; } mReferenceBuffer->setBuffer(0); llassert(vertex_count == max_vertices); llassert(index_count == max_indices); } if (gLLWindEnabled || gSavedSettings.getBOOL("RenderAnimateTrees")) { mDrawable->getFace(0)->mVertexBuffer = mReferenceBuffer; } else { //generate tree mesh updateMesh(); } return TRUE; }
void clippingNode::customDraw(){ updateMesh(); //ofNode's transformation mesh.drawWireframe(); }