示例#1
0
bool writeMeshContainerInCache(drn_writer_t * cache,
	DRNTDagNode & node,
	drn_scene::MeshContainer * meshContainer,
	drn_scene::MeshDynamicDataContainer * dynContainers,
	unsigned int frameCount, MeshExportMode mode)
{
	int32_t status;
	status = drn_writer_add_chunk(cache, dynContainers, frameCount * sizeof (drn_scene::MeshDynamicDataContainer));
	meshContainer->dynamicData = drn_writer_get_last_chunk_id(cache);
	status = drn_writer_add_chunk(cache, meshContainer, sizeof(drn_scene::MeshContainer));
	node.container = drn_writer_get_last_chunk_id(cache);
	status = drn_writer_add_chunk(cache, node.dagPath.fullPathName().asChar(), node.dagPath.fullPathName().length() + 1);
	node.fullPath = drn_writer_get_last_chunk_id(cache);
	return status;
}
示例#2
0
bool writeMeshStaticDataInCache(drn_writer_t * cache,
	DRNTDagNode & node,
	drn_scene::MeshContainer * meshContainer,
	DRNTHardEdge & he, MeshExportMode mode)
{
	uint32_t drnStatus = 0;
	MStatus status;
	MFnMesh mesh(node.dagPath);

	if (mode == MESH_EXPORT_FULL_TOPOLOGY)
	{
		meshContainer->numPolygons = mesh.numPolygons(&status);
		meshContainer->numVertices = mesh.numVertices(&status);
		meshContainer->numNormals = mesh.numNormals(&status);
	}
	else
	{
		meshContainer->numPolygons = 0;
		meshContainer->numVertices = 0;
		meshContainer->numNormals = 0;
	}

	MIntArray vertexCount;
	MIntArray vertexList;
	MIntArray normalCount;
	MIntArray normalList;
	MIntArray uvCounts;
	MIntArray uvIds;
	mesh.getAssignedUVs(uvCounts, uvIds);
	MIntArray triangleCount;
	MIntArray triangleList;
	MIntArray triangleNList;
	MIntArray triangleUVList;
	mesh.getVertices(vertexCount, vertexList);
	mesh.getNormalIds(normalCount, normalList);
	mesh.getTriangles(triangleCount, triangleList);
	triangleNList.setLength(triangleList.length());
	triangleUVList.setLength(triangleList.length());
	meshContainer->numTriangles = triangleList.length()  / 3;
	int * vcarray = new int[vertexCount.length()];
	int * vlarray = new int[vertexList.length()];
	int * ncarray = new int[normalCount.length()];
	int * nlarray = new int[normalList.length()];
	// Triangulation
	int poly_idx_offset = 0;
	int tri_idx_offset = 0;
	for (int i = 0; i < mesh.numPolygons(); ++i)
	{
		for (int j = 0; j < triangleCount[i]; ++j)
		{
			for(unsigned int k=0; k < 3; ++k)
			{
				int v_idx = triangleList[tri_idx_offset+j*3 + k];
				int match = -1;
				int l = 0;
				while (match < 0 && l < vertexCount[i])
				{
					if (vertexList[poly_idx_offset+l] == v_idx)
					match = l;
					++l;
				}
				triangleNList[tri_idx_offset+j*3 + k] = normalList[poly_idx_offset+match];
				int id = 0;
				if (uvIds.length() != 0)
				mesh.getPolygonUVid(i, match, id);
				triangleUVList[tri_idx_offset+j*3 + k] = id;
			}
		}
		poly_idx_offset += vertexCount[i];
		tri_idx_offset += 3 * triangleCount[i];
	}
	he.tlist.resize(triangleList.length(), -1);
	//he.itlist.resize(triangleList.length());
	he.itlist.resize(triangleList.length());
	//std::map<std::pair<int, int>, int> h;
	std::map<triplet, int> h;
	int idx = 0;
	for (int i = 0, n = triangleList.length(); i != n; ++i)
	{
		//std::pair<int, int> p = std::make_pair(triangleList[i], triangleNList[i]);
		triplet p(triangleList[i], triangleNList[i], triangleUVList[i]);
		//std::map<std::pair<int, int>, int>::const_iterator match = h.find(p);
		std::map<triplet, int>::const_iterator match = h.find(p);
		if (match != h.end())
		{
			he.tlist[i] = match->second;
			he.itlist[i] = match->first;
		}
		else
		{
			h[p] = idx;
			he.tlist[i] = idx;
			he.itlist[i] = p;
			++idx;
		}
	}
	meshContainer->numHwVertices = he.idmax = idx;
	if (mode == MESH_EXPORT_FULL_TOPOLOGY)
	{
		vertexCount.get(vcarray);
		vertexList.get(vlarray);
		normalCount.get(ncarray);
		normalList.get(nlarray);
		drnStatus = drn_writer_add_chunk(cache, vcarray, sizeof(int) * vertexCount.length());
		meshContainer->vertexCountPerFace = drn_writer_get_last_chunk_id(cache);
		drnStatus = drn_writer_add_chunk(cache, vlarray, sizeof(int) * vertexList.length());
		meshContainer->vertexListPerFace = drn_writer_get_last_chunk_id(cache);
		drnStatus = drn_writer_add_chunk(cache, ncarray, sizeof(int) * normalCount.length());
		meshContainer->normalCountPerFace = drn_writer_get_last_chunk_id(cache);
		drnStatus = drn_writer_add_chunk(cache, nlarray, sizeof(int) * normalList.length());
		meshContainer->normalListPerFace = drn_writer_get_last_chunk_id(cache);
		drnStatus = drn_writer_add_chunk(cache, & (he.tlist[0]), sizeof(int) * he.tlist.size());
		meshContainer->triangleList = drn_writer_get_last_chunk_id(cache);
		delete[] vcarray;
		delete[] vlarray;
		delete[] ncarray;
		delete[] nlarray;
	}
	else
	{
		meshContainer->numUVSets = 0;
		drnStatus = drn_writer_add_chunk(cache, & (he.tlist[0]), sizeof(int) * he.tlist.size());
		meshContainer->triangleList = drn_writer_get_last_chunk_id(cache);
		meshContainer->defaultUVSet = 0;
	}
	DRNT_DBG_LVL2(std::cout << "trianglelist" << triangleList << std::endl;);
示例#3
0
int32_t drn_close_writer(drn_writer_t *cache)
{
    drn_header_container_t header;
    drn_map_container_t * maps = (drn_map_container_t *) ALLOCATE(sbcount(cache->maps) * sizeof(drn_map_container_t));
    uint64_t m_idx;
    uint64_t i;
    size_t bytes;

    for (m_idx=0; m_idx < sbcount(cache->maps); ++m_idx)
    {
        drn_writer_map_t * map = cache->maps + m_idx;
        drn_hash_cell_t * hash_map = (drn_hash_cell_t *) ALLOCATE(DRN_HASH_MAP_SIZE * sizeof (drn_hash_cell_t));
        uint64_t hc_idx;
        uint64_t chunk_count = 0;
        uint64_t values_size = 0;
        drn_writer_key_t * key_array = map->keys;
        uint64_t k_idx;
        drn_hash_desc_t * descriptors;
        char * values_string_array;
        uint32_t desc_offset_cntr;
        uint32_t value_strings_offset_cntr;

        for (hc_idx = 0; hc_idx < DRN_HASH_MAP_SIZE; ++hc_idx)
        {
            hash_map[hc_idx].offset = 0;
            hash_map[hc_idx].count = 0;
        }
        /* count Es + sum VV lengths */
        for (k_idx = 0; k_idx < sbcount(map->keys); ++k_idx)
        {
            drn_writer_key_t * value = map->keys + k_idx;
            chunk_count += sbcount(value->descriptors);
            values_size += strlen(value->value)+1;
        }
        /* Allocate Es */
        descriptors = (drn_hash_desc_t*) ALLOCATE((size_t) chunk_count * sizeof(drn_hash_desc_t));
        /* Allocate Vv */
        values_string_array = (char *) ALLOCATE((size_t) values_size * sizeof(char));
        /* Sort Vs */
        qsort(key_array, sbcount(map->keys), sizeof(drn_writer_key_t), drn_val_hash_cmp);
        /* For each V */
        desc_offset_cntr = 0;
        value_strings_offset_cntr = 0;
        for (k_idx = 0; k_idx < sbcount(map->keys); ++k_idx)
        {
            uint32_t hash = drn_oat_hash(key_array[k_idx].value, (uint32_t) strlen(key_array[k_idx].value))%DRN_HASH_MAP_SIZE;
            uint64_t * chunk_ids = key_array[k_idx].descriptors;
            uint64_t d_idx;

            /* Fill H */
            hash_map[hash].offset = desc_offset_cntr;
            hash_map[hash].count = sbcount(key_array[k_idx].descriptors);
            /* Fill Vv */
            memcpy(values_string_array + value_strings_offset_cntr, key_array[k_idx].value, strlen(key_array[k_idx].value)+1);
            /*  fill E */
            qsort(chunk_ids, sbcount(key_array[k_idx].descriptors), sizeof(uint64_t), drn_uint64_cmp);
            for (d_idx = 0; d_idx < sbcount(key_array[k_idx].descriptors); ++d_idx)
            {
                descriptors[desc_offset_cntr].chunk_id = chunk_ids[d_idx];
                descriptors[desc_offset_cntr].key_value_offset = value_strings_offset_cntr;
                ++desc_offset_cntr;
            }
            /* Increment offsets */
            value_strings_offset_cntr += (uint32_t) strlen(key_array[k_idx].value)+1;
        }
        /*  Write hash array as desc */
        drn_writer_add_chunk(cache, hash_map, sizeof(drn_hash_cell_t) * DRN_HASH_MAP_SIZE);
        maps[m_idx].hash_chunk_id = drn_writer_get_last_chunk_id(cache);
        /*  Write hash name as desc */
        drn_writer_add_chunk(cache, map->name, strlen(map->name) + 1);
        maps[m_idx].name_chunk_id = drn_writer_get_last_chunk_id(cache);
        /*  Write value string array as desc */
        drn_writer_add_chunk(cache, descriptors, sizeof(drn_hash_desc_t) * chunk_count);
        maps[m_idx].descriptors_chunk_id = drn_writer_get_last_chunk_id(cache);
        /*  Write desc array as desc */
        drn_writer_add_chunk(cache, values_string_array, values_size);
        maps[m_idx].value_strings_chunk_id = drn_writer_get_last_chunk_id(cache);
        FREE(hash_map);
        FREE(descriptors);
        FREE(values_string_array);
    }
    drn_writer_add_chunk(cache, maps, sizeof(drn_map_container_t) * sbcount(cache->maps));
    FREE(maps);
    header.version = cache->version;
    memcpy(header.description, cache->description, 256);
    header.index_offset = cache->desc_start_offset + cache->desc_end_offset;
    header.chunk_count = cache->chunk_count;
    header.maps_chunk_id = drn_writer_get_last_chunk_id(cache);
    LSEEK(cache->fd, 0L, SEEK_SET);
    bytes = WRITE(cache->fd, &header, sizeof(drn_header_container_t));
    if (bytes !=  sizeof(drn_header_container_t))
        return -1;
    LSEEK(cache->fd, cache->desc_start_offset + cache->desc_end_offset, SEEK_SET);
    bytes = WRITE(cache->fd, cache->descriptors, WRITE_COUNT_CAST (sizeof(drn_desc_t) * cache->chunk_count));
    if (bytes !=  sizeof(drn_desc_t) * cache->chunk_count)
        return -1;
    if (CLOSE(cache->fd) == -1)
        return -1;
    for (i = 0; i < sbcount(cache->maps); ++i)
    {
        drn_writer_map_t * map = cache->maps + i;
        uint64_t j;
        for (j = 0; j < sbcount(map->keys); ++j)
        {
            drn_writer_key_t * value = map->keys + j;
            sbfree(value->descriptors);
            FREE(value->value);
        }
        sbfree(map->keys);
        FREE(map->name);
    }
    sbfree(cache->maps);
    sbfree(cache->descriptors);
    return 0;
}