How do I set all display edges in a model to hard (in Maya 2017)? - maya

How do I set all display edges in a model to hard (in Maya 2017)?
I found a MEL script in a different post that lets you select all hard edges
(this one: polySelectConstraint -m 3 -t 0x8000 -sm 1;),
but I want to turn all display edges to hard, not just select them. I want to do this because I didn't build my model out of primitives and it's overly complex, (importing from SketchUp). The only way I can think to do this is individually select each and every mesh component and set it manually. But I feel there must be a MEL script that might do the trick, does anyone know of one?

the relevant command is polySoftEdge -- if you set the angle to something lower than the angle between the faces the edge will be hard; if you set it to something higher it will be soft.

Related

How can I smooth the seam from merged geometry in Maya?

I'm not sure if this is a geometry problem or a normal problem but I am having a hard time combining meshes without leaving a "seam" or visible discontinuity. In the example below I have a simple example with two sphere polygons with matching divisions. I have done a union and merged nearby vertices. I then tried to do a little manual adjustment to smooth it, but as you can see the result is not good.
I know that I can use the smooth tool to smooth it by adding new geometry, but I feel like given that the vertices match perfectly here I should be able to fix this through some other means. I've played with "soften edge normals" but I don't see any effect from that. I've tried averaging vertices but that doesn't seem to do much. I've gone to the sculpting tools and using the relax and smooth tools there... No matter how correct the geometry looks to me it still appears discontinuous unless I use the add-geometry smoothing tool.
What is the correct way to merge geometry like this?
thanks.
UPDATE:
I'm going to mark the answer below correct even thought it is basically one of the procedures I tried before. I think the real answer is that I just wasn't performing the merge very well (cutting the geometry and merging the edges in the cleanest way possible) prior to softening the edge.
Here is how to merge geometry and get rid of unpleasant seam from scratch:
a) Delete a history for each object (Edit–>DeleteByType–>History)
b) Combine a mesh (Mesh–>Combine)
c) Merge the edges, controlling a tolerance (EditMesh–>Merge)
d) Soften the edges, controlling an angle (MeshDisplay–>SoftenEdge)
Remember, Angle parameter makes the edge hard/soft.
Here are MEL equivalents:
// Deleting a history
DeleteHistory;
// Combining a mesh
polyUnite;
// Merge border edges within a given threshold
polySewEdge;
// Softening the edge (angle = 0...180)
polySoftEdge;
MEL example for softening the edge:
select -r pSphere2.e[35:54];
polySoftEdge -a 180;

Generate MEL to rebuild a model in Maya

I made a 3D tree in Maya and need MEL code to run in a for loop and generate as many trees as I want. Is there any way to convert a model made in Maya into MEL code that would rebuild the tree?
I can't just duplicate it because the script needs to generate the tree from scratch. Unfortunately, I cleared my history because it was messy, so I am looking for a way to generate the MEL code given just the geometry.
It is slightly unfortunate that you deleted the history. If you had not then you could have just built a script out if the history tree. But all is not lost, still i will explain how you can do this in case you do remake the history at some point.
The complexity of your history is never really a issue, at least when modeling. I would advice to not delete any history until your sure its of no use. Having a 1000 node history is not in any way slowing you down since most of it is inactive. Its only a problem once you enter animation even then its not necessarily a problem at all. Since the history deletion is a bit destructive its a good idea to save the scene when you are deleting big areas of history. So rule of thumb do not delete history and use the freeze transformation operation unless its really necessary (and it may be you never actually do this).
Another side remark: Copying stuff is still valid, unless like in this case there is a artificial limitation. The only time when this limitation is valid is if this is homework (in which case you may want to demonstrate that your willing to follow instruction). Doing a copy does not detract in any way the end result. Copying is mel (and all maya ascii files are mel of sorts).
Method 1: (when history is cleared)
You can reduce the problem to a normal rigging operation. What you do is you rig the tree that you built with bones, clusters and possibly blend shapes. Then just randomize the channels of your rig on each copy operation. The neat thing here is that the script can be easily extended with different base trees, or just about anything, just by making new separate rigs.
The bonus here is that you could now also easily animate the tree being blown by the wind etc.
This might feel like something outside the scope of the assignment. However a good MEL programmer does not really separate tasks. Using a node to do something is just as valid, if not more valid, as writing everything in code. Something like this demonstrates really thorough understanding of maya use and maya programming. On the other hand not all users are as enlightened (most are not).
Everything in Maya is or at least should be a rig. (the auxiliary to this is that your mel should strive to build a rig or you should use API to make nodes)
Method 2: (when history is cleared)
Chunk your result into pieces. Then randomize the chunk positions with L-system like rule based generator. It may seem counter intuitive to use a L-system with hand modeled pieces when the entire thing could be generated with a L-system.
But clunking allows for a very simple l-system to be built. The end result also retains the artistic integrity of the original in some ways that might be much more pleasing.
A slightly different version of this and method 3 is to make 2-3 overlapping set of branches in the model and then randomly delete branches for variation.
Method 3: (when history is cleared)
Cheat, well i would actually argue that in CG there's no such thing as cheating. Just copy the same tree about, alter its rotation ans scale. And randomize new shaders to your model (swap different leaf textures different color etc). When combined with even slight amount of rigginng approach can totally hide the fact that there is just one tree. Copies dont have to be all that exact they might be shaped with a lattice or something. This is actually pretty efficient, most people wouldn't notice.
Method 4: (when history is not cleared)
When you model something manually maya records this quite efficiently. The history can be turned into a script with little or no effort. The best kept secret. If you save this kind of scene as maya ascii then the maya ascii file is (almost) just mel and you can repeat this by adding variables to the stream to instrument it to mel. Beware tough that not all tools build meaningful history so point tweaks should be done on clusters instead on manual point tweaking that ends up in the shapes tweak array.
It is also possible to build the mel automatically with a mel script that checks for connections and values in nodes to reproduce the thing in code. The good thing is that you can readily introduce the instrumentation. Here's a really old version of code as giveaway (you need to handle the shaders and inputComponents for example):
/* jooConvertNodeNetworkToMelLadder.mel 0.0
Authors: Janne 'Joojaa' Ojala
Testing: Has known bugs, code deprecated, no bug reporting
Licence: Creative Commons Attribution-ShareAlike 3.0 Unported
About:
A deprecated early version of code generation it has some bugs and
is nowhere near perfect but you can have this code for the heck of
it. Main thing missing is that it does not check for selection
sets for nodes so you need to make those manually.
Install Instructions:
copy jooConvertNodeNetworkToMelLadder.mel to your maya script
directory
Usage:
Select node and run jooConvertNodeNetworkToMelLadder from mel
commandline.
Deprecated at 31.12.2006
*/
proc string generateAttrib(string $node, string $createNode,
string $attrib,string $varName){
string $return="";
if (getAttr($node + "." + $attrib) !=
getAttr($createNode + "." + $attrib))
$return = (" setAttr (" +
$varName + "+\"." + $attrib+"\") "+
getAttr($node + "." + $attrib) + ";\n");
return $return;
}
proc string doOneNode(string $nodeOrig,string $connections[]){
string $hist[]=`listConnections -c 1 -p 1 $nodeOrig`;
string $return="";
$type=`nodeType $nodeOrig`;
$varName=("$"+$nodeOrig);
$createNode=`createNode $type`;
$return=(" "+$varName+"=`createNode -n "+$nodeOrig+" "+$type+"`;\n");
if ($type != "mesh") {
for ($attrib in `listAttr -settable -multi -w -scalar $createNode`){
$return += generateAttrib($nodeOrig, $createNode,
$attrib, $varName);
}
}
delete $createNode;
for ($i=0;$i< size($hist);$i=$i+2){
if (size(`connectionInfo -dfs $hist[$i]`)){
string $node,$port,$type,$nodeOrig,$portOrig;
$node=`match "[^.]*" $hist[$i+1]`;
$port=`match "[.].*$" $hist[$i+1]`;
$nodeOrig=`match "[^.]*" $hist[$i]`;
$portOrig=`match "[.].*$" $hist[$i]`;
$connections[size($connections)]=
(" connectAttr -f ($" +
$nodeOrig + "+\"" + $portOrig + "\") ($" +
$node+"+\""+$port+"\");");
}
}
return $return;
}
global proc jooConvertNodeNetworkToMelLadder()
{
print "\n// jooConvertNodeNetworkToMelLadder result:\n{\n";
string $a[]={};
for ($node in `listHistory`)
print(`doOneNode $node $a`);
print $a;
print "}\n";
}
But this is all I have time for, hope this helps.

best method of turning millions of x,y,z positions of particles into visualisation

I'm interested in different algorithms people use to visualise millions of particles in a box. I know you can use Cloud-In-Cell, adaptive mesh, Kernel smoothing, nearest grid point methods etc to reduce the load in memory but there is very little documentation on how to do these things online.
i.e. I have array with:
x,y,z
1,2,3
4,5,6
6,7,8
xi,yi,zi
for i = 100 million for example. I don't want a package like Mayavi/Paraview to do it, I want to code this myself then load the decomposed matrix into Mayavi (rather than on-the-fly rendering) My poor 8Gb Macbook explodes if I try and use the particle positions. Any tutorials would be appreciated.
Analysing and creating visualisations for complex multi-dimensional data is complex. The best visualisation almost always depends on what the data is, and what relationships exists within the data. Of course, you are probably wanting to create visualisation of the data to show and explore relationships. Ultimately, this comes down to trying different posibilities.
My advice is to think about the data, and try to find sensible ways to slice up the dimensions. 3D plots, like surface plots or voxel renderings may be what you want. Personally, I prefer trying to find 2D representations, because they are easier to understand and to communicate to other people. Contour plots are great because they show 3D information in a 2D form. You can show a sequence of contour plots side by side, or in a timelapse to add a fourth dimension. There are also creative ways to use colour to add dimensions, while keeping the visualisation comprehensible -- which is the most important thing.
I see you want to write the code yourself. I understand that. Doing so will take a non-trivial effort, and afterwards, you might not have an effective visualisation. My advice is this: use a tool to help you prototype visualisations first! I've used gnuplot with some success, although I'm sure there are other options.
Once you have a good handle on the data, and how to communicate what it means, then you will be well positioned to code a good visualisation.
UPDATE
I'll offer a suggestion for the data you have described. It sounds as though you want/need a point density map. These are popular in geographical information systems, but have other uses. I haven't used one before, but the basic idea is to use a function to enstimate the density in a 3D space. The density becomes the fourth dimension. Something relatively simple, like the equation below, may be good enough.
The point density map might be easier to slice, summarise and render than the raw particle data.
The data I have analysed has been of a different nature, so I have not used this particular method before. Hopefully it proves helpful.
PS. I've just seen your comment below, and I'm not sure that this information will help you with that. However, I am posting my update anyway, just in case it is useful information.

Solr4 spatial troubleshooting polygons

I am trying to troubleshoot Solr4 and its spatial capabilities.
I have a document indexed with a field “geo”.
In it I have the following
Latitude -34.7413
Longitude 149.7102
Stored as <geo>-34.741328,149.710238</>
I have also tried indexing the same document as
<geo> 149.710238 -34.741328
which is suggested if you are not comma separating the values (reverse the lat/long order and put a space between the values).
The docs index just fine.
I am attempting to send it a polygon search. The polygon is a triangle shape and if you can imagine the below 3 points of the triangle are in clockwise order. It’s a very large triangle with the target coordinate in the middle somewhere. I chose a triangle in the hopes of a simple debug, I intend to have much more complicate shapes drawn for these searches
(-34.580136904223494, 149.6165823974609)
(-34.84203933395146, 150.0175833740234)
(-34.84654761634415, 149.4627738037109)
I have sent Solr the following queries and get errors.
fq=geo:"Intersects(POLYGON(-34.5801 149.6165, -34.8420 150.0175, -34.8465 149.4627))"
My attempt at a triangle.
fq=geo:"Intersects(POLYGON(-34.5801 149.6165, -34.8420 150.0175, -34.8465 149.4627, -34.5801 149.6165))"
My attempt at a triangle adding the last co ordinate again in order to “close” the polygon.
The above 2 queries return no results only the following error.
ERROR 500
Unable to read: POLYGON(-34.5801 149.6165, -34.8420 150.0175, -34.8465 149.4627, -34.5801 149.6165)
My question I guess is where to first look? I have JTS library installed. Solr Log records this.
19:11:50
SEVERE
SolrDispatchFilternull:com.spatial4j.core.exception.InvalidShapeException: Unable to read: POLYGON((-34.5801 149.6165, -34.8420 150.0175, -34.8465 149.4627))
Thanks for any pointers anyone can provide. I think the problem is either a solr config issue, somehow something isn’t installed right, the way im sending it coordinates and shapes, or something else I am missing.
OK, so i think after days on this i fixed it with the help of David Smiley who pops up all over the internet helping myself and others with their Solr Spatial issues - If we ever meet I will pour many a beer into you - thanks for your help.
YOU must reverse the lat/long of each co-ord (long/lat instead) and it worked. Straight away. So.Simple.
fq=geo:"Intersects(POLYGON((149.4023 -34.6072, 149.4023 -34.8690, 149.9022 -34.8690, 149.9022 -34.6072, 149.4023 -34.6072)))"
instead of this
fq=geo:"Intersects(POLYGON((-34.6072 149.4023, -34.8690 149.4023, -34.8690 149.9022, -34.6072 149.9022, -34.6072 149.4023)))"
Hopefully this thread helps others.
When in doubt the things I tried to debug this where as follows.
1. Unpack the solr.war file and save it as a folder instead of a file. There are many ways to do this depending on your server. For amateurs like me, configserver explorer, a whm plugin, is your friend :).
2. Download the jts plugin, unzip it, inside the /lib/ folder there was a file jts-1.12.jar - this it the money file.
3. Upload this to your solrinstall/solr.war/WEB-INF/lib/ location - you know that your in the right place when you see many other .jar files in there
4. If you want you can repack the war file, or it should work unpacked like this.
5. Make sure your schema is EXACTLY as it says in the solr wiki here. It is not there by default. Check and check again. Add this
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
spatialContextFactory="com.spatial4j.core.context.jts.JtsSpatialContextFactory"
distErrPct="0.025"
maxDistErr="0.000009"
units="degrees"
/>
and add your field "geo" in the following manner.
<field name="geo" type="location_rpt" indexed="true" stored="true" multiValued="true" />
Index your data. My data is in a Lat/long order and looks like this.
geo : -34.741328,149.710238
Remember Lat=horizontal, Long=Vertical lines.
6. Test your search by using the Lucene method of searching. There is a very simple rectangular search you can do. Find your target documents GEO point, then find a co-ordinate on the bottom left hand corner, and the top right hand corner. All you need for a rectangle is 2 points and you simply do a range search. For me it looks like this.
fq=geo:[-34.8690,149.4023 TO -34.6072,149.9022]
If that works you have basic GEO searching working.
Now lets make a polygon out of those co-ordinates. To make a polygon (rectangle shape in this case) we need 5 co-ords, the starting one, 3 other points of the rectangle, and then the starting co-ord again in order to close the shape(polygon).
For whatever reason, polygon searches use a different lat/long layout. You must reverse this. You put the LONGITUDE FIRST. You must also construct this shape in COUNTER-CLOCKWISE format. So a polygon search using points constructed of the above co-ordinates looks like this.
fq=geo:"Intersects(POLYGON((149.4023 -34.6072, 149.4023 -34.8690, 149.9022 -34.8690, 149.9022 -34.6072, 149.4023 -34.6072)))"
As you can see, the lat/long is long/lat, each long/lat is seperated by a space, and each co-ord pair is seperated by a comma ",".
Hopefully this thread helps others.
fq=geo:"Intersects(POLYGON(-34.5801 149.6165, -34.8420 150.0175, -34.8465 149.4627, -34.5801 149.6165))"
You almost had it right. Yes you need to close the polygon, and you did here. But you're missing an extra pair of parenthesis around the coordinate list:
fq=geo:"Intersects(POLYGON((-34.5801 149.6165, -34.8420 150.0175, -34.8465 149.4627, -34.5801 149.6165)))"
The extra parenthesis is because there could be multiple lists of coordinates. The first list is the outer ring, the subsequent lists are inner rings, AKA holes. This is standard WKT.

Detect signs on roads

I have a video which has got turn left,turn right etc marks on the roads.
I have to detect those signs.I am going ahead with template matching in which I am matching the edge detected outputs,But I am not getting satisfactory results,Is there any other way to detect it? Please help.
If you want a solution that is not too complicated but more robust than template matching, I suggest you'd go for Hough voting on SIFT descriptors. This method is provides some degree of robustness to various problems, including partial occlusion of the sign, illumination variations and deformations of the sign. In particular, the method is completely invariant to rotation and uniform scaling of the template object.
The basic idea of the algorithm is as follows:
a) extract SIFT features from the template and query images.
b) set an arbitrary reference point in the template image and calculate, for each keypoint in the template image, the vector from the keypoint to the reference point.
c) match keypoints from the template image to the query image.
d) cast a vote for each matched keypoint for all object locations in the query image that this keypoint agrees with. You do that using the vectors calculated in step (b) and the location, scale and orientation of the matched keypoints in the query image.
e) If the object is indeed located in the image, the votes map should have a strong local maximum at it's location.
f) Optionally, you can verify the detection by using template matching.
You can read more about that method on Wikipedia here or in the original paper (by D. Lowe) here.
Using SIFT or SURF. You can get the invariable descriptor with training you can determine if the vector that represent the road marks (turn left, right or stop) match with the new in the video.
You might try extracting features and training a classifier (linear discriminant, neural network, naive Bayes, etc.). There are many candidate features you might try, but I'd think that you wouldn't need anything too complicated, even if the edge detection is poor, assuming that isolation of the sign is good. Some features to consider are: horizontal and vertical projections (row and column totals) and simple statistics of edge pixels (mean, standard deviation, skewness, etc. For more feature ideas, see any of these books:
"Shape Classification and Analysis: Theory and Practice", by Costa and Cesar
"Algorithms for Image Processing and Computer Vision", by J. R. Parker
"Digital Image Processing", by Gonzalez and Woods

Resources