viewport.setCamera - playback


#1

Anyone knows why viewport.setCamera stops the playback? Any idea how we can recreate this function again without this problem?


#2

ha… topic suggestion sometimes works well enough
%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5


guess you can check prosequencer sources to find a solution


#3

Well, I’m looking for the function itself. What happen when the viewport will change to the camera view?


#4

C:\Program Files\Autodesk\3ds Max 2014 SDK\samples\maxscript\mxsagni\viewport.cpp
Value* VP_SetCamera_cf(Value **arg_list, int count)


#5

So, where this function comes from?

vpt.SetViewCamera(camnode);


#6

I found SetViewCamera in maxapi.h header
And that’s what the description says:

These are functions that are exported from the 3DS MAX executable.

But 3dsmax.exe doesn’t really export such function. It’s somewhere else among max dlls.


#7

using Serejah’s snippet you can do something like:

delete objects

cam1 = Freecamera()
cam2 = Freecamera()
cam1.pos = [100,100,100]
cam2.pos = [-20,-100,150]
cam1.dir = normalize cam1.pos
cam2.dir = normalize cam2.pos
Teapot()

cam0 = copy cam1

cam0.baseobject = cam1.baseobject

if (viewport.GetCamera() != cam0) do viewport.SetCamera cam0

unRegisterTimeCallback camSwitcher

fn camSwitcher = (
    
    if currenttime > 50 then (
        
        if (viewport.GetCamera() != cam0) do viewport.SetCamera cam0
		if cam0.baseobject != cam2.baseobject do 
		(
			print ">> camera2"
			cam0.baseobject = cam2.baseobject
		)
		if cam0.transform != cam2.transform do 
		(
			print "<< tm2"
			cam0.transform.controller = cam2.transform.controller
		)
        
    ) 
	else 
	(
        if (viewport.GetCamera() != cam0) do viewport.SetCamera cam0
		if cam0.baseobject != cam1.baseobject do 
		(
			print "<< camera1"
			cam0.baseobject = cam1.baseobject
		)
		if cam0.transform != cam1.transform do 
		(
			print "<< tm1"
			cam0.transform.controller = cam1.transform.controller
		)
        
    )

)

registerTimeCallback camSwitcher

sure that link constraint for cam0 will be better


#8

Brilliant! as always Denis!


#9

But my question still remained. Why SetCamera will stop the playback? while
actionMan.executeAction 0 “40068” – Views: Camera View
will not?


#10

And this is my version:

(
	delete objects
	cam1 = Freecamera()
	cam2 = Freecamera()
	cam1.pos = [100,100,100]
	cam2.pos = [-20,-100,150]
	cam1.dir = normalize cam1.pos
	cam2.dir = normalize cam2.pos
	Teapot()
)

(
	fn SwitchCamera cam range =
	(
		switched = false
		if isvalidnode cam and viewport.GetCamera() != cam and currenttime >= range.start and currenttime < range.end do
		(
			with redraw off
			(
			undo off
			(
			animate off
			(
				selTemp = selection as array
				select cam
				actionMan.executeAction 0 "40068"  -- Views: Camera View
				select selTemp
			)))
			switched = true
		)
		switched
	)
	
	fn TimeChangeCallbackFunction =
	(
		cams = for o in cameras where superclassof o == camera collect o
		ranges = #(interval 0 50,interval 50 100)
		switched = false
		for i = 1 to cams.count while switched == false do
		(
			switched = SwitchCamera cams[i] ranges[i]
		)
	)
	
	if Global_TimeChangeCallbackFunction == undefined do
	(
		global Global_TimeChangeCallbackFunction
		fn Global_TimeChangeCallbackFunction = TimeChangeCallbackFunction()
		registerTimeCallback Global_TimeChangeCallbackFunction
	)
)

#11
(
	with redraw off viewport.setcamera <camera>
)

#12

Provably because the viewport.setCamera() has a “Complete Redraw” flag being set to true, which does stop the animation and actionMan.executeAction() doesn’t.

MAXScript_TLS* _tls = (MAXScript_TLS*)TlsGetValue(thread_locals_index);
ObjectState os = camnode->EvalWorldState(MAXScript_time_tls());
if(os.obj && os.obj->SuperClassID() == CAMERA_CLASS_ID)
{
	vpt.SetViewCamera(camnode);
	needs_complete_redraw_set(_tls);
}

#13

:slight_smile: nice! Thank You!