How to make inputs of multiple type in Fuses

User avatar
Chad
Fusionator
Posts: 1408
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 14 times

How to make inputs of multiple type in Fuses

#1

Post by Chad » Fri Sep 11, 2015 11:31 am

ploveday wrote:There are two ways this is commonly done by Tools in Fusion.
Thank you for the output example, but I have a question about the reverse, how do I allow an input to be multiple types? So let's say I had a tool that always output an image, but one of the inputs could be a number OR a gradient OR an image. It seems like we always define the input type and filter possible connections accordingly, so maybe this isn't possible?

The other option I have is to have a multibutton that chooses the type for the input and a NotifyChanged hides the current input and unhides the new input, but it would be much much better if this wasn't needed.

User avatar
Tilt
Global Moderator
Posts: 336
Joined: Sat Aug 02, 2014 4:10 am
Location: Munich, Germany
Contact:

Re: [Fuse] Time Machine Modifier Fuse

#2

Post by Tilt » Fri Sep 11, 2015 3:42 pm

It would be cool if Fusion had an "Any" input and output type that allowed you to programmatically reject connections. That way, a TimeStretcher or my Switch fuse could be inserted into both image and 3D streams. Right now you have an extra Retime3D for 3D tools. Chad has probably duplicated every tool for material workflows :-)

User avatar
Chad
Fusionator
Posts: 1408
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 14 times

Re: [Fuse] Time Machine Modifier Fuse

#3

Post by Chad » Fri Sep 11, 2015 4:42 pm

Hehe... that's actually what I really want. We have the number modifier toolset, want to use it with some material plugins. So BC3 would have material inputs for Gain, Lift, etc., but you could connect numbers to it too for uniform but animated control. But it's bugged me for the number tools too because points and numbers are so close.

Your Switch example is even better. Should be able to switch anything, right?

User avatar
PeterLoveday
Fusioneer
Posts: 146
Joined: Sun Sep 14, 2014 6:09 pm
Answers: 6
Been thanked: 16 times

Re: [Fuse] Time Machine Modifier Fuse

#4

Post by PeterLoveday » Wed Sep 16, 2015 6:03 pm

Chad wrote:
ploveday wrote:There are two ways this is commonly done by Tools in Fusion.
Thank you for the output example, but I have a question about the reverse, how do I allow an input to be multiple types? So let's say I had a tool that always output an image, but one of the inputs could be a number OR a gradient OR an image.
There are a couple of options, I guess.

One is to go the same way as publish, and use REGID_InputDataType in addition to the aforementioned REGID_DataType in the FuRegisterClass() call. This is what allows Publish to do Number->Number, Point->Point etc, and also tells Fusion what input type is available for "Insert" behaviour. However this doesn't really allow for an input that can connect to more than one type after the fact. The correct type of Publish is created for a certain situation, and it is then locked to that type.

If you want an input to be capable of handling more than one type, you can give it multiple datatypes (note the extra braces required to allow multiples):

Code: Select all

	InBlah = self:AddInput("Blah", "Blah",
		{ LINKID_DataType = "Image", },
		{ LINKID_DataType = "Number", },
		LINK_Main = 1,
		})
Then in Process() et al, you will need to check what you have:

Code: Select all

	local p = InBlah:GetValue(req)
	
	if istype("Image", p) then
		...
	elseif istype("Number", p) then
		...
	end
Love, Light and Peace,
- Peter Loveday

User avatar
Chad
Fusionator
Posts: 1408
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 14 times

Re: [Fuse] Time Machine Modifier Fuse

#5

Post by Chad » Wed Sep 16, 2015 7:52 pm

Whoa, that's simpler than I was expecting. Thank you, I am so excited to try this out!

User avatar
Tilt
Global Moderator
Posts: 336
Joined: Sat Aug 02, 2014 4:10 am
Location: Munich, Germany
Contact:

Re: [Fuse] Time Machine Modifier Fuse

#6

Post by Tilt » Sat Sep 19, 2015 6:25 am

cool!

Is there a function that allows you to reject connections? For example, to make sure that an input is of the same type as an output (or vice versa, depending on what was connected first). Or would you have to return nil in Process()?

User avatar
Chad
Fusionator
Posts: 1408
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 14 times

Re: How to make inputs of multiple type in Fuses

#7

Post by Chad » Thu Sep 24, 2015 11:01 am

Would this...

Code: Select all

   InBlah = self:AddInput("Blah", "Blah",
      { LINKID_DataType = "Image", },
      { LINKID_DataType = "Number", },
      LINK_Main = 1,
      })
Be conceptually equivalent to this...

Code: Select all

InMask = AddInput("Blah", "Blah",
	LINKID_DataType, CLSID_DataType_MtlGraph3D,
	LINKID_AllowedDataType, CLSID_DataType_Image,
?

User avatar
Kristof
Fusionista
Posts: 557
Joined: Thu Aug 07, 2014 1:30 pm
Answers: 1
Been thanked: 18 times

Re: How to make inputs of multiple type in Fuses

#8

Post by Kristof » Wed Nov 25, 2015 6:57 am

M'kay, I can't get this to work. I can see where the syntax is coming from--it looks similar to a ComboControl--and I think there's a "{" missing in the example posted above.

Anyway, I'm trying to make a more versatile wireless fuse:

Code: Select all

--[[-- 
Brutally Simple Fuse - used to wirelessly connect one 
part of a composition with another.
--]]--

FuRegisterClass("UberWireless", CT_Tool, {
	REGS_Name = "Uber Wireless Link",
	REGS_Category = "Fuses\\Misc",
	REGS_OpIconString = "UberWire",
	REGS_OpDescription = "UberWireless Link",
	REG_OpNoMask = true,
	REG_NoBlendCtrls = true,
	REG_NoObjMatCtrls = true,
	REG_NoMotionBlurCtrls = true,
	REG_SupportsDoD = true,
	})

function Create()

	InImage = self:AddInput("Input", "Input", {
		{ LINKID_DataType = "Image", },
		{ LINKID_DataType = "DataType3D", },
		INPID_InputControl = "ImageControl",
		LINK_Visible = false,
		})
		
	OutImage = self:AddOutput("Output", "Output", {
		LINKID_DataType = InImage:GetValue(req),
		LINK_Main = 1,
		})				
end

function Process(req) 
	local img = InImage:GetValue(req)
	
	OutImage:Set(req, img)
end