[Closed] Extend Editable_Poly Geometry with Scripted Plugin
I want to create a scripted plugin to extend the Editable_Poly geometry class. I have run into some problems and have a question regarding this.
-
Will Graphite Modeling Tools work with scipted plugins that extend the Editable_Poly class?
-
How does one actually extend the class such that you can create it in the viewport and use it as an editable poly? Since you cannot actually create an epoly directly in MXS, you’d normally create some other object and then convertToPoly. But the nature of doing this inside a scripted plugin is confusing me.
Here is my plugin thus far… but it the object never displays in the scene… I don’t understand the program flow for the delegate (or maybe how to attach the delegate to a node…).
/*
Wall Worm Displacement Plugin
by Shawn Olson
[ http://www.shawnolson.net ]( http://www.shawnolson.net)
*/
plugin geometry wallworm_displacement
name:"Displacement"
classId:#(0x675a6691, 0x161e158e)
category:"WallWorm.com"
version:9
extends:Editable_Poly
(
local disp --the actual displacement mesh
local brsh --store the base plane
parameters main rollout:params (
disp_length type:#worldUnits ui:spn_length default:128
disp_width type:#worldUnits ui:spn_width default:128
disp_power type:#integer ui:rdo_power default:1
disp_mat type:#material ui:mat_pick
disp_lightmapScale type:#integer ui:spn_lightmap default:16
disp_noPhys type:#integer ui:chk_noPhys default:0
disp_noHull type:#integer ui:chk_noHull default:0
disp_noRay type:#integer ui:chk_noRay default:0
on power set val do
(
if brsh != undefined then (
--TODO: add function to store the current power's displacement offsets and recreate the displacements at new power as best as possible.
disp_power = val
brsh=undefined
this.createDisplacementPlane recreate:true
)
)
)
rollout params "Source Displacement" width:162 height:119
(
group "Geometry" (
spinner spn_length "Length:" range:[8,1024,128] type:#worldunits scale:1
spinner spn_width "Width:" range:[8,1024,128] type:#worldunits scale:1
label smtl_lbl "Set Displacement Material to:"
materialButton mat_pick "Pick Material"
)
group "Settings" (
radiobuttons rdo_power "Power" labels:#("2", "3", "4") default:1
spinner spn_lightmap "Lightmap Scale" range:[1,64,16] scale:1
checkbox chk_noPhys "No Phys"
checkbox chk_noHull "No Hull Collision"
checkbox chk_noRay "No Ray Collision"
)
)
function createDisplacementPlane recreate:false =(
if brsh == undefined OR recreate == true then (brsh = createInstance Plane)
brsh.width = disp_width
brsh.length = disp_length
local s = 4
case of (
(disp_power==1): (
s = 4
facesToRetriangulate = #{2, 4..5, 7, 10, 12..13, 15}
)
(disp_power==2): (
s=8
facesToRetriangulate =#{2, 4, 6, 8..9, 11, 13, 15, 18, 20, 22, 24..25, 27, 29, 31, 34, 36, 38, 40..41, 43, 45, 47, 50, 52, 54, 56..57, 59, 61, 63}
)
(disp_power==3): (
s=16
facesToRetriangulate =#{2, 4, 6, 8, 10, 12, 14, 16..17, 19, 21, 23, 25, 27, 29, 31, 34, 36, 38, 40, 42, 44, 46, 48..49, 51, 53, 55, 57, 59, 61, 63, 66, 68, 70, 72, 74, 76, 78, 80..81, 83, 85, 87, 89, 91, 93, 95, 98, 100, 102, 104, 106, 108, 110, 112..113, 115, 117, 119, 121, 123, 125, 127, 130, 132, 134, 136, 138, 140, 142, 144..145, 147, 149, 151, 153, 155, 157, 159, 162, 164, 166, 168, 170, 172, 174, 176..177, 179, 181, 183, 185, 187, 189, 191, 194, 196, 198, 200, 202, 204, 206, 208..209, 211, 213, 215, 217, 219, 221, 223, 226, 228, 230, 232, 234, 236, 238, 240..241, 243, 245, 247, 249, 251, 253, 255}
)
(disp_power==undefined): (
s = 4
facesToRetriangulate = #{2, 4..5, 7, 10, 12..13, 15}
)
default: (
s = 4
facesToRetriangulate = #{2, 4..5, 7, 10, 12..13, 15}
)
)
brsh.lengthsegs = s
brsh.widthsegs = s
disp = Editable_Mesh()
disp.mesh = brsh.mesh
convertToPoly disp
for i in facesToRetriangulate do (
disp.TurnDiagonal i 1
)
ConvertToMesh disp
notDone = true
while notDOne do (
local edges = disp.Edges
meshop.autoEdge disp edges 0 type:#SetClear
if edges.count == (disp.Edges).count do (
notDone = false
)
)
convertToPoly disp
delegate.mesh disp.mesh
update delegate.mesh
)
on buildMesh do
(
createDisplacementPlane()
)
on attachedToNode obj do
(
--TODO:not sure
)
tool create numPoints:3 (
local startPoint
on mousePoint click do coordsys grid (
case click of (
1: startPoint = nodeTM.translation = gridPoint
--2: nodeTM.translation = startPoint + gridDist/2
2: (#stop)
)
)
on mouseMove click do (
case click of (
2: (disp_width = abs gridDist.x; disp_length = abs gridDist.y;nodeTM.translation.x = startPoint.x + gridDist.x/2;nodeTM.translation.y = startPoint.y + gridDist.y/2)
)
)
)
) --end plugin
honestly there are so many things in your plugin made wrong and i don’t believe that you will be able to untangle it.
let’s start from beginning. what has the plugin to do?
Always Denis to the rescue!
This is my first step into scripted plugins rather than scripts, as you can tell. I started with a SimpleObject but since I want to be able to utilize Epoly methods and tools, switched to Geometry Plugin. In the SimpleObject version (before I posted this) I did get the mesh to appear in the viewport, but since switching to Geometry and extending Editable_Poly, I’m completely lost.
Essentially, the plugin needs to create an Editable Poly object, but have various parameters similar to a Plane() primitive (width, lengths, lengthsegs, widthsegs) as well as some other parameters used in the game engine (lightmap scale, etc).
The use should be able to create the basic shape like a Plane() primitive and control the base parameters like a Plane() but still be able to utilize all the Epoly methods.
My main goal is to get a good feel for creating scripted plugins … and after reading the entire section in MXS docs I kind of have a feel… but I’m not sure about accessing nodes from the plugin (in this specific example… how how to generate the scene node’s mesh for the extended epoly).
I noticed also that when extending a epoly, the modifier stack of the object does not show a + icon to go into sub-object mode… although in the modify panel it does show all the extended rollouts of an epoly and those specified in the scripted plugin.