Пример #1
0
void	MD5Node::DebugDrawJointTransforms(float size, bool worldSpace) {
	//Temporary VAO and VBO
	unsigned int skeletonArray;
	unsigned int skeletonBuffer;
	unsigned int skeletonColourBuffer;

	glGenVertexArrays(1, &skeletonArray);
	glGenBuffers(1, &skeletonBuffer);
	glGenBuffers(1, &skeletonColourBuffer);
	//Temporary chunk of memory to keep our joint positions in

	int numVerts = currentSkeleton.numJoints * 6;

	Vector3*	 skeletonVertices = new Vector3[numVerts];
	Vector4*	 skeletonColours = new Vector4[numVerts];


	for (int i = 0; i < currentSkeleton.numJoints; ++i) {
		Matrix4 transform = (worldSpace ? currentSkeleton.joints[i].transform : currentSkeleton.joints[i].localTransform);

		Vector3 start = transform.GetPositionVector();
		transform.SetPositionVector(Vector3(0, 0, 0));

		Vector4 endX = transform * Vector4(1, 0, 0, 1);
		Vector4 endY = transform * Vector4(0, 1, 0, 1);
		Vector4 endZ = transform * Vector4(0, 0, 1, 1);

		skeletonVertices[(i * 6) + 0] = currentSkeleton.joints[i].transform.GetPositionVector();
		skeletonVertices[(i * 6) + 1] = currentSkeleton.joints[i].transform.GetPositionVector() + (endX.ToVector3() * size);

		skeletonVertices[(i * 6) + 2] = currentSkeleton.joints[i].transform.GetPositionVector();
		skeletonVertices[(i * 6) + 3] = currentSkeleton.joints[i].transform.GetPositionVector() + (endY.ToVector3() * size);

		skeletonVertices[(i * 6) + 4] = currentSkeleton.joints[i].transform.GetPositionVector();
		skeletonVertices[(i * 6) + 5] = currentSkeleton.joints[i].transform.GetPositionVector() + (endZ.ToVector3() * size);


		skeletonColours[(i * 6) + 0] = Vector4(1, 0, 0, 1);
		skeletonColours[(i * 6) + 1] = Vector4(1, 0, 0, 1);

		skeletonColours[(i * 6) + 2] = Vector4(0, 1, 0, 1);
		skeletonColours[(i * 6) + 3] = Vector4(0, 1, 0, 1);

		skeletonColours[(i * 6) + 4] = Vector4(0, 0, 1, 1);
		skeletonColours[(i * 6) + 5] = Vector4(0, 0, 1, 1);
	}

	//You should know what this all does by now, except we combine it with the draw operations in a single function
	glBindVertexArray(skeletonArray);
	glBindBuffer(GL_ARRAY_BUFFER, skeletonBuffer);
	glBufferData(GL_ARRAY_BUFFER, currentSkeleton.numJoints*sizeof(Vector3) * 6, skeletonVertices, GL_STREAM_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(0);

	glBindBuffer(GL_ARRAY_BUFFER, skeletonColourBuffer);
	glBufferData(GL_ARRAY_BUFFER, currentSkeleton.numJoints*sizeof(Vector4) * 6, skeletonColours, GL_STREAM_DRAW);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(1);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, 0);

	glLineWidth(2.0f);
	glDrawArrays(GL_LINES, 0, currentSkeleton.numJoints * 6);	// draw Bones
	glLineWidth(1.0f);

	glBindVertexArray(0);

	//Delete the VBO and VAO, and the heap memory we allocated earlier
	glDeleteVertexArrays(1, &skeletonArray);
	glDeleteBuffers(1, &skeletonBuffer);
	glDeleteBuffers(1, &skeletonColourBuffer);

	delete[]skeletonVertices;
	delete[]skeletonColours;
}
Пример #2
0
Vector4 Vector4::xwzw() const  { return Vector4	   (x, w, z, w); }
Пример #3
0
Vector4 Vector4::xwww() const  { return Vector4	   (x, w, w, w); }
Пример #4
0
Vector4 Vector4::zwww() const  { return Vector4	   (z, w, w, w); }
Пример #5
0
Vector4 Vector4::xyww() const  { return Vector4	   (x, y, w, w); }
Пример #6
0
Vector4 Vector4::xzww() const  { return Vector4	   (x, z, w, w); }
Пример #7
0
Vector4 Vector4::yyzw() const  { return Vector4	   (y, y, z, w); }
Пример #8
0
Vector4 Vector4::yxww() const  { return Vector4	   (y, x, w, w); }
Пример #9
0
Vector4 Vector4::wxzw() const  { return Vector4	   (w, x, z, w); }
Пример #10
0
Vector4 Vector4::xyzw() const  { return Vector4	   (x, y, z, w); }
Пример #11
0
Vector4 Vector4::zxzw() const  { return Vector4	   (z, x, z, w); }
Пример #12
0
Vector4 Vector4::yxzw() const  { return Vector4	   (y, x, z, w); }
Пример #13
0
Vector4 Vector4::xxzw() const  { return Vector4	   (x, x, z, w); }
Пример #14
0
Vector4 Vector4::zwyw() const  { return Vector4	   (z, w, y, w); }
Пример #15
0
Vector4 Vector4::zyzw() const  { return Vector4	   (z, y, z, w); }
Пример #16
0
Vector4 Vector4::zwzw() const  { return Vector4	   (z, w, z, w); }
Пример #17
0
Vector4 Vector4::wyzw() const  { return Vector4	   (w, y, z, w); }
Пример #18
0
Vector4 Vector4::zxww() const  { return Vector4	   (z, x, w, w); }
Пример #19
0
Vector4 Vector4::xzzw() const  { return Vector4	   (x, z, z, w); }
Пример #20
0
Vector4 Vector4::zyww() const  { return Vector4	   (z, y, w, w); }
Пример #21
0
Vector4 Vector4::yzzw() const  { return Vector4	   (y, z, z, w); }
Пример #22
0
Vector4 Vector4::yzww() const  { return Vector4	   (y, z, w, w); }
Пример #23
0
Vector4 Vector4::zzzw() const  { return Vector4	   (z, z, z, w); }
Пример #24
0
Vector4 Vector4::ywww() const  { return Vector4	   (y, w, w, w); }
Пример #25
0
Vector4 Vector4::wzzw() const  { return Vector4	   (w, z, z, w); }
Пример #26
0
Vector4 Vector4::wwww() const  { return Vector4	   (w, w, w, w); }
Пример #27
0
Vector4 Vector4::ywzw() const  { return Vector4	   (y, w, z, w); }
Пример #28
0
Vector4 Deserializer::ReadVector4()
{
    float data[4];
    Read(data, sizeof data);
    return Vector4(data);
}
Пример #29
0
Vector4 Vector4::ywyw() const  { return Vector4	   (y, w, y, w); }
Пример #30
-1
DTerr	ImporterGeometryTWM::import(GeometryResource *target, std::string args)
{
	FilePath pathname(target->path());
	
    // open the file
    BinaryFileStream	file;
	FileManager::open(file, pathname, true);
     
    // 
	// Read_ in header
	//
	
	DTuint magic;
	file >> magic;
    if (magic != MAGIC) {
        return DT3_ERR_FILE_WRONG_TYPE;
    }
	
	DTuint version;
	file >> version;
	
	//
	// Read_ in data
	//
	
	_normals_count = 0;
	_uv_set_0_count = 0;
	_uv_set_1_count = 0;
	_weights_count = 0;
	
	DTint section,size;
	file >> section >> size;
	switch(section) {
		case FILE:		read_file(file, size);			break;
		default:		WARNINGMSG("Invalid section");	break;
	};
	
	//
	// Build Streams
	//
    
	// Calculate sizes needed
	DTuint joints_size = 0;
	
	for (DTuint i = 0; i < _meshes.size(); ++i) {
		joints_size += _meshes[i]._joint_names.size();
	}

	// allocate joint names, force first one to always be identity
	std::vector<std::string>	joint_names;
	joint_names.resize(joints_size);	
	DTuint joint_offset = 0;	// Account for identity above

	for (DTuint i = 0; i < _meshes.size(); ++i) {
		MeshData &meshdata = _meshes[i];

        if (meshdata._vertices.size() == 0)
            continue;
    
        std::shared_ptr<Mesh> mesh = Mesh::create();
		
		// copy joint names
		for (DTuint j = 0; j < meshdata._joint_names.size(); ++j) {
			joint_names[joint_offset + j] = meshdata._joint_names[j];
		}
        
        std::vector<Vector3> vertex_stream;
        std::vector<Vector3> normals_stream;
        std::vector<Vector2> uvs_stream_0;
        std::vector<Vector2> uvs_stream_1;
        std::vector<Vector4> weights_strength;
        std::vector<WeightsIndex> weights_index;
        std::vector<Triangle> indices;
        
        vertex_stream = meshdata._vertices;
        normals_stream = meshdata._normals;
        uvs_stream_0 = meshdata._uv_sets[0]._uvs;
        uvs_stream_1 = meshdata._uv_sets[1]._uvs;
        indices = meshdata._indices;
		
        if (meshdata._weights.size()) {
            
            weights_index.resize(meshdata._weights.size());
            weights_strength.resize(meshdata._weights.size());
        
            for (DTuint j = 0; j < meshdata._weights.size(); ++j) {
                weights_strength[j] = Vector4(      meshdata._weights[j].weight_1(),
                                                    meshdata._weights[j].weight_2(),
                                                    meshdata._weights[j].weight_3(),
                                                    meshdata._weights[j].weight_4()    );

                weights_index[j] = WeightsIndex(    meshdata._weights[j].bone_1(),
                                                    meshdata._weights[j].bone_2(),
                                                    meshdata._weights[j].bone_3(),
                                                    meshdata._weights[j].bone_4()    );
            
            }
        }

        mesh->set_vertex_stream(vertex_stream);
        mesh->set_normals_stream(normals_stream);
        mesh->set_uv_stream0(uvs_stream_0);
        mesh->set_uv_stream1(uvs_stream_1);
        mesh->set_index_stream(indices);
        mesh->set_weights_index_stream(weights_index);
        mesh->set_weights_strength_stream(weights_strength);

        // Some stuff we can generate
        if (normals_stream.size() == 0)     mesh->generate_normals();
        if (uvs_stream_0.size() != 0)       mesh->generate_tangents();
        
        // Add the mesh
        target->add_mesh(mesh);

		joint_offset += (DTushort) meshdata._joint_names.size();
	}
		 	
	
	// Build skeleton
	std::vector<SkeletonJoint> s;
	build_skeleton(joint_names, _skeleton._joints, s);
    
    Skeleton skeleton;
    skeleton.set_skeleton(s);
    
	target->set_skeleton(skeleton);

	return DT3_ERR_NONE;
}