Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

3D engine... Much interest?
Started by richard11 Dec 23 2018 04:52 PM

83 replies to this topic
[TOPIC CONTROLS]
« Page 4 of 4 2 3 4
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#76

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

I've managed to get the code together and uploaded to github. The build even runs in a browser:

 

https://github.com/HoraceBury/3d


  • Michael Flad likes this

[TOPIC: post.html]
#77

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 448 posts
  • Corona SDK

Wow, thanks for posting that. I'd definitely like to devote some time to digging through your code a little. I've had a quick scroll through some of it but I'm far too sleepy to understand your maths right now!

[TOPIC: post.html]
#78

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 448 posts
  • Corona SDK

Right. I had a few hours to brush the dust off of this today!

 

Fixed a fairly critical bug that was previously preventing me from showing off the camera rotation, implemented some very basic off-screen culling, reworked the rendering to order faces by their distance instead of by the distance of the object they belong to (for slightly better handling of overlapping objects but it's not perfect), and experimented more with current performance figures. Definitely needs optimising better and I am now very much doubting that I'll be able to get any kind of proper intersecting faces support into this, but for those interested, here's an Android APK:

 

https://development.qweb.co.uk/q3d-test-2.apk

 

This creates 50 cubes located randomly around the camera, then rotates the camera around on a timer. Each face is currently made up of 32 triangles and because the culling is basic, on average it's rendering between 30 and 100 faces at any one time so we're looking at around 1000 - 3000 polygons.

 

I've only been able to test on my own phone so far - a slightly battered Samsung S8 - and the results aren't great. There's visible jutter when a large number of faces are being rendered because again the culling is basic - a good number of off-screen faces are actually still being rendered at the moment - and in all honesty a fair bit of the rendering code just needs thinking out better. The rotation timer for the demo itself isn't the best implementation either to be fair... it fires every 1ms and rotates by 0.005 degrees, but at 30fps there'll be around 33ms between each frame even when the renders can keep up, so that's 33 fires between each frame meaning 0.165 degrees of rotation between visual update, which was never going to be smooth.

 

Here's the entire code behind this demo, by the way:

-- This isn't really needed, but Android's navigation bar looks ugly so...
native.setProperty("androidSystemUiVisibility", "immersiveSticky")

-- First, tell q3dengine where 3D models and texture files are.
q3d.setAssetsFolder("assets")

-- Generate some cubes

math.randomseed( os.time() )

for i=1, 50, 1 do
	q3d.addCube({ name = "myCube" .. i, x = math.random(-20, 20), y = math.random(-1, 1), z = math.random(-20, 20) })
end

-- Initial camera placement
q3d.moveCamera({ x = 0, y = 6, z = -10 })
q3d.rotateCamera({ x = -30, y = 0, z = 0 })

-- Enable the main Q3D loop to render/update our world
q3d.activate()

-- And set up some auto camera rotation
local function doCameraRotation()
	q3d.rotateCamera({ y = .005 })
end
timer.performWithDelay(1, doCameraRotation, -1)

I'm tired. I'll tidy up properly later and hopefully squeeze better performance out, but for now I just wanted to post an update.


  • Michael Flad and sporkfin like this

[TOPIC: post.html]
#79

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 448 posts
  • Corona SDK

Proper off-screen culling now, reducing to an average of 15 faces at any one time (480 poly). Also replaced the timer based rotation with enterFrame. Much smoother results, I think. There's still a noticeable speed increase when only a couple of cubes are on screen compared to when there are a dozen or so, but it's a definite improvement...

 

https://development.qweb.co.uk/q3d-test-3.apk

 

I'm sure I can squeeze more performance out of this somewhere...



[TOPIC: post.html]
#80

Kevin H

[GLOBAL: userInfoPane.html]
Kevin H
  • Contributor

  • 131 posts
  • Corona SDK

I love this project. Amazing work!



[TOPIC: post.html]
#81

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 448 posts
  • Corona SDK

Thanks Kevin. It's a fun project to work on, I just hope I can squeeze enough out of it to be useful to people...

[TOPIC: post.html]
#82

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

Richard, I love this too.  My Samsung S8 is acting up but I'll give the APK a try when I get the issue resolved.



[TOPIC: post.html]
#83

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 448 posts
  • Corona SDK

Performance still isn't what I want it to be on the S8, but I've a plan for how to make the rendering considerably more efficient. I might not be able to crack on with that until the weekend though.

There's a bug in the above APK too - The culling happens slightly too early on some screens so you can see the faces disappear before they fully leave the screen. That's fixed now, just not in the demo.
  • Michael Flad likes this

[TOPIC: post.html]
#84

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

I got it running, that's really cool Richard!  I'm excited to see what comes next.


  • Michael Flad and richard11 like this


[topic_controls]
« Page 4 of 4 2 3 4
 
[/topic_controls]