@@ -1587,17 +1587,49 @@ HUSD_Scene::lookupGeomId(const UT_StringRef &path)
15871587 if (entry != myDisplayGeometry .end ())
15881588 return entry -> second -> id ();
15891589
1590- return getOrCreateID (path , GEOMETRY );
1590+ // Path -> Render ID -> Hou Geom ID
1591+ auto rentry = myRenderIDs .find (path );
1592+ if (rentry != myRenderIDs .end ())
1593+ {
1594+ auto gentry = myRenderIDtoGeomID .find (rentry -> second );
1595+ if (gentry != myRenderIDtoGeomID .end ())
1596+ return gentry -> second ;
1597+ }
1598+
1599+ return -1 ;
15911600}
15921601
15931602
15941603void
15951604HUSD_Scene ::setRenderID (const UT_StringRef & path , int id )
15961605{
1597- myRenderIDs [path ] = id ;
1598- myRenderPaths [id ] = path ;
1599- int pid = getOrCreateID (path );
1600- myRenderIDtoGeomID [id ] = pid ;
1606+ int idx = path .findCharIndex ('[' );
1607+ if (idx != -1 )
1608+ {
1609+ UT_StringView base_v (path .c_str (), idx );
1610+ UT_StringHolder base (base_v );
1611+
1612+ int pid = getOrCreateID (base , INSTANCER );
1613+ auto node = myTree -> lookupID (pid );
1614+ if (node )
1615+ {
1616+ UT_StringView indices_v (path .c_str ()+ idx + 1 ,
1617+ path .length () - idx - 2 );
1618+ UT_StringHolder indices (indices_v );
1619+ int inst_id = node -> addInstance (indices , myTree );
1620+
1621+ myRenderIDs [path ] = id ;
1622+ myRenderPaths [id ] = path ;
1623+ myRenderIDtoGeomID [id ] = inst_id ;
1624+ }
1625+ }
1626+ else
1627+ {
1628+ myRenderIDs [path ] = id ;
1629+ myRenderPaths [id ] = path ;
1630+ int pid = getOrCreateID (path );
1631+ myRenderIDtoGeomID [id ] = pid ;
1632+ }
16011633}
16021634
16031635int
@@ -1919,6 +1951,18 @@ HUSD_Scene::convertSelection(const char *selection,
19191951 }
19201952}
19211953
1954+ bool
1955+ HUSD_Scene ::hasInstanceSelections ()
1956+ {
1957+ for (auto sel : mySelection )
1958+ {
1959+ auto type = getPrimType (sel .first );
1960+ if (type == INSTANCE )
1961+ return true;
1962+ }
1963+ return false;
1964+ }
1965+
19221966bool
19231967HUSD_Scene ::removeInstanceSelections ()
19241968{
@@ -1927,7 +1971,7 @@ HUSD_Scene::removeInstanceSelections()
19271971 for (auto sel : mySelection )
19281972 {
19291973 auto type = getPrimType (sel .first );
1930- if (type == INSTANCER || type == INSTANCE )
1974+ if (type == INSTANCE )
19311975 to_remove .append (sel .first );
19321976 }
19331977
@@ -1948,7 +1992,7 @@ HUSD_Scene::removePrimSelections()
19481992 for (auto sel : mySelection )
19491993 {
19501994 auto type = getPrimType (sel .first );
1951- if (type != INSTANCER && type != INSTANCE )
1995+ if (type != INSTANCE )
19521996 to_remove .append (sel .first );
19531997 }
19541998
@@ -2643,27 +2687,28 @@ HUSD_Scene::isSelected(int id) const
26432687 if (entry != node -> myIDPaths -> end ())
26442688 {
26452689 const UT_StringRef & instance = entry -> second ;
2646- UT_ASSERT (instance .startsWith (theQuestionMark ));
2647-
2648- // If nested, check if higher instance levels are selected.
2649- // Keep stripping off indices until the topmost instance is reached,
2650- // checking if the instancer is selected at each level.
2651- const int nest_level = instance .countChar (' ' ) - 1 ;
2652- for (int pass = 1 ; pass < nest_level ; pass ++ )
2690+ if (instance .startsWith (theQuestionMark ))
26532691 {
2654- const int idx = instance .lastCharIndex (' ' , pass );
2655- if (idx >= 0 )
2692+ // If nested, check if higher instance levels are selected.
2693+ // Keep stripping off indices until the topmost instance is
2694+ // reached, checking if the instancer is selected at each level.
2695+ // Instances generated from Render Delegates (setRenderID())
2696+ // can only have 1 nesting level and don't start with ?.
2697+ const int nest_level = instance .countChar (' ' ) - 1 ;
2698+ for (int pass = 1 ; pass < nest_level ; pass ++ )
26562699 {
2657- UT_StringHolder inst_key (instance .c_str (), idx );
2658- auto ientry = node -> myInstances -> find (inst_key );
2659- if (ientry != node -> myInstances -> end ())
2700+ const int idx = instance .lastCharIndex (' ' , pass );
2701+ if (idx >= 0 )
26602702 {
2661- if (mySelection .find (ientry -> second ) != mySelection .end ())
2703+ UT_StringHolder inst_key (instance .c_str (), idx );
2704+ auto ientry = node -> myInstances -> find (inst_key );
2705+ if (ientry != node -> myInstances -> end () &&
2706+ mySelection .find (ientry -> second ) != mySelection .end ())
26622707 return true;
26632708 }
2709+ else
2710+ break ;
26642711 }
2665- else
2666- break ;
26672712 }
26682713 }
26692714 }
0 commit comments