Esempio n. 1
0
RemoteInformation deserializeDataSourceData( const ::zeq::Event& event )
{
    if( event.getType() != EVENT_DATASOURCE_DATA )
        return RemoteInformation();

    auto data = GetVolumeInformation( event.getData( ));
    RemoteInformation info;
    livre::VolumeInformation& vi = info.second;

    info.first.low() = data->eventLow();
    info.first.high() = data->eventHigh();
    vi.isBigEndian = data->isBigEndian();
    vi.compCount = data->compCount();
    vi.dataType = DataType( data->dataType( ));
    vi.overlap = _deserializeVector3< unsigned >( data->overlap( ));
    vi.maximumBlockSize = _deserializeVector3< unsigned >(
                                 data->maximumBlockSize( ));
    vi.minPos = _deserializeVector3< float >( data->minPos( ));
    vi.maxPos = _deserializeVector3< float >( data->maxPos( ));
    vi.voxels = _deserializeVector3< unsigned >( data->voxels( ));
    vi.worldSize = _deserializeVector3< float >( data->worldSize( ));
    vi.boundingBox.getMin() = _deserializeVector3< float >(
                                     data->boundingBoxMin( ));
    vi.boundingBox.getMax() = _deserializeVector3< float >(
                                     data->boundingBoxMax( ));
    vi.worldSpacePerVoxel = data->worldSpacePerVoxel();

    const Vector3ui& blockSize = vi.maximumBlockSize - vi.overlap * 2;
    Vector3ui blocksSize = vi.voxels / blockSize;
    blocksSize = blocksSize / ( 1u << data->depth( ));

    vi.rootNode = RootNode( data->depth(), blocksSize );
    return info;
}
ParticleSkinnedModel::ParticleSkinnedModel(Shader& pShader, Body * body, Material ** mat, unsigned int materialCount) :
Model(body, mat, materialCount)
{
	assert(body);

	const std::vector<Body::sTriangle> tris = m_body->getTriangleData();
	std::set<Body::sConnection> uniqueConnections;

	// add unique line connections given by triangles
	for(size_t i=0; i<body->getTriangleCount(); ++i)
	{
		uniqueConnections.insert(Body::sConnection(tris[i].index[0], tris[i].index[1]));
		uniqueConnections.insert(Body::sConnection(tris[i].index[0], tris[i].index[2]));
		uniqueConnections.insert(Body::sConnection(tris[i].index[1], tris[i].index[2]));
	}

	for(std::set<Body::sConnection>::const_iterator it = uniqueConnections.begin(); it != uniqueConnections.end(); ++it)
		m_constraints.push_back(*it);

	printf("Unique connections: %zu \n", m_constraints.size());

	// Find vertices that share the same positions
	// These must be merged after the constraints update
	// Or else the seems will show
	const float limit = 1.0e-9;
	const std::vector<Body::sVertex> verts = m_body->getVertexData();
	for(size_t i=0; i<body->getVertexCount()-1; ++i)
	{
		for(size_t j=i+1; j<body->getVertexCount(); ++j)
		{
			glm::vec3 v = verts[i].position - verts[j].position;
			if(glm::dot(v,v) < limit)
				m_postVertexMerge.push_back(Body::sConnection(i,j));
		}
	}

	printf("Post vertex merge size: %u \n", m_postVertexMerge.size());

    size_t particleCount = body->getVertexCount();
	m_particles.resize(particleCount);

	glm::vec3 boundingBoxMin(1.0e20f);
	glm::vec3 boundingBoxMax(-1.0e20f);
    for(size_t i=0; i<particleCount; ++i)
    {
        const Body::sVertex v = body->getVertexData()[i];
        sParticle& p 	= m_particles[i];
        p.position 		= v.position;
		p.oldPosition 	= p.position;
		p.mass_k_d 		= getParticleMass_K_D(i);

		boundingBoxMin = glm::min(boundingBoxMin, v.position);
		boundingBoxMax = glm::max(boundingBoxMax, v.position);
    }
	boundingBoxMin = boundingBoxMax - boundingBoxMin;
	printf("%f, %f, %f\n", boundingBoxMin.x, boundingBoxMin.y, boundingBoxMin.z);

	m_ps = new GPUParticleSystem(&m_particles[0], particleCount, pShader);
	assert(m_ps);

	m_particleBuffer.bind();
	glBufferData(GL_ARRAY_BUFFER, particleCount * sizeof(sParticle), &m_particles[0], GL_STREAM_DRAW);
	m_particleBuffer.unbind();

	int positionAttr	= pShader.getAttribLocation("in_vertexPosition");
	int weightAttr 		= pShader.getAttribLocation("in_vertexWeight");

	printf("positionAttr %i\n",	positionAttr);
	printf("weightAttr %i\n",	weightAttr);

	const char * pOffset = 0;

	// Append Vertex Attribute pointers to the particle systems VAOs
	glBindVertexArray(m_ps->getSourceVA());

		glBindBuffer(GL_ARRAY_BUFFER, body->getVertexBuffer());

		glEnableVertexAttribArray(positionAttr);
		glEnableVertexAttribArray(weightAttr);

		glVertexAttribPointer(positionAttr, 3, GL_FLOAT, GL_FALSE, 	sizeof(Body::sVertex), pOffset);
		glVertexAttribPointer(weightAttr,	4, Body::VertexWeight::getGLType(), GL_FALSE, 	sizeof(Body::sVertex), 32 + pOffset);

	glBindVertexArray(0);

	glBindVertexArray(m_ps->getTargetVA());

		glBindBuffer(GL_ARRAY_BUFFER, body->getVertexBuffer());

		glEnableVertexAttribArray(positionAttr);
		glEnableVertexAttribArray(weightAttr);

		glVertexAttribPointer(positionAttr, 3, GL_FLOAT, GL_FALSE, 	sizeof(Body::sVertex), pOffset);
		glVertexAttribPointer(weightAttr,	4, Body::VertexWeight::getGLType(), GL_FALSE, 	sizeof(Body::sVertex), 32 + pOffset);

	glBindVertexArray(0);
}