Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed May 12, 2016
1 parent 39d3c7a commit 0a39363
Show file tree
Hide file tree
Showing 27 changed files with 99 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package jme3_ext_xbuf.mergers;
package jme3_ext_xbuf;

import com.jme3.scene.Node;

import jme3_ext_xbuf.XbufContext;
import xbuf.Datas.Data;

public interface Merger{
Expand Down
1 change: 0 additions & 1 deletion jme3_xbuf_loader2/src/main/java/jme3_ext_xbuf/Xbuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import jme3_ext_xbuf.mergers.CustomParamsMerger;
import jme3_ext_xbuf.mergers.LightsMerger;
import jme3_ext_xbuf.mergers.MaterialsMerger;
import jme3_ext_xbuf.mergers.Merger;
import jme3_ext_xbuf.mergers.MeshesMerger;
import jme3_ext_xbuf.mergers.NodesMerger;
import jme3_ext_xbuf.mergers.RelationsMerger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import java.util.Map;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("unchecked")
public class XbufContext {
// public Logger log=LoggerFactory.getLogger("Xbuf");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jme3_ext_xbuf.mergers.animations;
package jme3_ext_xbuf.animations;

import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jme3_ext_xbuf.mergers.animations;
package jme3_ext_xbuf.animations;

import com.jme3.animation.Bone;
import com.jme3.animation.BoneTrack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import java.lang.reflect.Field;

import org.slf4j.Logger;

import com.jme3.animation.AnimControl;
import com.jme3.animation.Skeleton;


import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package jme3_ext_xbuf.ext;

import com.google.common.primitives.Floats;

import xbuf.Meshes.FloatBuffer;

public class FloatBufferExt{

// //TODO use an optim version: including a patch for no autoboxing : https://code.google.com/p/protobuf/issues/detail?id=464
public static float[] array(FloatBuffer src) {
return Floats.toArray(src.getValuesList());
}


}
Original file line number Diff line number Diff line change
@@ -1,58 +1,45 @@
package jme3_ext_xbuf;
package jme3_ext_xbuf.ext;

import com.google.common.primitives.Floats;
import com.google.common.primitives.Ints;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.scene.Mesh;
import com.jme3.scene.Mesh.Mode;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.Mesh.Mode;
import com.jme3.scene.VertexBuffer.Type;

import xbuf.Meshes;
import xbuf.Meshes.FloatBuffer;
import xbuf.Meshes.UintBuffer;
import xbuf.Meshes.VertexArray;
import xbuf.Primitives;
import xbuf.Meshes.VertexArray;
import xbuf.Primitives.Mat4;

public class Converters{
public class PrimitiveExt{

public static Vector2f cnv(Primitives.Vec2 src, Vector2f dst) {
dst.set(src.getX(),src.getY());
return dst;
public static Vector2f toJME(Primitives.Vec2 src) {
return new Vector2f(src.getX(),src.getY());
}

public static Vector3f cnv(Primitives.Vec3 src, Vector3f dst) {
dst.set(src.getX(),src.getY(),src.getZ());
return dst;
public static Vector3f toJME(Primitives.Vec3 src) {
return new Vector3f(src.getX(),src.getY(),src.getZ());
}

public static Vector4f cnv(Primitives.Vec4 src, Vector4f dst) {
dst.set(src.getX(),src.getY(),src.getZ(),src.getW());
return dst;
public static Vector4f toJME(Primitives.Vec4 src) {
return new Vector4f(src.getX(),src.getY(),src.getZ(),src.getW());
}

public static Quaternion cnv(Primitives.Quaternion src, Quaternion dst) {
dst.set(src.getX(),src.getY(),src.getZ(),src.getW());
return dst;
public static Quaternion toJME(Primitives.Quaternion src) {
return new Quaternion(src.getX(),src.getY(),src.getZ(),src.getW());
}

public static Vector4f cnv(Primitives.Quaternion src, Vector4f dst) {
dst.set(src.getX(),src.getY(),src.getZ(),src.getW());
return dst;
}

public static ColorRGBA cnv(Primitives.Color src, ColorRGBA dst) {
dst.set(src.getR(),src.getG(),src.getB(),src.getA());
return dst;
public static ColorRGBA toJME(Primitives.Color src) {
return new ColorRGBA(src.getR(),src.getG(),src.getB(),src.getA());
}

public static Matrix4f cnv(Mat4 src, Matrix4f dst) {
public static Matrix4f toJME(Mat4 src) {
Matrix4f dst=new Matrix4f();
dst.m00=src.getC00();
dst.m10=src.getC10();
dst.m20=src.getC20();
Expand All @@ -72,7 +59,7 @@ public static Matrix4f cnv(Mat4 src, Matrix4f dst) {
return dst;
}

public static Mesh.Mode cnv(Meshes.Mesh.Primitive v) {
public static Mesh.Mode toJME(Meshes.Mesh.Primitive v) {
switch(v){
case line_strip:
return Mode.LineStrip;
Expand All @@ -89,7 +76,7 @@ public static Mesh.Mode cnv(Meshes.Mesh.Primitive v) {
}
}

public static VertexBuffer.Type cnv(VertexArray.Attrib v) {
public static VertexBuffer.Type toJME(VertexArray.Attrib v) {
switch(v){
case position:
return Type.Position;
Expand Down Expand Up @@ -122,13 +109,4 @@ public static VertexBuffer.Type cnv(VertexArray.Attrib v) {
}
}

//TODO use an optim version: including a patch for no autoboxing : https://code.google.com/p/protobuf/issues/detail?id=464
public static float[] hack_cnv(FloatBuffer src) {
return Floats.toArray(src.getValuesList());
}

//TODO use an optim version: including a patch for no autoboxing : https://code.google.com/p/protobuf/issues/detail?id=464
public static int[] hack_cnv(UintBuffer src) {
return Ints.toArray(src.getValuesList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jme3_ext_xbuf.ext;

import com.google.common.primitives.Ints;

import xbuf.Meshes.UintBuffer;

public class UintBufferExt{
//TODO use an optim version: including a patch for no autoboxing : https://code.google.com/p/protobuf/issues/detail?id=464
public static int[] array(UintBuffer src) {
return Ints.toArray(src.getValuesList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import jme3_ext_xbuf.mergers.animations.XbufAnimation;
import jme3_ext_xbuf.mergers.animations.XbufTrack;
import jme3_ext_xbuf.animations.XbufAnimation;
import jme3_ext_xbuf.animations.XbufTrack;
import xbuf.Datas.Data;
import xbuf_ext.AnimationsKf;
import xbuf_ext.AnimationsKf.SampledTransform;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package jme3_ext_xbuf.mergers;

import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.plugins.physics4loaders.PhysicsData;
import com.jme3.scene.plugins.physics4loaders.PhysicsData.PhysicsShape;
import com.jme3.scene.plugins.physics4loaders.PhysicsData.PhysicsType;

import jme3_ext_xbuf.Converters;
import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import lombok.experimental.ExtensionMethod;
import xbuf.Datas.Data;
import xbuf_ext.Bullet.BulletPhysics;

@ExtensionMethod({jme3_ext_xbuf.ext.PrimitiveExt.class})
public class BulletPhysicsMerger implements Merger{

@Override
Expand All @@ -25,8 +26,8 @@ public void apply(Data src, Node root, XbufContext context) {
phydata.linearDamping=p.getLinearDamping();
phydata.margin=p.getMargin();
phydata.restitution=p.getRestitution();
phydata.angularFactor=Converters.cnv(p.getAngularFactor(),new Vector3f());
phydata.linearFactor=Converters.cnv(p.getLinearFactor(),new Vector3f());
phydata.angularFactor=p.getAngularFactor().toJME();
phydata.linearFactor=p.getLinearFactor().toJME();
phydata.isGhost=p.getIsGhost();
phydata.isKinematic=p.getIsKinematic();
phydata.collisionGroup=p.getCollisionGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.jme3.scene.Node;

import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import xbuf.Datas.Data;
import xbuf_ext.CustomParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import com.jme3.math.FastMath;
import com.jme3.scene.Node;

import jme3_ext_xbuf.Converters;
import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import lombok.experimental.ExtensionMethod;
import lombok.extern.slf4j.Slf4j;
import xbuf.Datas.Data;
import xbuf.Lights;

@ExtensionMethod({jme3_ext_xbuf.ext.PrimitiveExt.class})
@Slf4j
public class LightsMerger implements Merger{

Expand All @@ -29,7 +31,7 @@ public void apply(Data src, Node root, XbufContext context) {
}

if(srcl.hasColor()){
light.setColor(Converters.cnv(srcl.getColor(),new ColorRGBA()).mult(srcl.getIntensity()));
light.setColor(srcl.getColor().toJME().mult(srcl.getIntensity()));
}

// TODO manage attenuation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package jme3_ext_xbuf.mergers;

import static jme3_ext_xbuf.Converters.cnv;

import org.slf4j.Logger;


import com.jme3.asset.AssetManager;
import com.jme3.asset.AssetNotFoundException;
Expand All @@ -18,19 +14,22 @@
import com.jme3.texture.Texture.MagFilter;
import com.jme3.texture.Texture.MinFilter;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.texture.image.ColorSpace;
import com.jme3.texture.Texture2D;
import com.jme3.texture.image.ColorSpace;

import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.ExtensionMethod;
import lombok.extern.slf4j.Slf4j;
import xbuf.Datas.Data;
import xbuf.Materials;
import xbuf.Primitives;
import xbuf.Primitives.Color;
import xbuf.Primitives.Texture2DInline;

@ExtensionMethod({jme3_ext_xbuf.ext.PrimitiveExt.class})

@Slf4j
public class MaterialsMerger implements Merger{
Expand Down Expand Up @@ -82,7 +81,7 @@ public void setColor(boolean has, Color src, Material dst, String[] names, Mater
if(has){
String name=findMaterialParamName(names,VarType.Vector4,scope);
if(name!=null){
dst.setColor(name,cnv(src,new ColorRGBA()));
dst.setColor(name,src.toJME());
}else{
log.warn("can't find a matching name for : [{}] ({})",",",names,VarType.Vector4);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.jme3.scene.Node;

import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import jme3_ext_xbuf.mergers.meshes.XbufMesh;
import jme3_ext_xbuf.scene.XbufMesh;
import xbuf.Datas.Data;

//@ExtensionMethod({jme3_ext_xbuf.ext.XbufMeshExt.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

import jme3_ext_xbuf.Converters;
import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import lombok.experimental.ExtensionMethod;
import xbuf.Datas.Data;
import xbuf.Primitives.Transform;
import xbuf.Tobjects.TObject;

@ExtensionMethod({jme3_ext_xbuf.ext.PrimitiveExt.class})
public class NodesMerger implements Merger{

@Override
Expand All @@ -23,9 +25,9 @@ public void apply(Data src, Node root, XbufContext context) {
}
child.setName(n.hasName()?n.getName():n.getId());
Transform transform=n.getTransform();
child.setLocalRotation(Converters.cnv(transform.getRotation(),child.getLocalRotation()));
child.setLocalTranslation(Converters.cnv(transform.getTranslation(),child.getLocalTranslation()));
child.setLocalScale(Converters.cnv(transform.getScale(),child.getLocalScale()));
child.setLocalRotation(transform.getRotation().toJME());
child.setLocalTranslation(transform.getTranslation().toJME());
child.setLocalScale(transform.getScale().toJME());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.jme3.scene.Node;

import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import jme3_ext_xbuf.mergers.relations.Linker;
import jme3_ext_xbuf.mergers.relations.RefData;
Expand All @@ -17,7 +18,6 @@
import jme3_ext_xbuf.mergers.relations.linkers.PhysicsToSpatial;
import jme3_ext_xbuf.mergers.relations.linkers.SkeletonToSpatial;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import xbuf.Datas.Data;
import xbuf.Relations.Relation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import java.util.HashMap;


import com.jme3.animation.Bone;
import com.jme3.animation.Skeleton;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

import jme3_ext_xbuf.Converters;
import jme3_ext_xbuf.Merger;
import jme3_ext_xbuf.XbufContext;
import lombok.experimental.ExtensionMethod;
import xbuf.Datas.Data;
import xbuf.Relations.Relation;
import xbuf.Skeletons;

@ExtensionMethod({jme3_ext_xbuf.ext.PrimitiveExt.class})

public class SkeletonsMerger implements Merger{

@Override
Expand All @@ -35,7 +35,7 @@ private Skeleton makeSkeleton(Skeletons.Skeleton e) {
for(int i=0;i<bones.length;i++){
xbuf.Skeletons.Bone src=e.getBones(i);
Bone b=new Bone(src.getName());
b.setBindTransforms(Converters.cnv(src.getTransform().getTranslation(),new Vector3f()),Converters.cnv(src.getTransform().getRotation(),new Quaternion()),Converters.cnv(src.getTransform().getScale(),new Vector3f()));
b.setBindTransforms(src.getTransform().getTranslation().toJME(),src.getTransform().getRotation().toJME(),src.getTransform().getScale().toJME());
db.put(src.getId(),b);
bones[i]=b;
}
Expand Down
Loading

0 comments on commit 0a39363

Please sign in to comment.