Making a surface reflective / mirror like in Java 3D - java

I've been trying to make a surface in Java 3D reflect in a similar manner to a mirror. The API says to use TexCoordGeneration in SPHERE_MAP mode, but it doesn't seem to be making any difference at all.
Can anyone spot what I'm doing wrong?
Appearance reflectAp = new Appearance();
TexCoordGeneration tex = new TexCoordGeneration();
tex.setGenMode(TexCoordGeneration.SPHERE_MAP);
reflectAp.setMaterial(matFact.silver());
reflectAp.setTexCoordGeneration(tex);
flat = new Box(.7f, .9f, .01f, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, reflectAp);

Related

Texturing bug in Jmonkey

To my immense surprise, it seems impossible to find any other people having this problem -- I can use Jmonkey to import a mesh (in my case a gear), but it doesn't properly map the texture (which is supposed to look like wood), only texturing a few select faces shown:
It still looks fine in Blender:
To summarize, how do I get the texture to map over the ENTIRE gear, not just some triangles?
My code is written like this (pardon if it's a little messy, I've been trying to solve this for a while now):
Spatial gear = assetManager.loadModel("Models/cog_3.j3o");
//Geometry geargeo=(Geometry)gear;
//Node gearnode = (Node)gear;
//Mesh gearmesh = (Mesh) gearnode;
//Mesh gearmesh = (Geometry)(gearnode.getChildren().get(0));
TangentBinormalGenerator.generate(gear);
Material wood = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture woodtex = assetManager.loadTexture("Textures/wood-texture.jpg");
woodtex.setWrap(Texture.WrapMode.Repeat);
wood.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
wood.setTexture("ColorMap", woodtex);
wood.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
gear.setMaterial(wood);
rootNode.attachChild(gear);
My mesh looks like this (you can see the uv seams):
Uv looks like this:
I'm using blender 2.78a,
and (as far as I know), the latest version of JME.
Any help is appreciated greatly.

Android native SDL glContext messed up picture

I'm trying to setup SDL2 native application with use of custom glContext.
Java part: this has by default Absolute layout which is deprecated. And i wonder if i need to use some kind of SurfaceView:
mSurface = new SDLSurface(getApplication());
mLayout = new RelativeLayout(this);
mLayout.setLeft(0);
mLayout.setTop(0);
mLayout.addView(mSurface);
setContentView(mLayout);
Next, i'm creating opengl context in my native code:
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2");
SDL_SetHint(SDL_HINT_RENDER_OPENGL_SHADERS, "1");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
m_glContext = SDL_GL_CreateContext(_window);
SDL_GL_MakeCurrent(_window, m_glContext);
Window is created like this:
m_mainWindow = SDL_CreateWindow("clovo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 2048, 1536,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_FULLSCREEN);
I thought the case may be in size of window, but after creation the size is fits the screen. Also, this code works fine in iOS.
I can't find a solution for a problem. Can't even find a problem. I'm new to Android, so maybe there something about glContext what i should know?
Found the problem.
It's occur when i'm using my own framebuffers and then setting it back to default.
In order to not set wrong buffer at my renderer initialization i'm storing default framebuffer
GLint default_buffer;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &default_buffer);
And then i can restore default buffer to draw to screen.

How make the tkinter widget ".place()" method in python work similarly to the ".setbounds()" method in Java?

Python 3.4 and Eclipse IDE
I have a java form I am translating into python tkinter. I have a number of jlabels, jtextfields, jcomboboxes, and a seperator line that need to be placed on an identical python form with their respective python widget counterparts.
Example label from java using specific positioning:
JLabel lblWhichTrip = new JLabel("Which Trip:");
lblWhichTrip.setHorizontalAlignment(SwingConstants.RIGHT);
lblWhichTrip.setFont(new Font("Tahoma", Font.PLAIN, 16));
lblWhichTrip.setBounds(64, 22, 135, 20);
frmBookCalc.getContentPane().add(lblWhichTrip);
After 50 some odd browser tabs the python equivalent should be:
self.lblWhichTrip = Label(self, text = "Which Trip:", bg = "white", anchor = "e")
self.lblWhichTrip.place(x = 64, y = 22, height=135, width=20)
But the widget does not appear at all, not even in the wrong place.
The reason I want to use the ".place()" method in python is the same reason I used specific positioning in java, one has very little precise control over the ".pack()" method.
There was an instance where I found an example of the ".pack()" method being called directly before the ".place()" method, but more examples of just the ".place()" only used.
So here is the question:
How do I utilize the ".place()" method to similarly place the python tkinter widgets on the python form as I did with the Java form? I know I am close but it is not working.
With more work I have found the button below will put a button on my form but the labels section is blank as stated above.
languages = ['Python','Perl','C++','Java','Tcl/Tk']
labels = range(5)
for i in range(5):
ct = [random.randrange(256) for x in range(3)]
brightness = int(round(0.299*ct[0] + 0.587*ct[1] + 0.114*ct[2]))
ct_hex = "%02x%02x%02x" % tuple(ct)
bg_colour = '#' + "".join(ct_hex)
l = Label(self, text=languages[i], fg='White' if brightness < 120 else 'Black', bg=bg_colour)
l.place(x = 20, y = 30 + i*30, width=120, height=25)
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
The form is being made in a class structure as denoted by the term "self". I have no idea why the button will show on the form but the labels will not. the only difference is ".pack()" and ".place()" methods used. From my research they are functionally the same thing, they just go about it in different ways.
I have looked at so many examples my eyes hurt. If someone could clear this up i would be forever thankful.
Reference:
Reference for tkinter
Update:
The ".place()" does not like being inside a class or I don't know how to instantiate it inside a class. I got it to work by neglecting the class structure that I wanted to use. How do I get ".place()" to work inside a class?
Update:
import tkinter as tk
import random
root = tk.Tk()
w = 465
h = 590
x = (root.winfo_screenwidth()/2) - (w/2)
y = (root.winfo_screenheight()/2) - (h/2)
root.minsize(width=w, height=h)
root.maxsize(width=w, height=h)
root.resizable(width=tk.FALSE, height=tk.FALSE)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.configure(background='white')
root.option_add("*font", "Tahoma 12")
root.title("Book Calc")
lblWhichTrip = tk.Label(root, text = "Which Trip:", bg = "white", anchor = "e")
lblWhichTrip.place(x=200, y=30, height=135, width=20)
root.mainloop()
I ditched the py file and the class containing all the form stuff for a single file with direct code and now the label is not visible again. The code immediately above is the entirety of my program at the moment. I hope I can figure this out soon.
Update:
The height and width needs to be on place and not the label. Above code modified.
lblWhichTrip = tk.Label(root, text = "Which Trip:", bg = "white", anchor = "e")
lblWhichTrip.place(x=200, y=30, height=135, width=20)
This works perfectly fine outside of a class structure, but it doesn't seem to work inside of a class. This is a half answer for my question above for placing a label or other widget in a specific location on a python form.
The other half the question is still unanswered being that this solution does not work inside of a class, which it should. If someone can shed some light on this, it would be great. Someone else will be wanting to write a much more robust program than I at this time so a better answer than this one is needed.
Thank you.
Update:
root = tk.Tk()
app = Application(root)
The above is when you create the class. Root needs to be sent directly.
def __init__(self, master):
self.parent = master
A pointer to root needs to be set a class var for persistence.
lblWhichTrip = tk.Label(root, text = "Which Trip:", bg = "white", anchor = "e")
lblWhichTrip.place(x=85, y=-35, height=135, width=100)
Then you can make all the widgets you want from inside a class, and all the layout engines will work fine. Pack, Place, and Grid will work perfectly.
Answered fully from due diligence.
Refernce:
Additional info here

libgdx body from model

I'm trying to make the game, using LibGDX. I create a Model from *g3db file like this:
public AssetManager assets;
assets = new AssetManager();
assets.load("data/road.g3db", Model.class);
Model road = assets.get("data/road.g3db", Model.class);
ModelInstance roadInstance = new ModelInstance(road);
data/road.g3db is a а long ribbon like road. I make its in blender 3d. Somthing like this:
****
* ***** ****
* * *
*** *******
My question is: how can i create body from this Model? I try this:
ChainShape shape = new ChainShape();
Mesh roadMesh = roadInstance.model.meshes.get(0);
float ar[] = new float[roadMesh.getVerticesBuffer().capacity()];
roadMesh.getVerticesBuffer().get(ar);
shape.createChain(ar);
But there are error:
AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!
Program: C:\Program Files (x86)\Java\jre7\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/gdx/jni/Box2D/Collision/Shapes/b2ChainShape.cpp,
Line 63
Expression: b2DistanceSquared(v1, v2) > 0.005f * 0.005f
Is there another way to create body for long road ?
Box2D is, as the name says, for 2D physics. If you have a 3D game, with 2D physics only, you can easily use it under the hood and change the view to 3D. But if you need 3D physics i would suggest to use PhysicsBullet. It is a 3D Collision Detection and Rigid Body Dynamics Library.
To give you something to read: Bullet physics on GitHub

libGDX: Changing visibility of a 3d model

Imagine I have a model of a human with some accessory like sunglasses, a hat, a chain and so on. Is there any way to switch the visibility of those items inside my libGDX application, by writing something like:
modelInstance.getNode("sunglasses").setVisible(false)
You can set a blending attibute to its material:
blendingAttribute = new BlendingAttribute(GL10.GL_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
material = modelinstance.materials.get(0);
material.set(blendingAttribute);
Then you can set its opacity like this:
blendingAttribute.opacity = 0.5F; //0-1

Categories

Resources