Notifications
Clear all

[Closed] viewport.setCamera – playback

 MZ1

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

12 Replies
1 Reply
(@polytools3d)
Joined: 1 year ago

Posts: 0
(
	with redraw off viewport.setcamera <camera>
)

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

 MZ1

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

1 Reply
(@serejah)
Joined: 1 year ago

Posts: 0

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

 MZ1

So, where this function comes from?

vpt.SetViewCamera(camnode);

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.

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

 MZ1

Brilliant! as always Denis!

 MZ1

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

 MZ1

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
	)
)

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);
}
Page 1 / 2