Assimp with android port. Error import .obj file - android

I am built assimp for android with android port (AndroidJNIIOSystem). When I import a file from assets, I get message: Assimp: Asset exists and next get error:
Error::Assimp::No suitable reader found for the file format of file "model/nanosuit.obj".
I have assets hierarchy:
assets/model/nanosuit.obj
My code:
importer.SetIOHandler(ioSystem);
auto modelPath = "model/nanosuit.obj";
const aiScene *scene =
importer.ReadFile(modelPath, aiProcess_Triangulate | aiProcess_FlipUVs);
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
LOGI("%s::%s", "Error::Assimp", importer.GetErrorString());
}
But then I use this code with assimp built for Linux, it work without any errors. Please, help me find solution. Thanks!
P.S. importer.IsDefaultIOHandler() returns false.

When I build lib, I am use -DASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT=OFF in order to reduce lib file size. If remove this flag, all works fine. That use .obj importer you need use -DASSIMP_BUILD_OBJ_IMPORTER=ON flag

Related

Unity, JSON file - Android problem, can't find my JSON file

I wrote a script that allows you to read and write to a json file. As long as I tried the script in unity editor, I didn't have any problems. But when I switched to installing the application on an Android device, I can't find my json file.
The json file is called "playerData.json" and has been placed in a folder called "playerData.json".
This is the code for the path of the json file (working on unity but not working on android)
path = Application.streamingAssetsPath + "/playerData.json";
I tried using this string of code to get the code to work on android as well, but there is no way to get it to work.
path = System.IO.Path.Combine(Application.streamingAssetsPath, "/playerData.json");
I only wrote the line concerning the path as my android device cannot find the JSON file. Thanks everyone for the help!
Application.streamingAssetsPath does not work on Android and WebGL
It is not possible to access the StreamingAssets folder on WebGL and Android platforms. No file access is available on WebGL. Android uses a compressed .apk file. These platforms return a URL. Use the UnityWebRequest class to access the Assets.
There is a workaround though as mentioned using UnityWebRequest, can find an example in this Unity Answer

How to read from file using Chaquopy?

I want to read a file using Chaquopy. After some errors like "PermissionError" I wrote the same code in Python Idle and Chaquopy:
This code in Idle writes 'True' in output.
import xlrd, os
filename = 'F:/q1.xlsx'
print(os.path.isfile(filename))
And this one in Chaquopy outputs 'False':
import xlrd, os
filename = 'F:/q1.xlsx'
self.findViewById(R.id.label).setText(str(os.path.isfile(filename)))
I tried all the described combinations of '\' and '/'. It also cannot open a file in the same folder with Python activity if I write only its relative path. How to make Chaquopy work with files correctly?
You can access files either using pkgutil or by using the extractPackages setting. See the documentation for details.

How to display python matplotlib graphs (png) with Chaquopy in Android Studio

So I use chaquopy to get simple python programs functioning in an old (jelly bean) tablet (I replace the example console app's main.py in the src directory). Not bad for a beginner's start and I'm very happy.
But now for a test I try to display a matplotlib graph like this:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def main():
image = mpimg.imread("/storage/emulated/0/Documents/test.png")
plt.imshow(image)
plt.show()
The matplotlib library was installed from within android studio (albeit with a few missing elements, manual pip3 install and usage of local files). Now the build and program finish without errors, but there is no graph. Installation of pillow and use of other graph types no avail.
Can this be handled in python, or is a dive into android studio / java required?
Thanks for any advice
You'll have to include an ImageView in your app's layout, and then load the image file into it, as in this answer.
For an image which is generated dynamically by matplotlib, either save it to a file and then load from that file, or save it to a bytes object like this:
import io
bio = io.BytesIO()
plt.savefig(bio, format="png")
b = bio.getvalue()
... and then load that bytes object into the ImageView like in this app.

Trying to access Lua scripts in assets via require on Android

I've recently tried porting an engine I've been working on to Android and have ran into some problems when trying to use "require" or "dofile" within a lua script.
(quick note: this is written in C++11, using ndk-build and ant to compile on windows 7)
Compiling Lua (Version 5.3) was pretty simple and I used the following article to get access to the internal assets directory:
50ply blog post on loading compressed android assets
I added an output in the replaced fopen function to help debug this issue and when I run:
luaL_dofile(LuaS, "scripts/test.lua");
I get:
>> scripts/test.lua , read
Which is perfect for me and runs the file in the assets/scripts folder, but when I try to run the following line in the lua script:
local derp = require("scripts.noop")
I get:
>> /usr/local/lib/lua/5.3/scripts/noop.so , read
After looking through the Lua source code, this path seems to be the "LUA_CDIR" as defined in "luaconf.h", which also explains why it looks for *.so files instead of *.lua... So I'm not sure why it's looking for the LUA_CPATH instead of the LUA_PATH or how to fix this.
If anyone could point me in the right direction, that would be great and if I could do this by overwriting the search path/settings outside of the Lua source, it would be even better.
Sorry if this question is not well written, if any further information is required, I will provide it. I'm in a bit of a rush right now.
Thanks for reading.
Require checks both LUA_PATH and LUA_CPATH with many different combinations found within package.path and package.cpath. Environment variables LUA_PATH and LUA_CPATH can be found merged into package actually, as preparation goes.
Psuedo-c/c++-example:
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
lua_getfield(L, -2, "cpath");
const char* cpath = lua_tostring(L, -1);
const char* path = lua_tostring(L, -2);
lua_pop(L, 3); // field 2, field 1, package table
printf("cpath: `%s`\n", cpath);
printf("path: `%s`\n", path);
Which is almost equivalent to, minus the print calls:
>print(package.cpath)
.\?.dll;C:\Program Files\LuaConsole\bin\?.dll;C:\Program Files\LuaConsole\bin\loadall.dll
>print(package.path)
.\?.lua;C:\Program Files\LuaConsole\bin\lua\?.lua;C:\Program Files\LuaConsole\bin\lua\?\init.lua;
Here is an example of require working:
>require("abc")
(Runtime) | Stack Top: 0 | [string "require("abc")"]:1: module 'abc' not found:
no field package.preload['abc']
no file '.\abc.lua'
no file 'C:\Program Files\LuaConsole\bin\lua\abc.lua'
no file 'C:\Program Files\LuaConsole\bin\lua\abc\init.lua'
no file '.\abc.dll'
no file 'C:\Program Files\LuaConsole\bin\abc.dll'
no file 'C:\Program Files\LuaConsole\bin\loadall.dll'
--
stack traceback:
[C]: in function 'require'
[string "require("abc")"]:1: in main chunk
[C]: at 0x00401c80
The solution of your problem is to have your assets directory fall into a directory found within package.cpath or package.path. As #GabeSechan suggested in the comments, "You'll probably have an easier time of things if you copy the files from assets to the actual filesystem. Assets is not a directory on the device, so anything looking for a file won't find it." So if you are able to get this situated, go for it!

Why can't I create a file on android using python

I can't run my python program on my android device using qpython3.
The first step in he program is to create a text file to save data to it. But I get an I/O error (file system read only)
This is the function used to create / or be sure that the file exists easily.
def filecreate(file): # creates the text file
f = open(file, 'a')
print('file created successfully\n')
print()
f.close()
How to overcome this problem in android ?
QPython by default runs your programs from the root directory which is not writable by non-root users. If you check the ftp utility (under About menu) you will find the name of the directory that is writable by QPython. On my HTC it is:
/storage/emulated/0/com.hipipal.qpyplus
So you need to do something along the lines of:
RootPath='/storage/emulated/0/com.hipipal.qpyplus'
...
import os
f = open(file, os.path.join(RootPath,'a'))
...
Example of a similar problem with QPython and SQLite3
Just create the file with QPython before use in your script.
You can create an txt file with QPython.
In My case I create the file whith name "pontoText.txt"
Inside folder "MyPythonScripts" (Im create that folder to put my python files)
so the file is in the same folder of the script and are created in QPython
Now an example code im make ton test:
import time
import os
a = input("1 to save date on file or 2 too see records on file. ")
folder= '/storage/emulated/0/MyPythonScripts'
if(a == "1"):
pontoTxt=open(os.path.join(folder,'pontoText.txt'),'w')
pontoTxt.write(time.strftime("%I %M %p on %A, %B %e, %Y"))
if(a == "2"):
pontoTxt=open(os.path.join(folder,'pontoText.txt'),'r')
exibe = pontoTxt.read()
print(exibe)
Your app may not have required permission to manage that file. Check your manifest, specify Android version and file path. Check documentation: http://developer.android.com/training/basics/data-storage/files.html
You have to actually find the file path, as it doesn't infer the directory that the file is in as the destination directory, unlike in Python on the PC.
Use what they're changed.
The file you have is inside /accounts/mastercard root and the file you're inside is /accounts/main.py you only need to use is this
/mastercard/xxxxx like my code
from django.shortcuts import render
from django.http import HttpResponse
from . import models
# Create your views here.
def index(request):
return render(request,"mastercard/Templates/mastercard/Base.html")
def about(request):
return render(request,"mastercard/Templates/mastercard/index.html")

Categories

Resources