X3Canvas with ModelMouseDown event

Some of you might have seen on the Xojo3D.com website, that I’m busy working on an open source 3D engine written in pure Xojo known as X3.

Recently I’ve added a brand new X3Canvas control to the X3Core module. This canvas control mimics the native 2D Xojo Canvas control exactly, except that it uses OpenGL for rendering. X3Canvas also provides additional features for working with 3D graphics.

The point is, with X3Canvas you can now mix 2D and 3D graphics seamlessly, and using it is just as easy as it is to draw with the native Xojo canvas control.

A few examples on how to use X3Canvas is posted on GitHub:
https://github.com/alwyn1024/x3-core/tree/master/examples

Simply add the X3Core module to your project, drag the X3Canvas onto your Window, and access the Canvas.Graphics property to start drawing pictures and text exactly how you would with the native Xojo canvas control.

I would like to share one of the more advanced features of X3Canvas though, the new ModelMouseDown event. It does exactly what it implies… when a user clicks with his mouse on the X3Canvas control, a ModelMouseDown event is raised that returns the 3D (or 2D) X3Model that the user clicked on. You can manipulate models in your scene effortlessly by using this event. All the math complexity of picking models from 3D (or 2D) space is done automatically for you.

Here is a screenshot of the “selectmodel” project in the examples folder on GitHub.

Enjoy.

Now also added a PolygonMouseDown event to make interaction with individual polygons in your scenes easy.

Event PolygonMouseDown(x As Integer, y As Integer, polygon As X3Core.X3Polygon, polygonIndex As Integer)

This is amazing stuff, thanks a lot, Alwyn!
I have some problems running it on a Mac. It used to crash on the BGRABitmap assignment in X3Texture constructor – the image size calculated was more than the size of the MemoryBlock.
I changed it to BGRABitmap = mb.StringValue(54, mb.size - 54) whch makes it run now but the look is not quite satisfying – is there a difference in handling the alpha channel data on Mac vs Windows?
(The tiles demo gives a similar, yet somewhat less recognizable result)

Thanks Ulrich.

An optimization we recently made for faster texture loading on Windows caused the crash on OS X.

I have already reverted the code back to the previous version that runs without error on OS X. In time I will implement the optimizations with compiler directives as to not affect the running on OS X. If you see any BGRABitmap properties you don’t have the latest version… all the properties should be named RGBABitmap.

You can get the latest (fixed) version of “Canvas Test” here:
https://github.com/alwyn1024/x3-core/tree/master/examples

This is what the screen should look like…

I got it working with the optimized code with this extra line in the Constructor…

[code] if not texture.HasAlphaChannel then call texture.Mask //fix 3 bytes per pixel to 4

mb = texture.GetData(Picture.FormatBMP)
RGBABitmap = mb.StringValue(54, Height * Width * 4) // RGBA[/code]

See here for details about the fix. Guess it’s a Mac only issue.

Great stuff, thank you Will, this is a much better solution than a compiler directive workaround. Will update the code accordingly.

Much better! :smiley:
Thanks, Will!

I’ve updated the X3Core module with Alain’s improved algorithm for texture loading, together with Will’s fix for OS X operating system.

Could someone please verify if the canvastest project still runs correctly on OS X?

https://github.com/alwyn1024/x3-core/tree/master/examples/canvastest

Thank you in advance for checking.

I‘m not sure if this is my inability to use Git (I swear I‘ll watch the recorded webinar soon!) or something else, but while the demo image is now included, Will‘s fix is still missing.

I tried to push the fix myself (trying to learn a bit Git that way). Could you please check if this is working for you still now?

BTW: Is a binary format the right one for a Git project? I cannot view changes in GitHub. Wouldn‘t it be better to use text or XML format?

And sorry for all the remarks: Somehow, though I told Git to synchronize, your latest changes have not been transferred, I noticed now. I‘ll remove my commit and try to access the real version. Sorry again!

Just pulled the latest version to my home PC and it updated the module with the latest changes.

Great stuff. Best way to learn Git is simply to start using it :wink: Things are working on this side, but I am not seeing any changes that you made?

I suppose not. I’ve really been using Git as an easy way to synchronize code between my work and home PC, and the binary format worked ok for that. I also want to make it easy for fellow Xojo developers to use X3 in their own projects by simply downloading a single X3 binary module and importing it with one action (instead of importing all the different classes individually).

But now that the project is getting bigger with some examples, and a handful of gaming developers adopting X3 for their own game engines, I plan to relook the GitHub structure after the release of version 0.3.0 of X3 (the version being worked on now).

To be honest, I also probably also need to watch the Git seminar to get a better understanding of Git. My understanding is limited to:

Pull - Get the latest version from the server.
Push - Send my changes to the server.
Revert - Rollback changes that broke something.

I’m very spoiled with TortoiseGit in Windows, since it is integrated with the Windows Explorer and hides all the complexity of Git from the user. I simply right-click and select push or pull.

If there are other users interested in contributing to X3, I think we need to look at the branching and merging features to keep things organized. Currently all the changes are committed on a single master branch. I know about these features but haven’t really used it before. As soon as v0.3.0 is released, I’ll revisit the whole way X3 is currently stored in GitHub.

Just finished watching Justin Elliott’s session on “Getting to know Git”, and I will definitely change the project format to the text format with the next version.