📄 colladaimporter.java
字号:
"Rotate-X-")) {
rotx = (float[]) object;
} else if (animation.getsamplerAt(j).getinputAt(i)
.getsource().toString().contains(
"Rotate-Y-")) {
roty = (float[]) object;
} else if (animation.getsamplerAt(j).getinputAt(i)
.getsource().toString().contains(
"Rotate-Z-")) {
rotz = (float[]) object;
} else if (animation.getsamplerAt(j).getinputAt(i)
.getsource().toString().contains(
"Translate-X-")) {
transx = (float[]) object;
} else if (animation.getsamplerAt(j).getinputAt(i)
.getsource().toString().contains(
"Translate-Y-")) {
transy = (float[]) object;
} else if (animation.getsamplerAt(j).getinputAt(i)
.getsource().toString().contains(
"Translate-Z-")) {
transz = (float[]) object;
} else {
if (!squelch) {
logger
.warning("Not sure what this sampler is.");
}
}
}
} else if ("INTERPOLATION".equals(animation.getsamplerAt(j)
.getinputAt(i).getsemantic().toString())) {
String key = animation.getsamplerAt(j).getinputAt(i)
.getsource().toString().substring(1);
int[] interpolation = (int[]) resourceLibrary.get(key);
if (interpolation == null) {
logger.warning("Animation source invalid: " + key);
continue;
}
out.setInterpolationTypes(interpolation);
}
}
}
if (!transformsSet) {
Matrix4f[] transforms = generateTransforms(rotx, roty, rotz,
transx, transy, transz);
if (transforms != null) {
bt.setTransforms(transforms);
}
}
}
if (animation.haschannel()) {
String target = animation.getchannel().gettarget().toString();
if (target.contains("/")) {
String key = target.substring(0, animation.getchannel()
.gettarget().toString().indexOf('/'));
bt.setBoneId(key);
Bone b = (Bone) resourceLibrary.get(key);
if (b != null) {
bt.setBone(b);
}
out.addBoneTransforms(bt);
}
}
// if the animation has children attach them
if (animation.hasanimation()) {
for (int i = 0; i < animation.getanimationCount(); i++) {
out.addBoneAnimation(processAnimation(animation
.getanimationAt(i)));
}
}
return out;
}
private Matrix4f[] generateTransforms(float[] rotx, float[] roty,
float[] rotz, float[] transx, float[] transy, float[] transz) {
Quaternion rot = new Quaternion();
int index = 0;
if (rotx != null) {
index = rotx.length;
} else if (transx != null) {
index = transx.length;
}
Matrix4f[] transforms = new Matrix4f[index];
float[] angles = new float[3];
for (int i = 0; i < transforms.length; i++) {
angles[0] = angles[1] = angles[2] = 0;
if (rotx != null) {
angles[0] = rotx[i];
}
if (roty != null) {
angles[1] = roty[i];
}
if (rotz != null) {
angles[2] = rotz[i];
}
rot.fromAngles(angles);
transforms[i] = rot.toRotationMatrix(new Matrix4f());
if (transx != null) {
transforms[i].m03 = transx[i];
}
if (transy != null) {
transforms[i].m13 = transy[i];
}
if (transz != null) {
transforms[i].m23 = transz[i];
}
}
return transforms;
}
private void processCameraLibrary(library_camerasType libraryCam)
throws Exception {
if (libraryCam.hascamera()) {
for (int i = 0; i < libraryCam.getcameraCount(); i++) {
// processCamera(libraryCam.getcameraAt(i));
}
}
}
private void processCamera(cameraType camera) throws Exception {
opticsType optics = camera.getoptics();
technique_commonType2 common = optics.gettechnique_common();
Renderer r = DisplaySystem.getDisplaySystem().getRenderer();
int width = r.getWidth();
int height = r.getHeight();
// FIXME: THIS LINE IS SUPPOSED TO ONLY BE DONE IN A GL THREAD.
Camera c = r.createCamera(width, height);
float near = c.getFrustumNear();
float far = c.getFrustumFar();
float aspect = (float) width / (float) height;
if (common.hasorthographic()) {
orthographicType ortho = common.getorthographic();
float xmag = 1.0f;
float ymag = 1.0f;
if (ortho.hasznear()) {
near = Float.parseFloat(ortho.getznear().getValue().toString());
}
if (ortho.haszfar()) {
far = Float.parseFloat(ortho.getzfar().getValue().toString());
}
if (ortho.hasxmag() && ortho.hasymag()) {
xmag = Float.parseFloat(ortho.getxmag().getValue().toString());
ymag = Float.parseFloat(ortho.getymag().getValue().toString());
} else {
if (ortho.hasaspect_ratio()) {
aspect = Float.parseFloat(ortho.getaspect_ratio()
.getValue().toString());
}
if (ortho.hasxmag()) {
assert (!ortho.hasymag());
xmag = Float.parseFloat(ortho.getxmag().getValue()
.toString());
ymag = xmag / aspect;
} else {
assert (ortho.hasymag());
ymag = Float.parseFloat(ortho.getymag().getValue()
.toString());
xmag = ymag * aspect;
}
}
c.setParallelProjection(true);
c.setFrustum(near, far, -xmag, xmag, -ymag, ymag);
} else {
assert (common.hasperspective());
perspectiveType persp = common.getperspective();
float xfov = 1.0f;
float yfov = 1.0f;
if (persp.hasznear()) {
near = Float.parseFloat(persp.getznear().getValue().toString());
}
if (persp.haszfar()) {
far = Float.parseFloat(persp.getzfar().getValue().toString());
}
if (persp.hasxfov() && persp.hasyfov()) {
xfov = Float.parseFloat(persp.getxfov().getValue().toString());
yfov = Float.parseFloat(persp.getyfov().getValue().toString());
} else {
if (persp.hasaspect_ratio()) {
aspect = Float.parseFloat(persp.getaspect_ratio()
.getValue().toString());
}
if (persp.hasxfov()) {
assert (!persp.hasyfov());
xfov = Float.parseFloat(persp.getxfov().getValue()
.toString());
yfov = xfov / aspect;
} else {
assert (persp.hasyfov());
yfov = Float.parseFloat(persp.getyfov().getValue()
.toString());
xfov = yfov * aspect;
}
}
c.setParallelProjection(false);
c.setFrustumPerspective(yfov, aspect, near, far);
}
if (cameraNodeNames == null) {
cameraNodeNames = new ArrayList<String>();
}
CameraNode nodeCamera = new CameraNode(camera.getid().toString(), c);
// cameras are odd in that their rotation is typically exported
// backwards from the direction that they're looking in the scene
if ("X_UP".equals(upAxis))
nodeCamera.setLocalRotation(new Quaternion(1, 0, 0, 0));
else if ("Y_UP".equals(upAxis))
nodeCamera.setLocalRotation(new Quaternion(0, 1, 0, 0));
else if ("Z_UP".equals(upAxis))
nodeCamera.setLocalRotation(new Quaternion(0, 0, 1, 0));
cameraNodeNames.add(nodeCamera.getName());
put(nodeCamera.getName(), nodeCamera);
}
/**
* processImageLibrary will build a collection of image filenames. The image
* tag contains the full directory path of the image from the artists
* working directory. Therefore, the directory will be stripped off leaving
* only the filename. This filename will be associated with a id key that
* can be obtained by the material that wishes to make use of it.
*
* @param libraryImg
* the library of images (name/image pair).
*/
private void processImageLibrary(library_imagesType libraryImg)
throws Exception {
if (libraryImg.hasimage()) {
for (int i = 0; i < libraryImg.getimageCount(); i++) {
processImage(libraryImg.getimageAt(i));
}
}
}
/**
* processImage takes an image type and places the necessary information in
* the resource library.
*
* @param image
* the image to process.
* @throws Exception
* thrown if there is a problem with the imagetype.
*/
private void processImage(imageType image) throws Exception {
if (image.hasdata()) {
if (!squelch) {
logger.warning("Raw data images not supported.");
}
}
if (image.hasinit_from()) {
put(image.getid().toString(), image.getinit_from().toString());
}
}
/**
* processMaterialLibrary will build a collection (Map) of MaterialStates,
* with the defined material id as the key in the Map. This map and
* corresponding key will then be used to apply materials to the appropriate
* node. The library only defines the id of the material and the url of the
* instance effect that defines its qualities, it won't be until the
* library_effects tag is processed that the material state information is
* filled in.
*
* @param libraryMat
* the material library type.
* @throws Exception
* thrown if there is a problem processing the xml.
*/
private void processMaterialLibrary(library_materialsType libraryMat)
throws Exception {
if (libraryMat.hasmaterial()) {
for (int i = 0; i < libraryMat.getmaterialCount(); i++) {
processMaterial(libraryMat.getmaterialAt(i));
}
}
}
/**
* process Material which typically contains an id and a reference URL to an
* effect.
*
* @param mat
* @throws Exception
* thrown if there is a problem processing the xml.
*/
private void processMaterial(materialType mat) throws Exception {
ColladaMaterial material = new ColladaMaterial();
String url = null;
if (mat.hasinstance_effect()) {
url = mat.getinstance_effect().geturl().toString();
if (url.startsWith("#")) {
url = url.substring(1);
}
put(url, material);
put(mat.getid().toString(), url);
}
if (mat.hasextra()) {
ExtraPluginManager.processExtra(material, mat.getextra());
}
}
/**
* processEffects will build effects as defined by the techinque. The
* appropriate render state will be obtained from the materialMap hashmap
* based on the the name of the effect. Currently, the id of the effect is
* ignored as it is directly tied to the material id. However, in the future
* this may require support.
*
* @param libraryEffects
* the library of effects to build.
* @throws Exception
* thrown if there is a problem processing the xml.
*/
private void processEffects(library_effectsType libraryEffects)
throws Exception {
if (libraryEffects.haseffect()) {
for (int i = 0; i < libraryEffects.geteffectCount(); i++) {
String key = libraryEffects.geteffectAt(i).getid().toString();
ColladaMaterial mat = (ColladaMaterial) resourceLibra
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -