Jump to content
Developer Wiki and Function Reference Links ×

Render pane for plugin objects


Paolo

Recommended Posts

Objects 3D that are constructed within Vectorworks primitive tools (extrusions, extrusions along path, etc.) have full texture controls in the object render pane.

This is not true for custom plugin objects that creates parametric 3D objects, as far as I know…

Just the texture choice is available…

Is there a way to show all the options?

1351222714_Schermata2022-04-15alle11_25_43.png.31d814f1da608b00708f059f129c15f1.png

  • Like 1
Link to comment
  • 7 months later...

Hello Fabio,

in the simplest case, with just one object 3D created in the plugin, the "core" is in the following lines:

hTrim = vs.LNewObj() #hTrim is my 3D object I want to control the texture
					
from collections import namedtuple

Trim = namedtuple('Trims', ['trim'])
obj = Trim(hTrim);

if not vs.CustomTexPartExists(parmHand, 1000): #parmHand is the plugin's handle
	vs.SetTextureSet(parmHand,1)
	vs.RemoveCustomTexParts(parmHand)
	vs.AddCustomTexPart(parmHand, 1000, 'trim')
	vs.SetDefaultTexMapN(parmHand, 1000, 0)

vs.ApplyCustomTexPart(parmHand,obj.trim,1000);
setTexture(obj.trim, parmHand, 1000, materialChange, classChange)

 

The setTexture function (following) is where we set / get the OIP texture panel:

#************************ setTexture ************************#
def setTexture(h, hPio, idx, materialChange, classChange):
	#classes
	if not vs.PuseMaterials and materialChange:
		vs.SetClass(h, vs.GetClass(hPio))
		
		vs.SetTextureRefN(hPio, vs.GetClTextureG(vs.GetClass(h)), idx, 0)
		vs.SetTextureRefN(hPio, -1, idx, 0)

		vs.ResetObject(hPio)

	#*** material ***#
	if vs.PuseMaterials and materialChange:
		vs.SetClUseTexture(vs.GetClass(hPio), False)

		if vs.Pmaterials == '':
			MyList, NumItems = vs.BuildResourceList(19, 0, '')
			if NumItems == 0:
				MyList, NumItems = vs.BuildResourceList2(19, 345, '', True) #get it from the library
				
			#here I have at least the default material
			if NumItems > 0:
				result = vs.SetObjMaterialHandle(h, vs.GetObject(vs.GetNameFromResourceList(MyList, 1)))
				result = vs.SetObjMaterialHandle(hPio, vs.GetObject(vs.GetNameFromResourceList(MyList, 1)))
				vs.SetRField(hPio, vs.GetName(vs.GetParametricRecord(hPio)), 'materiale', vs.GetNameFromResourceList(MyList, 1)) #materiale is a parameter of type Material
				vs.SetRField(hPio, vs.GetName(vs.GetParametricRecord(hPio)), 'materials', vs.GetNameFromResourceList(MyList, 1))
		else:
			result = vs.SetObjMaterialHandle(h, vs.GetObject(vs.Pmaterials))
			result = vs.SetObjMaterialHandle(hPio, vs.GetObject(vs.Pmaterials))
			vs.SetRField(hPio, vs.GetName(vs.GetParametricRecord(hPio)), 'materiale', vs.Pmaterials)

		hMaterial = vs.GetObjMaterialHandle(h)
		textureRef = vs.GetMaterialTexture(hMaterial)
		vs.SetTextureRefN(hPio, textureRef, idx, 0)
		vs.SetTextureRefN(h, textureRef, 3, 0)
		
	if vs.PuseMaterials:
		result = vs.SetObjMaterialHandle(h, vs.GetObject(vs.Pmaterials))
		result = vs.SetObjMaterialHandle(hPio, vs.GetObject(vs.Pmaterials))
		
		if vs.Pmaterials == '':
			vs.ResetObject(hPio)

	#changes in OIP rendering
	if vs.GetTextureRefN(hPio, idx, 0, False) == -1 :
		vs.SetTextureRefN(h, vs.GetClTextureG(vs.GetClass(h)), 3, 0)
	else:
		vs.SetTextureRefN(h, vs.GetTextureRefN(hPio, idx, 0, False), 3, 0)

	if vs.GetTextureRefN(hPio, idx, 0, False) == 0 :
		vs.SetTextureRefN(hPio, 0, 3, 0)
             
	else:
		vs.SetTexMapInt(h, 3, 1, vs.GetTexMapIntN(hPio, idx, 0, 1));

		vs.SetTexMapBoolN(h, 3, 0, 1, vs.GetTexMapBoolN(hPio, idx, 0, 1))
		vs.SetTexMapBoolN(h, 3, 0, 2, vs.GetTexMapBoolN(hPio, idx, 0, 2))
		vs.SetTexMapBoolN(h, 3, 0, 3, vs.GetTexMapBoolN(hPio, idx, 0, 3))
		vs.SetTexMapBoolN(h, 3, 0, 4, vs.GetTexMapBoolN(hPio, idx, 0, 4))
		vs.SetTexMapBoolN(h, 3, 0, 5, vs.GetTexMapBoolN(hPio, idx, 0, 5))
		vs.SetTexMapBoolN(h, 3, 0, 6, vs.GetTexMapBoolN(hPio, idx, 0, 6))
		vs.SetTexMapBoolN(h, 3, 0, 7, vs.GetTexMapBoolN(hPio, idx, 0, 7))

		vs.SetTexMapRealN(h, 3, 0, 1,vs.GetTexMapRealN(hPio, idx, 0, 1))
		vs.SetTexMapRealN(h, 3, 0, 2,vs.GetTexMapRealN(hPio, idx, 0, 2))
		vs.SetTexMapRealN(h, 3, 0, 3,vs.GetTexMapRealN(hPio, idx, 0, 3))
		vs.SetTexMapRealN(h, 3, 0, 4,vs.GetTexMapRealN(hPio, idx, 0, 4))
		vs.SetTexMapRealN(h, 3, 0, 5,vs.GetTexMapRealN(hPio, idx, 0, 5))

 

The variables materialChange and classChange are triggered by the user acting on some parameters in the OIP:

# *** material change ***        
if vs.IsNewCustomObject(parmName):
	vs.SetObjectVariableBoolean(parmHand, 800, False)

result, widgID, prmIndex, oldValue = vs.vsoStateGetParamChng(parmHand)
if result or vs.GetObjectVariableBoolean(parmHand, 800):
	result, outWidgetID = vs.vsoPrmName2WidgetID('', 'materials') #materials menu managed in event kObjOnWidgetPrep and in setTexture
	if (widgID == outWidgetID):
		materialChange = True

	result, outWidgetID = vs.vsoPrmName2WidgetID('', 'useMaterials') #checkbox 
	if (widgID == outWidgetID):
		materialChange = True

	if vs.GetObjectVariableBoolean(parmHand, 800):
		materialChange = True
		classChange = True

	vs.SetObjectVariableBoolean(parmHand, 800, False)

 

Of course, in the case you have more materials in one plugin (such I have in some of my Mouldings Plugins), things get more complicated.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...