|
struct Test_GuidesFromMeshModifier
|
|
(
|
|
function Test_UpdateGuidesOnMeshSelectionChange =
|
|
(
|
|
-- Create a 2x1 plane and select one of the faces but not the other
|
|
distributionObject = convertToPoly(Plane lengthsegs:2 widthsegs:1)
|
|
polyop.setFaceSelection distributionObject #{1}
|
|
|
|
max modify mode
|
|
|
|
-- Setup guides with surface comb
|
|
select distributionObject
|
|
|
|
guidesFromSurfaceModifier = Ox_Guides_from_Surface()
|
|
guidesFromSurfaceModifier.method = 4
|
|
guidesFromSurfaceModifier.numSegs = 2
|
|
guidesFromSurfaceModifier.useSubSel = true
|
|
modPanel.addModToSelection guidesFromSurfaceModifier
|
|
|
|
-- Only 4 guides should be generated because sub-selection is on
|
|
guidesCopy = instance distributionObject
|
|
convertTo guidesCopy GuidesObject
|
|
myGuides = ( guidesCopy.GetGuides() ).AsHair()
|
|
EAssert.AreEqual 4 (myGuides.NumRoots())
|
|
delete guidesCopy
|
|
|
|
-- Go out of sub-object mode
|
|
max create mode
|
|
|
|
-- Select the second face of the distribution mesh, this should result in extra 2 guides being generated
|
|
polyop.setFaceSelection distributionObject #{1,2}
|
|
|
|
guidesCopy = instance distributionObject
|
|
convertTo guidesCopy GuidesObject
|
|
myGuides = ( guidesCopy.GetGuides() ).AsHair()
|
|
EAssert.AreEqual 6 (myGuides.NumRoots())
|
|
delete guidesCopy
|
|
|
|
-- Cleanup
|
|
delete distributionObject
|
|
),
|
|
|
|
-- Make sure that changing distribution map updates the roots when not in modify mode
|
|
function Test_RootUpdateOnDistributionMapChangeWhenInCreateMode =
|
|
(
|
|
distributionObject = Plane lengthsegs:1 widthsegs:1
|
|
max modify mode
|
|
|
|
-- Setup guides with surface comb
|
|
select distributionObject
|
|
guidesFromSurfaceModifier = Ox_Guides_from_Surface()
|
|
guidesFromSurfaceModifier.method = 4
|
|
guidesFromSurfaceModifier.numSegs = 2
|
|
guidesFromSurfaceModifier.uvChannel = 1
|
|
modPanel.addModToSelection guidesFromSurfaceModifier
|
|
|
|
distributionMap = Checker()
|
|
guidesFromSurfaceModifier.distrMap = distributionMap
|
|
|
|
-- Record number of roots at present
|
|
guidesCopy = instance distributionObject
|
|
convertTo guidesCopy GuidesObject
|
|
myGuides = ( guidesCopy.GetGuides() ).AsHair()
|
|
initialRootCount = (myGuides.NumRoots())
|
|
delete guidesCopy
|
|
|
|
-- Go out of sub-object mode
|
|
max create mode
|
|
|
|
-- Change the checker map to be all black
|
|
distributionMap.color1 = color 255 255 255
|
|
|
|
-- Number of generated guides should have changed
|
|
guidesCopy = instance distributionObject
|
|
convertTo guidesCopy GuidesObject
|
|
myGuides = ( guidesCopy.GetGuides() ).AsHair()
|
|
EAssert.AreNotEqual initialRootCount (myGuides.NumRoots())
|
|
delete guidesCopy
|
|
|
|
-- Cleanup
|
|
delete distributionObject
|
|
),
|
|
|
|
function Test_DisplacementMapAndOffset =
|
|
(
|
|
distributionObject = Plane lengthsegs:1 widthsegs:1
|
|
max modify mode
|
|
|
|
-- Setup guides with surface comb
|
|
select distributionObject
|
|
guidesFromSurfaceModifier = Ox_Guides_from_Surface()
|
|
TestUtilities.SetGuidesFromMeshDefaults guidesFromSurfaceModifier
|
|
guidesFromSurfaceModifier.method = 2
|
|
guidesFromSurfaceModifier.numSegs = 2
|
|
guidesFromSurfaceModifier.guideLength = 10
|
|
guidesFromSurfaceModifier.randomness = 0
|
|
modPanel.addModToSelection guidesFromSurfaceModifier
|
|
|
|
-- Without Displacement
|
|
guidesFromSurfaceModifier.displacementMap = undefined
|
|
guidesFromSurfaceModifier.displacementOffset = 0
|
|
guidesCopy = instance distributionObject
|
|
convertTo guidesCopy GuidesObject
|
|
myHair = ( guidesCopy.GetGuides() ).AsHair()
|
|
ZeroDisplaceTip = 0
|
|
ZeroDisplaceRoot = 0
|
|
for i = 0 to ( myHair.NumRoots() - 1 ) do
|
|
(
|
|
hairRootPoint = myHair.GetPointT i 0
|
|
hairTipPoint = myHair.GetPointT i 1
|
|
ZeroDisplaceTip += hairTipPoint.z
|
|
ZeroDisplaceRoot += hairRootPoint.z
|
|
)
|
|
print ZeroDisplaceRoot
|
|
EAssert.AreNearEqual 0 ( ZeroDisplaceRoot )
|
|
|
|
--With Displacement (with middle grey map and double Guide's Length as offset, it should be at the top of each strands without displacement)
|
|
DisplacementMap = Checker ()
|
|
DisplacementMap.color1 = DisplacementMap.color2 = (color 255 255 255) / 2
|
|
guidesFromSurfaceModifier.displacementMap = DisplacementMap
|
|
guidesFromSurfaceModifier.displacementOffset = guidesFromSurfaceModifier.guideLength * 2
|
|
guidesCopy2 = instance distributionObject
|
|
convertTo guidesCopy2 GuidesObject
|
|
myHair2 = ( guidesCopy2.GetGuides() ).AsHair()
|
|
DisplaceRoot = 0
|
|
for i = 0 to ( myHair2.NumRoots() - 1 ) do
|
|
(
|
|
hairRootPoint = myHair2.GetPointT i 0
|
|
DisplaceRoot += hairRootPoint.z
|
|
)
|
|
EAssert.AreNearEqual ZeroDisplaceTip DisplaceRoot
|
|
|
|
-- Cleanup
|
|
delete distributionObject
|
|
delete guidesCopy
|
|
delete guidesCopy2
|
|
),
|
|
|
|
function Test_DisplacementMapChannels =
|
|
(
|
|
-- Create a plane with 1x1 segments (so that there are are no vertices going exactly down the middle)
|
|
local distributionObject = Plane lengthsegs:1 widthsegs:1
|
|
max modify mode
|
|
|
|
-- Create Mapping Channels
|
|
select distributionObject
|
|
for i = 1 to 2 do
|
|
(
|
|
uvwMapModifier = Uvwmap ()
|
|
uvwMapModifier.mapChannel = i
|
|
uvwMapModifier.length = distributionObject.length / i
|
|
uvwMapModifier.width = distributionObject.width / i
|
|
modPanel.addModToSelection uvwMapModifier
|
|
)
|
|
|
|
-- Setup guides with surface comb
|
|
select distributionObject
|
|
guidesFromSurfaceModifier = Ox_Guides_from_Surface()
|
|
modPanel.addModToSelection guidesFromSurfaceModifier
|
|
|
|
-- Set default parameters
|
|
guidesFromSurfaceModifier.method = 2
|
|
guidesFromSurfaceModifier.uvChannel = 1
|
|
guidesFromSurfaceModifier.count = 100
|
|
guidesFromSurfaceModifier.guideLength = 10
|
|
guidesFromSurfaceModifier.randomness = 0
|
|
guidesFromSurfaceModifier.NumSegs = 2
|
|
|
|
local DisplacementMap = Checker ()
|
|
DisplacementMap.color1 = black
|
|
DisplacementMap.color2 = white
|
|
guidesFromSurfaceModifier.displacementMap = DisplacementMap
|
|
guidesFromSurfaceModifier.displacementOffset = guidesFromSurfaceModifier.guideLength
|
|
|
|
--Bake 1-st Mapping Channel
|
|
guidesFromSurfaceModifier.uvChannel = 1
|
|
local guidesCopy1 = instance distributionObject
|
|
convertTo guidesCopy1 GuidesObject
|
|
local myHair1 = ( guidesCopy1.GetGuides() ).AsHair()
|
|
|
|
--Bake 2-nd Mapping Channel
|
|
guidesFromSurfaceModifier.uvChannel = 2
|
|
local guidesCopy2 = instance distributionObject
|
|
convertTo guidesCopy2 GuidesObject
|
|
local myHair2 = ( guidesCopy2.GetGuides() ).AsHair()
|
|
|
|
--Hairs Count should be the same
|
|
EAssert.AreEqual ( myHair1.NumRoots() ) ( myHair2.NumRoots() )
|
|
|
|
--Check for matching, if Mapping channel isn't affected, 100% points will be at the same position
|
|
matchedPoints = 0
|
|
for i = 0 to ( myHair1.NumRoots() - 1 ) do
|
|
(
|
|
RootPoint1 = myHair1.GetPointT i 0
|
|
RootPoint2 = myHair2.GetPointT i 0
|
|
if ( RootPoint1 == RootPoint2 ) then
|
|
(
|
|
matchedPoints += 1
|
|
)
|
|
)
|
|
EAssert.AreNotEqual matchedPoints ( myHair1.NumRoots() )
|
|
|
|
-- Cleanup
|
|
delete distributionObject
|
|
delete guidesCopy1
|
|
delete guidesCopy2
|
|
),
|
|
|
|
-- Tests that guides are positioned correctly when topology orientation option isn't used
|
|
function Test_GuidePlacementWithTopologyOrientationOff =
|
|
(
|
|
-- Create a plane with 1x1 segments (so that there are are no vertices going exactly down the middle)
|
|
local distributionObject = Plane lengthsegs:1 widthsegs:1
|
|
local distributionObjectCopy = convertto (copy distributionObject) mesh
|
|
max modify mode
|
|
|
|
-- Setup guides with vertex distributioon and topology orientation off
|
|
select distributionObject
|
|
local guidesFromSurfaceModifier = Ox_Guides_from_Surface()
|
|
TestUtilities.SetGuidesFromMeshDefaults guidesFromSurfaceModifier
|
|
guidesFromSurfaceModifier.method = 4
|
|
guidesFromSurfaceModifier.topoOrient = off
|
|
modPanel.addModToSelection guidesFromSurfaceModifier
|
|
|
|
-- Make sure vertices are not at the origin
|
|
local guidesCopy = instance distributionObject
|
|
convertTo guidesCopy GuidesObject
|
|
local myGuides = ( guidesCopy.GetGuides() ).AsHair()
|
|
EAssert.ArePointsNearEqual (getvert distributionObjectCopy 3) (myGuides.GetPointT 0 0)
|
|
EAssert.ArePointsNearEqual (getvert distributionObjectCopy 1) (myGuides.GetPointT 1 0)
|
|
EAssert.ArePointsNearEqual (getvert distributionObjectCopy 4) (myGuides.GetPointT 2 0)
|
|
EAssert.ArePointsNearEqual (getvert distributionObjectCopy 2) (myGuides.GetPointT 3 0)
|
|
|
|
-- Cleanup
|
|
delete guidesCopy
|
|
delete distributionObjectCopy
|
|
delete distributionObject
|
|
)
|
|
)
|
|
|
|
EUnit.AddTestClass Test_GuidesFromMeshModifier
|
|
ok
|