Camera Effect Script - once again

Talk about the MediaTracker here

Moderator: English Moderator

winnixxl
Posts: 6
Joined: 04 Oct 2015, 14:24

Camera Effect Script - once again

Post by winnixxl » 07 Aug 2018, 23:11

TL;DR
(How) does the camera effect script work in the Replay Editor?

I know there were already a couple threads discussing this, but I cant figure out whether you can use a script to control the camera.

What Im trying to do:
I filmed a video with my camera, tracked the camera motion using Blender, and exported the position and rotation data to a text file. The result looks something like this (each line corresponds to 1 frame in the video):
|------camera position----------|-------camera rotation-------|
224.9051, 390.6299, 105.5979, 27.4825, 94.2573, 163.1965
224.9791, 390.6056, 105.5692, 27.4877, 94.3128, 163.1984
225.0992, 390.6345, 105.5379, 27.5061, 94.3870, 163.2044

now I want to get this data into the mediatracker (matching the movement of the real camera to the ingame camera)
The Camera Effect Script seemed to be the perfect tool for that.

What I've got so far:
I am using this script right now for testing how it works:

Code: Select all

#RequireContext CGameCtnMediaBlockCameraEffectScript
#Include "MathLib" as MathLib

while(True){
	OffsetPos[0] = A*200;
	OffsetPos[1] = 512.0;
	OffsetPos[2] = 15.0;
	
	OffsetRot[0] = 0.0;
	OffsetRot[1] = 0.0;
	OffsetRot[2] = 0.0;
	yield;
}
However the camera just stays fixed to its default position, where it was when I open the replay

How can you help me:
  • How to use the Camera Effect Script
    If I was able to make the camera do anything at all, that would be a huge step for me
  • Other ideas on how to control the movement of the camera
    My last resort would probably be a regular custom camera and AutoHotkey to create lots and lots of keyframes, but that would probably be really annoying
    I never have looked at Openplanet, could this be a possibility?
Thank you very much for reading this far :clap:
Any help would be appreciated

winnixxl
Last edited by winnixxl on 08 Aug 2018, 19:17, edited 1 time in total.

User avatar
Demented
Posts: 1932
Joined: 07 Nov 2010, 13:17
Location: United States

Re: Camera Effect Script - once again

Post by Demented » 08 Aug 2018, 13:32

Hi winnixxl, and welcome to the forum.
What you are trying to do sounds really cool.
I wish I had some answers for you, but I would like to know more about this also.
CPU: Intel I7-4770 64Bit @ 3.4Ghz.
Ram: 16GB DDR3
GPU: Geforce GXT 1060 6GB DDR5
Windows: 7 Pro SP1 64bit

winnixxl
Posts: 6
Joined: 04 Oct 2015, 14:24

Re: Camera Effect Script - once again

Post by winnixxl » 08 Aug 2018, 16:48

OK so Im gonna use this thread, to keep you updated about the progress I made

METHOD 1: AutoHotkey (Updated 2018-08-17)
Python Script to extract the coordinates out of blender export

Code: Select all

# One TM2Stadium Block is 32x32x8
# The Valley car is ~ 4x2.2x1.6
# The center of the map is at 512,512
# The floor is 9 high

import re, math

anchor_blender = {
    "pos": [0.54, -3.32, 0],
    "size": 0.45
}

anchor_trackmania = {
    "center": [500, 231.5, 18],
    "scale": 4
}


def transform_loc(loc):
    ret = [0, 0, 0]
    # We divide by 2 because cube sizes in blender are mesured as radius
    full_scale = anchor_trackmania["scale"] / anchor_blender["size"] / 2

    for i in range(3):
        offset_trackmania = (loc[i] - anchor_blender["pos"][i]) * full_scale
        if(i == 0):
            offset_trackmania *= -1
        ret[i] = offset_trackmania + anchor_trackmania["center"][i]
    return ret

data_stage_0 = []

with open("input/input.py", "r") as f:
    data_stage_0 = f.read().split("# ")

#This regex will match somthing that looks like:
#  new frame ...
#  obj.location = (coordinates)             <--- 1st group
#  obj.scale ... 
#  obj.rotation = (coordinates)             <--- 2nd group
#  ...
reg_ex=r'new frame.*obj\.location = ([\-\d\.\s,]*)\nobj\.scale.*obj\.rotation_euler = ([-\d\.\s,]*)\n.*'

with open("input/output.txt", "w") as out:
    for frame_data in data_stage_0:
        match = re.fullmatch(reg_ex, frame_data, re.S)
        if match != None:
            #get the coordinate triples and pack them in arrays
            loc = re.split(r",\s", match.group(1))
            rot = re.split(r",\s", match.group(2))

            #convert the strings into floats
            loc = list(map(float, loc))
            rot = list(map(float,rot))
            
            #we have to switch y and z because Maniaplanet... 
            loc = transform_loc(loc)
            loc[1], loc[2] = loc[2], loc[1]

            rot = list(map(lambda x: x / math.pi * 180, rot))
            rot[0] = 90 - rot[0]
            #and the same for the rotation
            rot[1], rot[2] = rot[2] % 360, rot[1]

            first_c = True
            for coord in loc + rot:
                if(first_c):
                    first_c = False
                    out.write(str(round(coord, 3)))
                else:
                    out.write(", " + str(round(coord, 3)))
            out.write("\n")
AHK Script: (Keep in mind that this is very much in developement right now and will most likely not work for you)

Code: Select all

^!j::
MsgBox, "Press F7 to interupt the Script"
;;;;;;  SETTINGS  ;;;;;;

start_time := 0				; times are in 1/100s of a second
end_time := 1600
fps := 30				; fps of original video 
keyframe_intervall := 25  		; Should be 6 or more
lens_angle := 31			; You find this in your blender export (line 7)

;;;;  END SETTINGS  ;;;;


CoordMode, Mouse, Client
CoordMode, Pixel, Client

; Open the advanced menu if necessary
PixelGetColor, targetColor, 100, 460
PixelGetColor, bgColor, 190, 460
if targetColor = %bgColor%
{
	Click, 230, 240
}

; set FOV on first and last Frame
Click, 170, 345
Send, {Del 10}%lens_angle%
Click, 170, 400
Send, {NumpadMult}
Click, 170, 345
Send, {Del 10}%lens_angle%
Click, 170, 400
Send, {NumpadDiv}




current_time := start_time
Loop
{	
	lineNumber := current_time * fps / 100 + 1
	FileReadLine, args, output.txt, %lineNumber%
	array := StrSplit(args, ",")

	Loop % array.MaxIndex()
	{
		x := 60 + 110 * Floor((A_Index - 1) / 3)
		y := 275 + 20 * Mod((A_Index - 1), 3)
		value := array[A_Index]
		
		Click, %x%, %y%
		SendInput, {Del 10}
		SendInput, %value%
	}

	current_time := current_time + keyframe_intervall

	PixelGetColor, errorBox, 1100, 475
	if current_time > %end_time%
		Break
	if errorBox = 0x442B04
		Break
	
	sec :=  SubStr("00" current_time // 100, -1)
	csec := Substr("00" Mod(current_time, 100), -1)

	Click, 835, 675
	SendInput, {BS 10}
	Sleep, 30
	SendInput, 0:%sec%.%csec%
	Click, 900, 675
	Click, 1370, 675
}

Progress, Off
return

F7::ExitApp
  • 2018-08-08
    Basically it creates a new keyframe, reads one line from the file and enters the coordinates
  • 2018-08-09
    The script now adds multiple keyframes. However Maniaplanet is limiting me to put the keyframes 0.05 seconds apart
    With my 50fps video, Id like to have a 0.02 second gap, but that is only possible if you drag the keyframes to their correct position and this seems to be almost impossible via AutoHotkey. :? Oh and I can put keyframes on 0.05 -> 0.10 -> 0.15 -> 0.21 but not 0.20??? Nadeo please...
    The next Task will be to make the script a bit faster (1.2 seconds per keyframe)
  • 2018-08-09
    Added setting to to deal with different framerates, FOVs, and compensate for Maniaplanets strange coordinate system
    Not too much new features but overall workflow enhancements
Last edited by winnixxl on 16 Aug 2018, 23:28, edited 3 times in total.

User avatar
adamkooo2
Posts: 1275
Joined: 13 Jun 2014, 08:43
Location: Slovakia // Slovensko
Contact:

Re: Camera Effect Script - once again

Post by adamkooo2 » 08 Aug 2018, 17:23

It would be nice if someone would know some information about this
/\rkady
Image

winnixxl
Posts: 6
Joined: 04 Oct 2015, 14:24

Re: Camera Effect Script - once again

Post by winnixxl » 10 Aug 2018, 01:20

A First Test Video :pop:
Far from perfect but im still quite happy
https://media.giphy.com/media/8ZhQm4nkp ... /giphy.gif

And its really annoying that I cant post links, images or videos :roll:

User avatar
TMarc
Posts: 14352
Joined: 05 Apr 2011, 19:10
Location: Europe
Contact:

Re: Camera Effect Script - once again

Post by TMarc » 10 Aug 2018, 07:59

Nice shot :thumbsup:
Yeah you don't have enough messages posted yet, it is part of the spam prevention.
Btw. I fixed the link for you :)
maniaplanet forum global moderator

Link list with FAQ, Support, Wiki, Tutorials, Community activities, and much more.

System specs: Intel i7-970 12GB RAM, nVidia GTX 970, Creative SB X-Fi, 2xSSD

winnixxl
Posts: 6
Joined: 04 Oct 2015, 14:24

Re: Camera Effect Script - once again

Post by winnixxl » 10 Aug 2018, 17:43

TMarc wrote:
10 Aug 2018, 07:59
I fixed the link for you :)
Thank you.
I wil be gone over the weekend, but post more updates next week

winnixxl
Posts: 6
Joined: 04 Oct 2015, 14:24

Re: Camera Effect Script - once again

Post by winnixxl » 13 Aug 2018, 23:41

Just a small update video today, gonna write more tomorrow.


User avatar
Miss
Posts: 1158
Joined: 05 Jan 2016, 11:34
Location: The Netherlands
Contact:

Re: Camera Effect Script - once again

Post by Miss » 14 Aug 2018, 03:34

Fixed your link again. That is super cool.

I'd like to add - it might be possible to simplify your AHK script a lot by using Openplanet scripts (see my signature). Not sure about the possibilities there as I haven't looked at MP's APIs for the maniatracker classes myself, but it might be worth checking out.
Forum moderator, opinions are my own. :thx:
Check out Image openplanet, the alternative Maniaplanet scripting platform! (Openplanet subforum)
I also stream on Twitch and tweet on Twitter.

User avatar
Demented
Posts: 1932
Joined: 07 Nov 2010, 13:17
Location: United States

Re: Camera Effect Script - once again

Post by Demented » 14 Aug 2018, 15:10

Wow! That's looking really cool. Can't wait to see what more you achieve with this project. :thumbsup:
CPU: Intel I7-4770 64Bit @ 3.4Ghz.
Ram: 16GB DDR3
GPU: Geforce GXT 1060 6GB DDR5
Windows: 7 Pro SP1 64bit

Post Reply

Return to “MediaTracker”

Who is online

Users browsing this forum: No registered users and 1 guest