Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Member Since 26 Nov 2012
Offline Last Active Yesterday, 10:34 PM

Topics I've Started

Trying to optimize a mesh in python, but it's WAY too slow :P

Yesterday, 02:56 PM

Yo, this is Solid.


I'm in a bit of a pickle here.


I am writing a mesh exporter script for Blender, which works, however I am also trying to optimize the mesh data before exporting to the file.


By export, I mean removing duplicate vertices.


For example:

A quad is made up of two triangles.

A triangle is made up of 3 edges/vertices (I use these terms interchangebly).

An edge has it's own vertex position, uv coordinates, and normals.


...Therefore, the quad has 6 edges.


The indices for the quad that is unoptimized would look something like this: 0 1 2 3 4 5.


...But, the mesh can be optimized to have only 4 edges, since two of them are shared by both triangles. Just look at any picture of a quad made up of two triangles and you will see what I mean.


You can get rid of the extra duplicate vertices, and change the indices to something like this: 0 1 2 1 3 2.


Of course, the exception is if the neighboring edges have different uv's or normals, in which case the vertices would NOT be optimized tongue.png.




So, here is the script I wrote to optimize the mesh (I cannot send the whole script because it is WAY too long):

#the vertex class
class nonAnimatedVertice:
    xPosition = 0.0
    yPosition = 0.0
    zPosition = 0.0
    u = 0.0
    v = 0.0
    xNormal = 0.0
    yNormal = 0.0
    zNormal = 0.0

#used to store data about a current vertex and it's previous location, as well as its copies
class vertexPointerForOptimisation:
    def __init__(self):
        self.vertexCopies = []
    vertexPreviousIndex = 0

vertexList = []
indices = []


#optimise the mesh and get rid of duplicate vertices:

listOfVertexPointers = []
currentVertexListLength = len(vertexList)
foundADupe = False
iterator = 0
currentVertexIndex = 0

#first, gather all of the necessary vertex data and put it into a list:
while iterator < currentVertexListLength:
    #check if there is already a duplicate in the list of vertex pointers:
    foundADupe = False
    currentVertexIndex += 1
    if listOfVertexPointers:
        for vertexPointerIndex in range(len(listOfVertexPointers)):
            if listOfVertexPointers[vertexPointerIndex].vertexCopies:
                for vertexCopyIndex in range(len(listOfVertexPointers[vertexPointerIndex].vertexCopies)):
                    if iterator == listOfVertexPointers[vertexPointerIndex].vertexCopies[vertexCopyIndex] and \
                    foundADupe == False:
                        #print("found a duplicate vertex!")
                        foundADupe = True
    if foundADupe == False:
        #create a new vPointer:
        vPointer = vertexPointerForOptimisation()
        vPointer.vertexPreviousIndex = iterator
        #check for duplicates:
        for vertex in range(0, currentVertexListLength):
            if vertex != iterator:
                if vertexList[vertex].xPosition == vertexList[iterator].xPosition and \
                vertexList[vertex].yPosition == vertexList[iterator].yPosition and \
                vertexList[vertex].zPosition == vertexList[iterator].zPosition and \
                vertexList[vertex].u == vertexList[iterator].u and \
                vertexList[vertex].v == vertexList[iterator].v and \
                vertexList[vertex].xNormal == vertexList[iterator].xNormal and \
                vertexList[vertex].yNormal == vertexList[iterator].yNormal and \
                vertexList[vertex].zNormal == vertexList[iterator].zNormal:
                    #print("found a copy!")
    iterator += 1
#remove all of the duplicate vertices by creating a new list of vertices:

optimizedVertices = []

for vertexPointerIndex in range(len(listOfVertexPointers)):
#Now that we have all the previous vertex data all inside of one list, we can
#now modify the indices with our new vertex indices.

changedAnIndice = False

for currentIndex in range(len(indices)):
    changedAnIndice = False
    for vertexPointer in range(len(listOfVertexPointers)):
        if changedAnIndice == False:
            if listOfVertexPointers[vertexPointer].vertexPreviousIndex == indices[currentIndex]:
                indices[currentIndex] = vertexPointer
                changedAnIndice = True
                for currentCopy in range(len(listOfVertexPointers[vertexPointer].vertexCopies)):
                    if indices[currentIndex] == listOfVertexPointers[vertexPointer].vertexCopies[currentCopy]:
                        indices[currentIndex] = vertexPointer
                        changedAnIndice = True
#Test and see if the indices are correct.

for index in range(len(indices)):
print("list of vertices:")
print(len(optimizedVertices ))
print("list of vertexPointers:")

Of course, this becomes extremely slow because of the fact that it uses O(n^2) loops.

However, I cannot figure out another way to look for duplicates. Or maybe there is a much easier way to do all of this tongue.png.


Does anyone have any ideas?


EDIT: I am considering using a quadtree or an octree, however if you have any ideas, let me know ;3.

Help! I cannot run makefiles with commands D:!

02 October 2014 - 03:38 PM

Hello, I am having some really strange issues with building libraries.


I've never really had a lot of luck with building libraries, and I usually end up throwing all the source code into an Eclipse program and compiling.


Every time I run a makefile, I do it by opening cmd.exe, then type make, and I just get an error. If I type make mingw, as many libraries specify me to do, I also get errors, and the program failed to start correctly message pops up. I just don't know what I am supposed to do :|.


I really just don't get it... I have Mingw\bin, and MSYS/bin in my PATH variables, so I figured there wouldn't be any problems, but apparently there are. And no, the libraries don't require cmake.


For example, I am trying to compile the Lua libraries (which is supposed to be a very simple compile, apparently :|), and it just gives me this output:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

make: *** No targets specified and no makefile found.  Stop.

C:\Users\NULL>make mingw
make: *** No rule to make target `mingw'.  Stop.

C:\Users\NULL>cd C:\Users\NULL\Downloads\lua-5.2.3.tar\lua-5.2.3\lua-5.2.3

C:\Users\NULL\Downloads\lua-5.2.3.tar\lua-5.2.3\lua-5.2.3>make mingw
cd src && make mingw
make: *** [mingw] Error 66

make: *** [none] Error 66

C:\Users\NULL\Downloads\lua-5.2.3.tar\lua-5.2.3\lua-5.2.3>make mingw
cd src && make mingw
make: *** [mingw] Error 66


Please help D:, I can't go on like this!!!1!


passing data between objects using messages... wat do?

01 October 2014 - 02:59 PM

Hello, I am looking for a better method for passing variables (or components maybe) between objects in c++.


I already have a working messaging system completed, and I am using a component based architecture.


Surprisingly, I haven't found very much information on how to actually pass information from one object to another in the form of variables.


for example: Lets say I'm making a game, and mario needs to know how much time is left in a level. Lets say there is a Mario object and a Time object. The time object has a float time;, and mario needs to know about it in his update function. How would I go about retrieving that time value (or a pointer to it for that matter)?


I was thinking of just grabbing a pointer to the component that has the variable (with an Interface Component pointer), and then just type cast it to the right type of component to get the variable...


but one major downside to this method is the lack of flexibility. I would have to #include the data type of the component for every type of component I want to access... which would be daunting. Sure, I could just put them all inside a MainHeader.h and include it in every Component.h, but that would stifle my compile times, and every time I add a new #include, I would have to recompile the whole program @~@!


Another alternative I was considering, Is to just subscribe a pointer to the variable I want to a map of maps, kinda like a list of subscribers. An example would be map<string, map<string, void*>>; Where the first string would be the instance name of the object, and the second string would be the variable name, and the void* would be a pointer to the variable I want. I could subscribe the variable name to the list of map objects when the object is created, so that I can access it later. I could send a message to the message system requesting the variable in question, and retrieve it easily.


However... the downside to this method is the overhead... I would have to subscribe hundreds of variables every frame if I was creating a whole lot of objects, and I would be doing a lot of string comparisons... etc. However I cannot think of a more flexible method.




What i'm really asking is... is there a better method to allow objects to flexibly access other objects variables?


Any code examples would really help me out.


Any help would be appreciated :3.

how to make a function pointer point to different methods of different classes

27 September 2014 - 09:43 PM

Hello, I am trying to set up a messaging system in my game engine in c++. I already have a component based architecture set up, and I have different components for different game objects.


However, I only just started learining about function pointers, and have decided that my message system will call whatever function pointers are subscribed to certain message types in a list, or a map.


At first I wanted to just use a "recieve message" function in all my components and use a switch statement to decide what functions to call, but decided that function pointers would be a lot more flexible.


The problem is, I have different components of different types, that all inherit from an IGameComponent Interface. I tried using the std::function function variable, and tried to create a list of std::function<void(&IGameComponent)> types, but I got a compile time error when trying to access the functions.


Every component that inherits from IGameComponent has their own methods, which is the way I want it to be. It seems that std::function doesn't like calling member functions from inherited classes, and I cannot seem to get it to work. I cannot let the messaging system know about each and every game component type, otherwise I would get a circular dependency.


Here is an example of what I am trying to do:

#include <functional>
#include <iostream>

class IClass
	virtual ~IClass(){};

	virtual void nopeFunction()=0;

class classWithMemberFunctions : public IClass
	virtual ~classWithMemberFunctions();

	void nopeFunction(){std::cout << "nope";};

	void memberFunction();

int var1;
int var2;
float var3;

#include "classWithMemberFunctions.h"





void classWithMemberFunctions::memberFunction()
	std::cout << "Function has been called.";

int main()
	classWithMemberFunctions class1;

	std::function<void(classWithMemberFunctions&)> functionPointer;

	std::function<void(IClass&)> functionPointer2;

	functionPointer = &classWithMemberFunctions::memberFunction;

	functionPointer2 = &classWithMemberFunctions::memberFunction;

	functionPointer(class1);    //This works!
	functionPointer2(class1);  //This doesn't work -.-

	std::cout << "Hello world!";
	return 0;

Any help would be greatly appreciated ^^.

Gl Bind Texture is taking over my program X(!

30 April 2014 - 09:35 PM

Hello, I am having a VERY strange problem with openGL recently.


To get to the point, I am trying to render objects with textures, and without textures. But for some reason, whenever I render an object with no texture, it ends up appearing black, even though I am using a pixel shader that outputs a red color, for example.

Psoudo code:

Bind Program...
Bind texture...
Bind Vertex Array...
Render textured object, done!

Bind texture(texture_2d, 0) // default texture

Bind Program...
Bind Vertex Array...
Render NON-Textured Object, da fek?? Why is it black!???

It seems like whenever I still use the last texture without setting it to 0, the shader uses one of the colors from the texture to color my non-textured object, even though the shader doesn't accept a texture for input... -.-


Here's a picture of what is happening:



These are what my color shaders look like:

        public string vertexColorShaderText = @"
#version 130

in vec3 in_Position;

out vec3 out_color;

uniform mat4 worldMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;

void main(void)
    gl_Position = worldMatrix * vec4(in_Position, 1.0f);
	gl_Position = viewMatrix * gl_Position;
	gl_Position = projectionMatrix * gl_Position;

        public string pixelColorShaderText = @"
#version 130

out vec4 last_color;

void main(void)
    vec4 derp_color;
    derp_color.r = 1.0;
    derp_color.g = 0.0;
    derp_color.b = 0.0;
    derp_color.a = 1.0;
    last_color = derp_color;

I just don't understand. Is there something I am supposed to be doing here???