How do I carry over identical texture mapping when exporting to DAE? - collada

I am able to open a 3DS file in MeshLab and when I export to Collada DAE format the textures are visible but they are not being projected onto the mesh in the same way as the preview in MeshLab. For example, the front/back faces of a cube would have the proper texture (suppose it's a polka dot) but the top and bottom have a striped look. How can I apply a single texture and have it appear as intended on all faces, like the imported model before I convert it?

This problem is a result of the end software being used to view the DAE file. It's not a problem with MeshLab.
For example, if loading the file into Away3D be sure to handle the texture materials using the TextureMaterial class instead of the simpler SinglePassMaterialBase such as what you might find in their example code. Here is what I use now, and it displays texture properly:
var material:TextureMaterial = cast(asset, TextureMaterial);
material.ambientColor = 0xffffff;
material.lightPicker = _lightPicker;
material.shadowMethod = new FilteredShadowMapMethod(_light);
material.lightPicker = _lightPicker;
material.gloss = 30;
material.specular = 1;
material.ambient = 1;
material.repeat = true;

Related

Creating layout PDFs by iterating feature selection and setting extent

In ArcGIS Pro 2.4, I need to create a PDF page of a map layout where the map frame is zoomed to each row in a feature class. Each feature in this class is a polygon. I'm relatively new to ArcPy so I'm learning as I'm going.
So far I've been messing with arcpy.SearchCursor, to iterate the selection of the features. Inside the cursor, I need to use mf.camera.setExtent(mf.getLayerExtent(selectedfeature)) and mf.camera.scale *= 1.05 so the polygon shows its surroundings for context. Then I've been trying to export the layout (lyt) to a PDF somewhere. There are 700 of these polgyons (each labelled as a alphanumerical map page) so it's best to do this with arcpy.
import arcpy
aprx = arcpy.mp.ArcGISProject(r"G:\ArcGIS Projects\project.aprx")
m = aprx.listMaps("Map")[0]
lyr = m.listLayers("PLSS Quarter Sections*")[0]
lyt = aprx.listLayouts("Paper Maps*")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "Sewer Sections*")[0]
fc = "PLSS Quarter Sections"
fields = ['OBJECTID']
cursor = arcpy.SearchCursor(fc)
row = cursor.next()
for row in cursor:
mf.camera.setExtent(mf.getLayerExtent(row, True, False))
mf.camera.scale *= 1.05
lyt.exportToPDF(r"G:\ArcGIS Projects\output.pdf")
It should move the map frame inside the layout to the selected feature, zoom out, and save that layout to a PDF. All it does it give a TypeError: 1. How would I go about doing this?
After asking around, ArcGIS Pro has a feature called Map Series that lets you make a series of maps based off a certain layer. In my case, it created 700 maps with a single polygon framed in the map frame in my layout. It's also much easier than scripting it by hand.

Insert 3D text to the front face of a cube GameObject

I want to add a text to a cube, which has a 3D text as a child. I am trying to write/show the text to the front face (or very close) of the cube.
I am using the below javascript to write on the 3D text:
#pragma strict
var countdown : int = 200;
function Update()
{
GetComponent(TextMesh).text = countdown.ToString();
}
EDIT: My difficulty is to make the text appear in the front side/face of the cube, like it is written on it.
My last failed try was to use the below lines:
var tm = gameObject.AddComponent(TextMesh);
tm.text = countdown.ToString();
Any ideas?
If the TextMesh object is a child of the cube, then what you'd want to use is:
transform.Find("TextMeshObjectName").GetComponent(TextMesh).text = countdown.ToString();
where TextMeshObjectName is the name of your TextMesh object. I'm also assuming the script is running from within the cube. There are of course other ways to find children as well, so if you like, take a look at this link here

d3.js geo - rendering svg path

I'd like to create choropleth map of Czech Republic. Inspired by this article http://bl.ocks.org/mbostock/4060606, I have created this
http://jsfiddle.net/1duds8tz/2/
var width = 960;
var height = 500;
var svg = d3.select("body").append("svg").attr("width", width).attr("height", height);
var offset = [width / 2, height / 2];
var projection = d3.geo.mercator().scale(6000).center([15.474, 49.822]).translate(offset);
var path = d3.geo.path().projection(projection);
queue().defer(d3.json, "..map.geojson").await(ready);
function ready(error, reg) {
var group = svg.selectAll("g").data(reg.features).enter().append("g");
group.append("path").attr("d", path).attr("fill", "none").attr("stroke", "#222");
}
When I tried to fill svg path with some color, I ended on this
http://jsfiddle.net/1duds8tz/3/
group.append("path").attr("d", path).attr("fill", "red").attr("stroke", "#222");
There are odd values in path d attribute.
My GeoJSON data must be somehow faulty but I can't figure what is wrong.
Everything looks right here: https://gist.github.com/anonymous/4e51227dd83be8c2311d
Your geoJSON is corrupted and as a result your polygons are being drawn as the interiors of an infinitely bounded polygon. That's why when you attempt to give a fill to the path, it goes beyond the extent of the screen but still displays the border just fine. I tried to reverse the winding order of your coordinates array, and that seemed to fix all of them except for "Brno-venkov", which might be the source of your problems (especially given its administrative shape).
I'd suggest going back to where you created the original GeoJSON and try to re-export it with simplification. If you want to reverse the coordinates on your GeoJSON to correct the winding order, that's pretty simple:
geodata = d3.selectAll("path").data();
for (x in geodata) {geodata[x].geometry.coordinates[0] = geodata[x].geometry.coordinates[0].reverse()}
But this won't fix the problem polygon, nor will not reversing its coordinates.
In case you are familiar with svg manipulation you can try geojson2svg. This allows you manipulate svg in standard way but you have to code a little more. In case your application requires d3 for many other purpose then d3 is best solution.
I've got exactly the same problem with Mapzen's .geojson files.
.reverse()-ing isn't good enough, if you can't make sure all your data has the same winding order.
I solved it with this one:
https://www.npmjs.com/package/geojson-rewind
You'll need to have npm & require available
Install it, and save it to your project
npm i -g geojson-rewind
Import it, to make it useable
var rewind = require('geojson-rewind');
Use it on the data, in this case:
req = rewind(req);
Tip: If you are working with static data, you can do this only once on the console, and you're good to go.

vtkMarchingCubes export nifti surfaces to wavefront OBJ

I want to run vtkMarchingCubes on a nifti label set. Regions of voxels, for which I want to produce surfaces all share the same value. I have two problems. First, I seem to be setting up the algorithm incorrectly because the resulting vtkPolyData apparently has no vertices. Secondly, it is not clear to me from the vtkOBJExporter documentation how to export the vtkPolyData as a wavefront .OBJ file. If anyone sees any issues with the code below or can tell me how to export the vtkPolyData as an OBJ, I would be grateful.
//Read The Nifti Label File
string input_path = "/MyPath/labels.nii";
nifti_image *im = nifti_image_read(input_path.c_str(),true);
cout<<im->nx<<","<<im->ny<<","<<im->nz<<endl; //Confirms Read Works
// Set up vtk image data
vtkImageImport* importer = vtkImageImport::New();
importer->SetImportVoidPointer((void*)im->data);
importer->SetDataScalarTypeToFloat();
importer->SetDataExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
importer->SetWholeExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
vtkImageData* point_cloud = importer->GetOutput();
point_cloud->SetScalarTypeToFloat();
point_cloud->SetExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
point_cloud->SetSpacing(im->dx, im->dy, im->dz);
//Apply Threshold To Cut Out Other Data
//Is this needed or will Marching Cubes properly identify the region
vtkImageThreshold* threshold = vtkImageThreshold::New();
threshold->ThresholdBetween(label_number,label_number);
threshold->SetInValue(255);
threshold->SetOutValue(0);
threshold->SetInput(point_cloud);
//Apply the Marching Cubes algorithm
vtkMarchingCubes* marching_cubes = vtkMarchingCubes::New();
marching_cubes->SetValue(0, 127.0f);
marching_cubes->SetInput(threshold->GetOutput()); //(vtkDataObject*)point_cloud);
vtkPolyData* surface = marching_cubes->GetOutput();
marching_cubes->Update();
//See That Marching Cubes Worked
cout<<"# Vertices: "<< surface->GetNumberOfVerts()<<endl;
cout<<"# Cells: "<< surface->GetNumberOfCells()<<endl;
//Export (How is this done properly?)
vtkOBJExporter* exporter = vtkOBJExporter::New();
exporter->SetInput(vtkRenderWindow *renWin); //I don't want a render window, I want at file
exporter->SetFilePrefix("/MyPath/surface");
exporter->Write();
You can use this class https://github.com/daviddoria/vtkOBJWriter to write the obj file in the way you would expect (like every other VTK writer). Unfortunately the vtkOBJExporter wants to also write additional information that I never have.

How to create a `pixelized' SVG image from a bitmap?

I have a 16x16 bitmap and want to create an SVG that contains 16x16 squares with the colors of the pixels of the image. Is there an easy way to achieve this?
My current thoughts go into the direction of using Python and PIL to read the bitmap image and dynamically create an SVG image file with the corresponding objects. But this feels a little clumsy and like reinventing the wheel.
Is there a better way to do this?
If you don't need the output to be SVG, I would suggest using an HTML5 Canvas where you can sample the pixels of the image client-side (using getImageData() on the context) and then draw your own up-scaled image. Or, if you need SVG, you could still use Canvas for the image sampling and then use procedurally-created <rect/> elements in SVG for each pixel.
I've written an example using just HTML Canvas so you can see how to do this. In short:
function drawPixelated(img,context,zoom,x,y){
if (!zoom) zoom=4; if (!x) x=0; if (!y) y=0;
if (!img.id) img.id = "__img"+(drawPixelated.lastImageId++);
var idata = drawPixelated.idataById[img.id];
if (!idata){
var ctx = document.createElement('canvas').getContext('2d');
ctx.width = img.width;
ctx.height = img.height;
ctx.drawImage(img,0,0);
idata = drawPixelated.idataById[img.id] = ctx.getImageData(0,0,img.width,img.height).data;
}
for (var x2=0;x2<img.width;++x2){
for (var y2=0;y2<img.height;++y2){
var i=(y2*img.width+x2)*4;
var r=idata[i ];
var g=idata[i+1];
var b=idata[i+2];
var a=idata[i+3];
context.fillStyle = "rgba("+r+","+g+","+b+","+(a/255)+")";
context.fillRect(x+x2*zoom, y+y2*zoom, zoom, zoom);
}
}
};
drawPixelated.idataById={};
drawPixelated.lastImageId=0;
If you really need SVG involved, I'd be happy to write an example that dynamically generated that.
Edit: OK, I've created an SVG version just for fun and practice. :)
As an aside (from an initial misreading of your question) this demo file from ASVG3 their old SVG Examples Page shows how to use some complex compositing of many different effects to create pixelation on arbitrary vector data. Unfortunately the demo does not load in Chrome, having been hardwired to require the (now-discontinued) Adobe SVG Viewer.

Resources