There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: PLUGIN: Sprite3D v0.9.2 (sprite and video render), based on Direct3D plugin  (Read 721 times)

This is an upgrade of the older "Direct3D" plugin by AJA, which was used to display Theora videos in AGS, and also freely display sprites with various transformations (without creating standard game objects).

WARNING: neither the original plugin nor this reimplementation play any sounds from videos, they only display video frames. Adding sound support might be a goal for the future versions, but it's not in the immediate plans.

The original plugin was a nice addition as it worked around some engine's limitations, such as being unable to display video non-blocking or while keeping some other objects on screen (like GUI or cursor); or randomly creating scaled and rotated sprites on any layer in game. Not much changed since, except maybe in AGS 3.6.0 Overlays now come close to this plugin's sprites abilities.
But the older plugin also had a significant limitation, as it was made for an older engine, it did not support anything besides Direct3D renderer on Windows.

This new upgraded version, called "Sprite3D", now has following major improvements:
* OpenGL renderer support;
* May be built for Linux;
* Potentially maybe will work on Mac and Android, but not yet configured the project for that.

Another important part is that this plugin is purposely made 100% script compatible with the old plugin, which means that you may simply replace it in your game project and all the scripts will continue to work. In fact, you may even rename new plugin's dll into "ags_d3d.dll", replace it in the game folder, and it should hook up correctly.

Documentation:
https://github.com/ivan-mogilko/ags-sprite3d/wiki

The plugin is currently in the "test stage", and I will be interested to see how it works with existing games that used the original plugin. My primary goal at this point is to make it complete and stable substitute for "Direct3D" plugin.

Downloads:
Updated 27 July 2022
For Windows: https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.2/win_ags_sprite3d.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.2/libags_sprite3d.tar.xz
Source code: https://github.com/ivan-mogilko/ags-sprite3d

TODO for v1.0:
* Testing in some real games.
* Bug fixing
« Last Edit: 27 Jul 2022, 21:46 by Crimson Wizard »

Thanks,

Just to add to that, the documentation for d3d is not complete afaik.
There are some properties and/or functions which don't have explanations.

Looking forward to android/osx support in the future and perhaps some new features.

Updated to v0.9.1, now implements D3D.OpenSpriteFile() again.

For Windows: https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.1/win_ags_sprite3d.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.1/libags_sprite3d.tar.xz

I think this now covers all the functionality of the old plugin. What remains is mostly testing and writing a documentation.

Thank you very much Crimson for working on this plugin, I really appreciate! 💖

AndreasBlack

  • Max Fury that's me
Cool! Can't wait to try it out later! 8-0  (nod) Thanks like always. Too much summer activities as of lately so not much of game creation going on, on my end. Great to see others keeping the spirit up (laugh)

I tried to use this plug in on my test game, but received an error "undefined token 'video'".  I was attempting to play the video clip on room load before the fade in.  Is there anything I need to do beyond copying the plug-in file to the ags directory?

I'm running AGS Build 3.5.1.19


I tried to use this plug in on my test game, but received an error "undefined token 'video'".  I was attempting to play the video clip on room load before the fade in.

Please post your script where you are using this plugin?

Is there anything I need to do beyond copying the plug-in file to the ags directory?

You also need to activate the plugin in the game's project tree.
« Last Edit: 21 Jul 2022, 11:33 by Crimson Wizard »

The plugin is activated.  This is just a simple room where I would like it to play the video, then open a menu with a title screen and start button.  Everything works just fine, until I try to add the video.  The plug in instructions just had the code, but not a lot of explanation, so I'm sure I just missed something

The code is below.  -Thank you!

// room script file


function room_Load()
{
gIconbar.Visible = false;
gStatusline.Visible = false;
mouse.DisableMode(eModeWalkto);
mouse.DisableMode(eModeLookat);
mouse.DisableMode(eModeInteract);
mouse.DisableMode(eModeTalkto);
mouse.DisableMode(eModeUseinv);
mouse.DisableMode(eModePickup);
mouse.DisableMode(eModeUsermode1);
mouse.DisableMode(eModeUsermode2);
mouse.EnableMode(eModePointer);
mouse.Mode = eModePointer;

// Required for autoplay
    D3D.SetLoopsPerSecond( GetGameSpeed() );
   
    // Open video file
    video = D3D.OpenVideo( "G:\AGS_RPG_POC\Renders\MMI Intro.ogv" );
   
    if ( video )
    {
        // Use room coordinates
        video.relativeTo = eD3D_RelativeToRoom;
       
        // Anchor point to top left corner
        video.SetAnchor( -0.5, -0.5 );
       
        // Play!
        video.Autoplay();
    }
    else
    {
        Display( "Couldn't open video." );
        return;

aTitleMusic.Play();
}

function Startbutton_AnyClick()
{
cEgo.ChangeRoom (2);
}

function room_Leave()
{
// Free memory when leaving the room
    video = null;
}

Everything works just fine, until I try to add the video.  The plug in instructions just had the code, but not a lot of explanation, so I'm sure I just missed something

In your code you are using a variable called "video", but you have not declared it anywhere. Since you are using it in multiple functions, you need to declare a global variable, somewhere at the top of your script:
Code: Adventure Game Studio
  1. D3DVideo* video;
  2.  

I placed:

Code: Adventure Game Studio
  1. // define video
  2. D3DVideo* video;

at the top of the global script, but I still get the undefined token error on the "video = D3D.OpenVideo ....." line of my room1 script.


Thank you for your help so far, I appreciate it.

I placed:

Code: Adventure Game Studio
  1. // define video
  2. D3DVideo* video;

at the top of the global script, but I still get the undefined token error on the "video = D3D.OpenVideo ....." line of my room1 script.

If you are using this variable only in the room script, then you should declare it in the room script. Room script does not see variables declared inside the global script.

If you want to use this variable throughout the game, in global script and multiple rooms, then you need to place it in global script and import/export it.
Code: Adventure Game Studio
  1. // in GlobalScript.asc
  2. D3DVideo* video;
  3. export video;
  4.  
  5. // in GlobalScript.ash
  6. import D3DVideo* video;
  7.  

AGS manual has this article about sharing variables between scripts:
https://adventuregamestudio.github.io/ags-manual/ImportingFunctionsAndVariables.html
« Last Edit: 23 Jul 2022, 22:31 by Crimson Wizard »

Thanks again for all your help!  I'll be using video in every room, so this sounds like a great solution.  I placed the code as instructed, lines 2&3 in the global script and line 6 in the global header.  I'm now getting the following error when I attempt to run the game.

Code: Adventure Game Studio
  1. Failed to save room room1.crm; details below
  2. GlobalScript.ash(7): Error (line 7): expected variable or function after import, not 'D3DVideo'

Sorry for asking so many questions - this is the first time I've used a plug-in.  Getting the music to keep playing while a video plays is one the last obstacles to overcome for my little proof of concept game - then I can start developing the real thing!

Thanks again!

Code: Adventure Game Studio
  1. Failed to save room room1.crm; details below
  2. GlobalScript.ash(7): Error (line 7): expected variable or function after import, not 'D3DVideo'

Sorry for asking so many questions - this is the first time I've used a plug-in.

Sorry, I said it wrong, it's D3D_Video, not D3DVideo.
This is mentioned in the original plugin's documentation here: http://www.serpentpictures.net/ags_d3d/ where it sais "b) Playing a video over the background"


EDIT:
Getting the music to keep playing while a video plays is one the last obstacles to overcome for my little proof of concept game - then I can start developing the real thing!

I was curious and found your previous posts about the game you're trying to make here: https://www.adventuregamestudio.co.uk/forums/index.php?topic=60020.0

I must mention that this plugin does not play any sound, it technically has no audio output, so it only displays video frames. I should have mentioned this in the description earlier.
Resolving the sound issue would require either to fix the engine and let it play video sounds simultaneously with the game sounds (that's perfectly possible to do), or extend the plugin to support audio output.
« Last Edit: 25 Jul 2022, 17:20 by Crimson Wizard »

Thank you!  The video played, and my menu sprites were still displayed above the video, that's exactly what I wanted!  I experimented by playing an audio file immediately after the video started, and it played at the same time.  I'll continue experimenting with playing the audio exported from the original video files and see how close they sync up.

1 more question for you.  When the video ended it just froze on the last frame until I clicked.  Is there a way to make it go away without user input when the video ends? - Calculated video cycles then:

Code: Adventure Game Studio
  1. WaitMouseKey(640);
  2.  
  3. video = null;

Thanks again!  Getting the video to play over the sound was a huge step toward getting my crazy idea out of my head and onto a screen. You made my day!
« Last Edit: 28 Jul 2022, 04:53 by Jess McD »

Updated to v0.9.2,

- Fixed D3D_Sprite's Tint properties not working in OpenGL mode.
- Fixed plugin crash when exiting game while video is playing.

For Windows: https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.2/win_ags_sprite3d.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.2/libags_sprite3d.tar.xz