R0J0hound's Forum Posts

  • The models already are in pretty much normalized coordinants of -1 to 1. Using color to define position probably has way too low of percision to be useful, not to mention it would be slow to constantly need to get the individual components.

    That's odd that using only one axis of rotation is that much faster. The rotation math is only done on three objects, one for each axis X,y and z. We could combine the equations together at the expense of being readable.

    The zsorting of the points is probably the slow point now. For the tilemap rendering we could instead do a zbuffer instead of sorting and see if that's faster. For the Sprite rendering we could import the normals and transform them too, and then don't display or sort the normals facing away from the camera.

    The tilemap object does some typically useful things when you set a tile, such as updating its collision polygons. That probably adds up the way we're using it.

    Overall 4000 points is pretty high and we probably can get something that looks good with much fewer. Although we'd want it much faster if at all possible.

    I did an animation test with that eagle where all the points lerp between two frames with distorted points. It only lost a few fps.

  • It is faster, although less readable, even when doubling the number of points. It's actually a bit faster just using sprites instead of plotting to a tilemap, although coloring is a bit trickier. You can switch between the two with the use_tilemap variable.

    https://drive.google.com/open?id=0B-1_F ... TNuUS04NnM

    Loading a model file takes a few seconds right now. Tokenat is inefficient with large amounts of text. There are some topics on loading a dictionary that show faster ways which could be used here.

  • It's more of a point cloud renderer than a voxel one. I'm pretty sure something more efficient is done with voxel renderer's than drawing everything.

    Loops in the event sheet are probably the biggest culprit of why it's slow. I've compared equivelent loops in just JavaScript and they're over 20x faster. I guess in general the slowdown is events are interpreted and there is some overhead involved with it.

  • You may be able to do that with meshlab or cloudcompare, but there's probably a more direct way to do it.

    I found this:

    http://www.danielgm.net/cc/forum/viewto ... f=9&t=2322

    So with cloudcompare you can load a mesh and get a point cloud of the surface. I think a file format like ply would help here since it can be in text.

    Here's the test. I took the model in blender and created a uv for it and baked a texture to it, then after a little fanagling I managed to get the exported obj file to include the image with it. Then I followed the guide in the link above to sample points on the 3d model. I used 2000 points since that seemed reasonable, then I exported with the ply file format since that stores vertex colors.

    https://dl.dropboxusercontent.com/u/542 ... zer_3.capx

    It works and is slightly faster but the object has to be drawn smaller to hide the gaps. I also disabled the perspective transform since that caused even more gaps.

  • Look here:

    http://www.meshlabjs.net/

    Load your 3d model in obj format and search for "Poisson Disk Sampling". You could then export it back out to a obj file. The only catch is color/texture isn't used. I think an orthogonal render of the model could be used to sample the colors.

    Another idea could be to convert the mesh to voxels. There's a command line utility poly2vox that looks like it supports a few formats. The voxel formats would need to be decoded though.

  • tunepunk

    I had some fun trying my hand at implementing some of that stuff. My events are mostly clean and as readable as possible, although it's at the point where a lot of it needs to be refactored and cleaned up. It is mostly organized so maybe you'll find it useful.

    https://dl.dropboxusercontent.com/u/542 ... rizer.capx

    What it does is fairly straight forward.

    1

    The object file is loaded so we have a list of 3d points and a list of faces which list indices of the points.

    2

    The points are moved around, or in the capx rotated around in 3d.

    Rotation

    The rotation math to rotate on the xy plane is this:

    newx = x*cos(ang)-y*sin(ang)

    newy = y*cos(ang)+x*sin(ang)

    It's basically the same for xz or yz rotations. Just change the x,y variables.

    Changing the amount of rotation every frame can be used for animation.

    Translation

    Next after rotating the points around we need to move the points away from 0,0,0 which is the viewer position. So for example we want the object center to be five units in front of the viewer you could do this:

    newz = z+5

    This is important to do before the perspective transform because things get distorted near 0 and we shouldn't be able to see points with z<0 or behind the camera.

    Perspective

    Perspective is really simple, it's just multiplying x,y by a scale number and dividing by z:

    perspectiveX= x*scale/z

    perspectiveY= y*scale/z

    final transformation to screen position

    This is basically changing the center from 0,0 to the center of the screen.

    screenx = x+320

    screeny = y+240

    3

    Now that the points are transformed we next want to draw points and lines and perhaps polygons. There are a few ways that come to mind.

    Using sprites

    Sprites could be created at the transformed xy position and lines could be done by stretching sprites from one point to another. Polygons could be done with some madness with triangle sprites but that's not straightforward.

    Using the canvas plugin

    You can plot points, draw lines and draw polygons fairly easy. The antialiased lines may not be what you want. Also the paster plugin can be used for textured polygons but that's a different topic.

    Using a tilemap

    The tilemap can be thought of as an array and it removes the step needed to convert the array to something visual. One color is simple but if you look at the capx it shows a way to do a spectrum of colors, well 4096 to be exact. It takes red,green and blue components in the range of 0 to 15 and converts it to a tile number.

    Line drawing

    This is done by lerping from the one point to the other and drawing the inbetween points. Look the "plot line" function in the capx, it's fairly simple.

    polygon drawing

    This took me a bit to wrap my head around. I tried two methods to draw triangles.

    The first one is fairly simple to understand. First you find the bounding box that contains the all three points of the triangle, then you loop over every pixel in that bounding box and see if that pixel is inside the polygon. Unfortunately the math looks a bit hairy.

    The second method is a scanline method which is faster. It involves sorting the three points by y and then lerping along the edges to get the x positions at every y. It has less hairy math but isn't the simplest to understand either.

    Performance on the monkey model is about 4-6 fps and I don't think a whole lot of extra performance for this can be squeezed out of the events. This sort of thing is always pretty slow which is why the rasterization is usually all done by the gpu. It can be made faster if most of it was done in javascript, and the events were only used to issue commands. 60fps should be possible with the events ported directly over, but js isn't pleasant to work with imo.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This isn't a bug, it's a feature request.

  • Im sure someone uses databases with c2, although I never have myself. You could look at the plugin list to see if there's something to help with that or maybe search the tutorials to see if someone explains how to do it.

  • Variables are used a lot for just about anything, it just depends if you need them. I don't quite understand the second part of your question. Do you have a game that needs a database?

  • You can find more info about that sort of thing by an Internet search of "software rasterizer." The aticle you linked only gives a general overview from what I see.

    You said you came up with a way to display the array as pixels so I'll leave that subject for now.

    The simplest thing to draw is points. Basically you just have a list of 3d points that project to 2d like the link in the second post and just set the nearest pixel to the color.

    Lines can be done by stepping from one projected point to another with something like "bresenham's line algorithm."

    Animation is done by clearing the array and doing something like a 3d rotation on the points before projecting them to 2d. So just clear, move points, project to 2d, and repeat. It's hard to make it fast though.

    The obj file format is a text format so it'll be easier to parse than something else. Tokenat() can be used to do this. Basically look at one line at a time and see what the line starts with. If it starts with "v" it's followed by 3 numbers seperated by spaces that is a 3D point. If it starts with "f" it's a face and it's followed by indexes of the points that make up the points. Lines can be found from pairs of points of the face. That's the basics of it. There is other info you can parse if you need it.

    Here's a tutorial that goes in depth on how to make a software rasterizer that may be useful:

    https://github.com/ssloy/tinyrenderer/w ... -Bresenham’s-Line-Drawing-Algorithm

  • Here's something similar.

    https://dl.dropboxusercontent.com/u/542 ... dproj.capx

    The rotation bit could be useful to look at.

  • Aizark

    All my plugins are free to use.

  • A lot of things are done every tick and saving an expression to a variable is negligible in my opinion.

  • It depends on the external JavaScript. If you're making a plugin you can make a condition to query the input state or make a trigger that's called from an event listener or callback. It's mainly specific to the JavaScript you use.