Loading OBJ file in three.js - three.js

I was trying to visualize a simple 3D model of the cylinder on the browser by importing OBJ file in three.js. I started with running simple example of three.js's OBJ loader:
https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_obj.html
which works fine locally.
I tried just by replacing the path of OBJ file with that of mine, but it failed to load. I double check the Path and it is correct.
On checking errors on the console on Firefox (Crtl + Shift + k), it says: Syntax Error and throws following error:
[22:59:30.865] Error: WebGL: DrawElements: bound vertex attribute buffers do not have sufficient size for given indices from the bound element array # http://localhost/~harmanpreet/three.js/build/three.min.js:455
The OBJ file is converted from model made in BRL-CAD (.g to .obj conversion). Link to OBJ file: http://devplace.in/~harman/cyl1_bot_dump.obj
Can anybody figure out what is the problem?
Thank you

Your .obj file looks correct according to specs, but I would advise you to use a non-minified three.js version and then look at the code surrounding the error message.
Also what you could try is replacing the "g" in the obj file at start with an "o" (g = group, o = object) - I'm not sure how three.js handles this internally or if it makes a difference, but I guess it won't hurt to try.
Other than that the error seems to be saying something like "I encountered an array index which is out of bounds", meaning a face (f in the .obj file) uses an index which is higher than the highest defined index, but that doesn't seem to be the case with your file (.obj indexes start at 1, so everything should be fine).

Related

PyQGIS - wrapped C/C++ object of type QgsVectorLayer has been deleted when editing the layer

I'm currently developing a QGIS plug-in.
When i start editing a layer either with with edit(QgsVectorLayer) or with QgsVectorLayer.startediting() this RuneTimeError happens the majority of runs: RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted. I can run 10 times the script and have no error and then run it another 10 times and get 10 times in a row the error. It feels completely random.
As i understood by reading post such as Understanding the "underlying C/C++ object has been deleted" error it might be a garbage collector problem C++ side. But none of the post i saw was about QgsVectorLayer so i'm not really sure it applies.
It really annoys me to the point where i start creating empty layers to store modified features instead of editing.
I tried to move start editing before the loop as i was thinking to continually start editing and commit changes for each feature might cause the issue but the error still appears.
Then i thought it might be the use of break at the end but removing it doesn't resolve the error.
As it is the first time i really use PyQGIS i spent sometimes reading the developer cookbook or searching online (Anita Graser - creating and editing a new vector layer) but i could not find any solutions.
I tried with different version, LTR or not. With another computer by despair but the issue is still here.
I also read somewhere that the progress bar was the issue, so i removed the feedback in my script also without success.
Here are some code example :
nodesLayer = self.parameterAsVectorLayer(parameters, self.INPUT_NODE, context)
arcsLayer = self.parameterAsVectorLayer(parameters, self.INPUT_LINE, context)
# Fill node Id_line_x
# Create spatial index
index = QgsSpatialIndex(nodesLayer.getFeatures())
for line in arcsLayer.getFeatures():
# Construct a geometry engine to speed up spatial relationship
engine = QgsGeometry.createGeometryEngine(line.geometry().constGet())
engine.prepareGeometry()
# Get potential neighbour
candidateIds = index.intersects(line.geometry().boundingBox())
request = QgsFeatureRequest().setFilterFids(candidateIds)
for node in nodesLayer.getFeatures(request):
# Get real neighbour
if engine.intersects(node.geometry().constGet()):
# Fill the Id_line fields for the number of neighbour
for fld in range(1, node["Nb_seg"] + 1):
if node["fk_Id_line_%d" %fld] == NULL:
with edit(nodesLayer):
node["fk_Id_line_%d" %fld] = line["Id_line"]
nodesLayer.updateFeature(node)
break
And the exact error :
Traceback (most recent call last):
File "/some/path/to/a/file.py", line 331, in processAlgorithm
nodesLayer.updateFeature(node)
RuntimeError: wrapped C/C++ object of type QgsVectorLayer has been deleted
Hope the example is enough. The goal of the code is for the nodes to be aware of their surroundings without going through the lines. it's just for treatment and those fields would be removed in the final output.

Projection of a SpatialPixelsDataFrame objects

I have created SpatialPixelsDataFrame objects from Raster files. But I cannot work it along with my SpatialPintsDataFrame object. I got this error message:
Error in count.points(GPSLocs, Grass) : different proj4string in w and xy
which means the SpatialPixelsDataFrame objects do not have a projection defined.
GPSLocs= SpatialPointsDataFrame object
Grass= SpatialPixelsDataFrame object
Any suggestions of how to fix this issue?
The message "different proj4string in w and xy" suggest that the coordinate reference systems are different (it may be that one of them is undefined). For others to be able to help you, should always show some code or data. For example what you get when you do:
library(raster)
w
xy
# or
crs(w)
crs(xy)

TypeError: cannot concatenate 'str' and 'pygame.Surface' objects

I am currently teaching myself game programming, and I've started nice and easy with pygame. I went through a tutorial that showed me how to build a simple game, and now that I am finished with it, I am in the process of trying to reorganize the code in a manner that makes sense to me, and also to edit it and add to it.
Part of what I tried to change is that instead of loading one '.png' file for a character, I load a list of them that will be iterated through in a 'move()' function I designed to make the characters look like they are moving. However I keep running into an error and I don't know why. Near the beginning of my code (all I've done is imported necessary modules and initialized pygame and some necessary variables) I tried to do the following code:
badguyimgs = ['badguy.png', 'badguy2.png', 'badguy3.png', 'badguy4.png']
for img in badguyimgs:
badguyimgs.append(pygame.image.load("resources/images/" + img))
badguyimgs.remove(img)
I keep getting the following error:
TypeError: cannot concatenate 'str' and 'pygame.Surface' objects
So far I have tried to initialize a new variable (resource = "resources/images/" + img) and place that at the beginning of the "for" loop and then insert that into the pygame.image.load(). I've also tried using os.path.join("resource/images/" + img). I've tried using the full path name ("c:\\Users\\ . . . \\resources\\images\\" +img). But any time I try to concatenate the pathname with the file name in the list, I get the above error code. I tried looking in the pygame documentation, but didn't see anything that helped in this situation. I've tried googling the error, but get nothing in reference to this. (a lot of issues with people tring to concatenate int types to strings though. . . ) I would appreciate any help anyone could give in pointing out why I am experiencing this, and what could fix it. Thanks.
It looks like what you're doing is appending the pygame.surface object (that you loaded from a png file) to the list while you're iterating through it. You are loading the images successfully. However after your function adds the first image and removes the string, your list looks like this:
badguyimgs = ['badguy2.png', 'badguy3.png', 'badguy4.png', pygame.image]
You are still iterating through the list, so your function starts trying to concatenate the string and the pygame.surface object. I would recommend creating an empty list, and add your loaded images to that list without adding or removing anything from the original. Hope this helped!
Here's an example to go with PlatypusVenom's explanation:
file_names = ['badguy.png', 'badguy2.png', 'badguy3.png', 'badguy4.png']
images = []
for file_name in file_names:
images.append(pygame.image.load("resources/images/" + file_name))
Now the pygame.Surface objects are in images, and the variable names for the lists are less confusing. Another option is to use a list comprehension:
images = [pygame.image.load("resources/images/" + file_name) for file_name in \
("badguy.png", "badguy2.png", "badguy3.png", "badguy4.png")]
This is similar to what you were going for in the code posted. The list of strings will be removed from memory, leaving only pygame.Surface objects in the images list.

Hand-Generated TopoJSON not Parsing

I wrote a simple function to parse a the results of d3.geom.voronoi into topoJSON format, which you can see here:
http://bl.ocks.org/emeeks/9908143
As far as I can tell, it matches up with the topoJSON generated in http://bl.ocks.org/mbostock/5249328 except that it doesn't use translate or scale (though I've generated it with a translate of (0,0) and a scale of (1) and received the same error). When I try to parse the features with topojson, I receive this error:
TypeError: Cannot read property 'length' of undefined
at arc (topojson.js:172:54)
at line (topojson.js:187:52)
at ring (topojson.js:193:20)
at Array.map (native)
at polygon (topojson.js:199:19)
at Object.geometryType.Polygon (topojson.js:214:37)
at geometry (topojson.js:205:71)
at object (topojson.js:218:12)
at feature (topojson.js:160:17)
at topojson.js:151:55
The Polygon example I based this on has an array of arrays for arcs, whereas the Linestring example I've compared it to has an array of arcs, so my assumption is that the Polygon by default is a multipolygon and I've followed the array of arrays for this example, but if I just make an array of arcs, it gives me the error "cannot call slice of undefined".
I'm pretty sure my vorToPoly function is mapping arcs correctly, but if someone could take a look at my object topoCollection (I've echoed it to the console) and tell me how it's not matching up with what topojson expects, I'd appreciate it.
Mike Bostock pointed out that the error occurred because my topojson collection was referring to an arc that didn't exist because it started counting the arcs at 1 instead of 0. The problem occurred in this part of my vorToPoly code:
topoArcs.push([[Math.floor(vorPolys[x][y][0]),Math.floor(vorPolys[x][y][1])],[Math.floor(vorPolys[x][nextVal][0]),Math.floor(vorPolys[x][nextVal][1])]]);
arcHash[hashVal] = topoArcs.length;
It should have been flipped:
arcHash[hashVal] = topoArcs.length;
topoArcs.push([[Math.floor(vorPolys[x][y][0]),Math.floor(vorPolys[x][y][1])],[Math.floor(vorPolys[x][nextVal][0]),Math.floor(vorPolys[x][nextVal][1])]]);
That way the hash is starting at 0 instead of 1. Flipping this makes everything work just fine.

term does not evaluate to a function taking 1 arguments

Please have a look at the following OpenCV code
Mat *curent;
current = new Mat();
cv::Rect bRect = cv::boundingRect(Mat(*points).reshape(2));
Mat roi = *current(bRect);
Here, I am trying to get a ROI to the Mat called roi. But whenever I try to get execute the last line of the above code I get the error term does not evaluate to a function taking 1 arguments. I have followed the same technique of getting an ROI without pointers number of times before in C++ and they worked. I guess the issue is with pointer current ? current must be a pointer because local variable slowed the application in an unbelievable way.
So, how can I solve this issue and get the ROI ?
please, throw out those pointers!
you're going to wreck havoc on the internal Mat refcounts, produce undefined behaviour and memleaks
"local variable slowed the application in an unbelievable way."
really, you think, copying a 58 byte struct is the reason ? i just don't believe you.
well i'll give you a hint, anyway - the ( ) operator has a higher precedence than the * operator.

Resources