How to load textures for obj? - aframe

I'm trying to load an .obj which has several .jpgs as textures. My .obj is rendering - but without applying the material.
The .mtl looks like
newmtl material_0
Ka 0.200000 0.200000 0.200000
Kd 1.000000 1.000000 1.000000
Ks 1.000000 1.000000 1.000000
Tr 1.000000
illum 2
Ns 0.000000
map_Kd tex_0.jpg
I assume the path to the .jpgs are correct - if I change it, I see 404 errors in the console.
My aframe code is:
<a-scene>
<a-assets>
<a-asset-item id="moore-obj" src="obj/moore.obj"></a-asset-item>
<a-asset-item id="moore-mtl" src="obj/moore.obj.mtl"></a-asset-item>
</a-assets>
<a-entity
obj-model="obj: #moore-obj; mtl: #moore-mtl"
scale="1 1 1"
rotation="0 0 0"
position="1 1 1"></a-entity>
</a-scene>
The 3D model appears in the scene - but there are no textures overlayed on it. I'm running this on localhost, and I'm not seeing any CORS warnings.
The object is http://www.thingiverse.com/thing:36415

Turns out to be an issue with that particular OBJ file. It uses three materials but it doesn't define object groups for the sub-objects that use each of those materials, so Three.js' OBJLoader doesn't associate the materials correctly.
You can work around it by adding group lines before each usemtl line in the obj file.
For example:
g g_0
usemtl material_0
...
g g_1
usemtl material_1
etc.

Related

In Aframe, the target is not working for Light Spot

I want to point a spot light towards a specific object. According to documentation (https://aframe.io/docs/1.3.0/components/light.html)
there is an property target that takes the id of the object to point to. However target does not seem to react to any value.
<a-light position="10 10 10" rotation="0 0 0" scale="1 1 1" light="type:spot;color:#ff0000;intensity:100;distance:1000;decay:0.1;angle:3;penumbra:0; target:myplane"></a-light>
Here is my codepen example:
https://codepen.io/jimver04/pen/JjZRJLz
A-Frame Version: 1.3.0
Platform / Device: Windows 10, Firefox 106, Desktop 3080 RTX GPU
Reproducible Code Snippet or URL: https://codepen.io/jimver04/pen/JjZRJLz
I found it, it just needs a # before the plane id
<a-light position="10 10 10" rotation="0 0 0" scale="1 1 1" light="type:spot;color:#ff0000;intensity:100;distance:1000;decay:0.1;angle:3;penumbra:0;target:#myplane"></a-light>

Textures for OBJ will not load

I simply cannot get the textures to load for my basic 3d models. The model appears but is only in grey.
I am using this model: https://www.turbosquid.com/3d-models/free-max-mode-hammer/384372
I am using the following code.
<a-asset-item id="hammer-obj" src="hammer.obj"></a-asset-item>
<a-asset-item id="hammer-mtl" src="hammer.mtl"></a-asset-item>
<a-entity
obj-model="obj: #hammer-obj; mtl: #hammer-mtl"
scale="1 1 1"
position="0.05 1 -1.90">
My MTL file currently looks like:
newmtl head
Ka 0 0 0
Kd 0 0 0
Ks 0.637 0.637 0.637
illum 2
Ns 2
map_Kd hammer.jpg
map_bump hammer.jpg
bump hammer.jpg
newmtl grip
Ka 0 0 0
Kd 0 0 0
Ks 1 1 1
illum 2
Ns 2
map_Kd hammer.jpg
map_bump hammer.jpg
bump hammer.jpg
I have converted the TIFF file into a jpg as well and that didnt work. I initially had all links to hammer.TIF but I tried JPEG.
Could anyone give me any insight as to what is happening?
Thanks.
If You want to get results 'as expected', my recommendation is the three.json and .glTF formats.
Apparently they are well implemented, and don't cause unexpected behaviour like obj's with mtl's, or sadly fbx's.
In my opinion You should use some blender glTF( 1 or 2 ) exporter, and change the 3D hammer model format, or You could use clara.io, to export it to the three.js json format.
Don McCurdy of the a-frame team recommended using the glTF and json format here.
In fact there is some valuable information there, like how using the material component to texture the .obj with a .jpg works randomly.
You can also find more information on model troubleshooting here.

Specifying Room dimensions in networked-a-frame

I am new to a-frame and have followed the examples of haydenjameslee networked-aframe. I was wondering if there is a way to specify the room size when defining the a-scene in it's tag
<a-scene networked-scene="app: myApp; room: room1;">
I have a workaround, for I don't fully understand how the component works.
I found there is a player list under the reference NAF.entities.entities
I made a component attached to the scene:
AFRAME.registerComponent('foo',{
init:function(){
setTimeout(function(){
console.log(Object.keys(NAF.entities.entities));
console.log(Object.keys(NAF.entities.entities)[0]);
console.log(Object.keys(NAF.entities.entities).length);
},5000);
}
});
The first log gives me an array of the players id's.
The second one gives the id of the first element.
The last gives me the number of the players.
You can check for the number of players on load, and if the number is exceeded, just deny access, change the room, or href to a 'lobby' website.
Working glitch here: glitch.com/edit/#!/sudden-antler
Of course instead of waiting 5 seconds i should be listening to a loaded event, I'll look into it once im not so busy.
As far as I know this is not possible in A-Frame.
What do you need it for?
An NPM Package aframe-room-component is available that easily lets you create rooms and connects them. Serves my need.
https://www.npmjs.com/package/aframe-room-component
It can be used as follows
<rw-room position="-3 0 -5" material="color:#787">
<rw-floor material="color:red"></rw-floor>
<rw-ceiling material="color:blue"></rw-ceiling>
<rw-wall position="6 0 0" material="color:yellow"></rw-wall>
<rw-wall position="6 0 6" material="color:green"></rw-wall>
<rw-wall position="0 0 6" material="color:brown"></rw-wall>
<rw-wall position="0 0 0" material="color:pink"></rw-wall>
</rw-room>

Why is this texture being loaded multiple times in AFrame?

I have this asset definition:
<a-asset-item id="DNA"
crossorigin="anonymous"
src="https://cdn.glitch.com/2dd120f4-5d77-403f-af9d-feb8e33ed767%2FAR_DNA.dae">
</a-asset-item>
And this reference in my scene:
<a-entity collada-model="#DNA"
position="-60 0 0"
scale="2 2 2"
rotation="0 90 0" model-monitor></a-entity>
When I look at the network window in my browser console, I'm seeing the asset being downloaded twice. And it's 12 mb.
Why is this happening?

Manually adding special characters to a pdf

I have a pdf (of a simple line graph) which was generated using R, and is just stored with plain text streams. The data used to generate the graph has been lost, and I would like to modify the axis labels by editing the pdf.
I found this line:
/F2 1 Tf 12.00 0.00 -0.00 12.00 238.73 18.72 Tm (**Error Rate**) Tj
Which appears to control the axis label I want (which currently says "Error Rate"). Changing it to say:
/F2 1 Tf 12.00 0.00 -0.00 12.00 238.73 18.72 Tm (**Different Label**) Tj
Does indeed result in the axis label changing to "Different Label".
Now, I want the new label to be "Mu". As in, the greek letter Mu. I know this is possible, since I can generate pdf's in R with greek letters in their axis labels.
My first thought was to manually enter the UTF-8 charactor for Mu using the vim trigraph ctrl+k m*, and also through the character map and the like, to give:
/F2 1 Tf 12.00 0.00 -0.00 12.00 238.73 18.72 Tm ( μ ) Tj
If I attempt to write the file after doing this, I get an error message "CONVERSION ERROR in line xyz", where xyz is the modified line. Opening the saved pdf reveals a '?' for the axis label.
How does the pdf encode mu? How can I modify the label accordingly?
PDF files are binary files, modifying them as text files will corrupt them in most cases. In order to keep the file valid you need to update the xref table (see the PDF specification for more details). If the byte count of the whole file changes, you will need to update each entry of the xref table for the file to remain valid. Another option could be to remove the xref table all together and pass the resulting file through another tool that can "guess" it for you. I have done this with ghostscript in the past with good results.
About the issue with fonts, which font /F2 corresponds to? Is it partially embedded in the PDF file?
If it is, you probably do not have the required information in the file to add the character μ.
I tried this:
pdf("testmu.pdf",compress=FALSE)
plot(1:10,1:10,xlab="abc",ylab=expression("LABEL "*mu))
dev.off()
and found the following chunk in the resulting file:
BT
/F2 1 Tf 0.00 12.00 -12.00 0.00 10.28 235.40 Tm (LABEL ) Tj
ET
BT
/F6 1 Tf 0.00 12.00 -12.00 0.00 10.28 276.09 Tm (m) Tj
ET
So I suspect if you use
/F6 1 Tf 12.00 0.00 -0.00 12.00 238.73 18.72 Tm ( m ) Tj
in your example above it should work. I don't know whether R always defines F6 (Symbol font), so you might also need to hack in something along these lines:
13 0 obj
<< /Type /Font /Subtype /Type1 /Name /F6 /BaseFont /Symbol
>>
edit: as pointed out in the other answer, and the comment below it, it seems you also need to manually update the xref count by (I think) searching for xref, finding a chunk like
xref
0 13
and incrementing the second value ...
As #yms pointed out, PDFs are typically not editable in a text editor, as they most likely contain binary data and have an xref table that needs to be updated if chracters are inserted or deleted in the PDF. If you must edit a pdf, use qpdf to edit the PDF.

Resources