|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "javax_microedition_m3g_SkinnedMesh.h" |
|
18 |
|
19 JNIEXPORT void JNICALL Java_javax_microedition_m3g_SkinnedMesh__1addTransform |
|
20 (JNIEnv* aEnv, jclass, jint aHandle, jint aHBone, jint aWeight, jint aFirstVertex, jint aNumVertices) |
|
21 { |
|
22 M3G_DO_LOCK |
|
23 m3gAddTransform((M3GSkinnedMesh)aHandle, (M3GNode)aHBone, aWeight, aFirstVertex, aNumVertices); |
|
24 M3G_DO_UNLOCK(aEnv) |
|
25 } |
|
26 |
|
27 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_SkinnedMesh__1ctor |
|
28 (JNIEnv* aEnv, jclass, jint aM3g, jint aHVertices, jintArray aHTriangles, jintArray aHAppearances, jint aHSkeleton) |
|
29 { |
|
30 jint* appearances = NULL; |
|
31 if (aHAppearances) |
|
32 { |
|
33 appearances = aEnv->GetIntArrayElements(aHAppearances, NULL); |
|
34 if (appearances == NULL) |
|
35 { |
|
36 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
37 return 0; |
|
38 } |
|
39 } |
|
40 |
|
41 jint* triangles = NULL; |
|
42 if (aHTriangles) |
|
43 { |
|
44 triangles = aEnv->GetIntArrayElements(aHTriangles, NULL); |
|
45 if (triangles == NULL) |
|
46 { |
|
47 if (appearances) |
|
48 { |
|
49 aEnv->ReleaseIntArrayElements(aHAppearances, appearances, JNI_ABORT); |
|
50 } |
|
51 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
52 return 0; |
|
53 } |
|
54 } |
|
55 jint numTriangles = aEnv->GetArrayLength(aHTriangles); |
|
56 M3GInterface m3g = (M3GInterface) aM3g; |
|
57 |
|
58 M3G_DO_LOCK |
|
59 M3Guint ret = (M3Guint)m3gCreateSkinnedMesh(m3g, |
|
60 (M3GVertexBuffer)aHVertices, |
|
61 (M3GIndexBuffer*)triangles, |
|
62 (M3GAppearance *)appearances, |
|
63 numTriangles, |
|
64 (M3GGroup)aHSkeleton); |
|
65 M3G_DO_UNLOCK(aEnv) |
|
66 |
|
67 if (appearances) |
|
68 { |
|
69 aEnv->ReleaseIntArrayElements(aHAppearances, appearances, JNI_ABORT); |
|
70 } |
|
71 if (triangles) |
|
72 { |
|
73 aEnv->ReleaseIntArrayElements(aHTriangles, triangles, JNI_ABORT); |
|
74 } |
|
75 |
|
76 return ret; |
|
77 } |
|
78 |
|
79 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_SkinnedMesh__1getSkeleton |
|
80 (JNIEnv* aEnv, jclass, jint aHandle) |
|
81 { |
|
82 M3G_DO_LOCK |
|
83 jint skeleton = (M3Guint)m3gGetSkeleton((M3GSkinnedMesh)aHandle); |
|
84 M3G_DO_UNLOCK(aEnv) |
|
85 return skeleton; |
|
86 } |
|
87 |
|
88 /* M3G 1.1 JNI Calls */ |
|
89 |
|
90 JNIEXPORT void JNICALL Java_javax_microedition_m3g_SkinnedMesh__1getBoneTransform |
|
91 (JNIEnv* aEnv, jclass, jint aHandle, jint aBone, jbyteArray aTransform) |
|
92 { |
|
93 jbyte *transform = NULL; |
|
94 if (aTransform) |
|
95 { |
|
96 transform = aEnv->GetByteArrayElements(aTransform, NULL); |
|
97 if (transform == NULL) |
|
98 { |
|
99 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
100 return; |
|
101 } |
|
102 } |
|
103 |
|
104 M3G_DO_LOCK |
|
105 m3gGetBoneTransform((M3GSkinnedMesh)aHandle, (M3GNode)aBone, (M3GMatrix *)transform); |
|
106 M3G_DO_UNLOCK(aEnv) |
|
107 |
|
108 if (transform) |
|
109 { |
|
110 /* Update array to java side and release arrays */ |
|
111 aEnv->ReleaseByteArrayElements(aTransform, transform, 0); |
|
112 } |
|
113 } |
|
114 |
|
115 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_SkinnedMesh__1getBoneVertices |
|
116 (JNIEnv* aEnv, jclass, jint aHandle, jint aBone, jintArray aIndices, jfloatArray aWeights) |
|
117 { |
|
118 int *indices = NULL; |
|
119 float *weights = NULL; |
|
120 jint vertices = 0; |
|
121 |
|
122 /* get indices int array */ |
|
123 if (aIndices != NULL) |
|
124 { |
|
125 indices = aEnv->GetIntArrayElements(aIndices, NULL); |
|
126 if (indices == NULL) |
|
127 { |
|
128 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
129 return 0; |
|
130 } |
|
131 } |
|
132 |
|
133 /* get weights float array */ |
|
134 if (aWeights != NULL) |
|
135 { |
|
136 weights = aEnv->GetFloatArrayElements(aWeights, NULL); |
|
137 if (weights == NULL) |
|
138 { |
|
139 if (indices) |
|
140 { |
|
141 /* Release indices int array*/ |
|
142 aEnv->ReleaseIntArrayElements(aIndices, indices, JNI_ABORT); |
|
143 } |
|
144 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
145 return 0; |
|
146 } |
|
147 } |
|
148 |
|
149 M3G_DO_LOCK |
|
150 /* Get number of vertices */ |
|
151 int requiredLength = m3gGetBoneVertices((M3GSkinnedMesh)aHandle, (M3GNode)aBone, NULL, NULL); |
|
152 M3G_DO_UNLOCK(aEnv) |
|
153 |
|
154 /* If return value is 0, an error has occured so we leave here */ |
|
155 if (requiredLength == 0) |
|
156 { |
|
157 |
|
158 /* release arrays before exiting */ |
|
159 if (indices) |
|
160 { |
|
161 /* Release indices int array */ |
|
162 aEnv->ReleaseIntArrayElements(aIndices, indices, JNI_ABORT); |
|
163 } |
|
164 if (weights) |
|
165 { |
|
166 /* Release indices int array */ |
|
167 aEnv->ReleaseFloatArrayElements(aWeights, weights, JNI_ABORT); |
|
168 } |
|
169 return 0; |
|
170 } |
|
171 /* |
|
172 * If either of arrays is null, lengths are not checked. |
|
173 * If length validation fails, exception is automatically raised. |
|
174 */ |
|
175 if (indices != NULL && weights != NULL && |
|
176 (!validateArray(aEnv, (jbyteArray)aIndices, requiredLength) || |
|
177 !validateArray(aEnv, (jbyteArray)aWeights, requiredLength))) |
|
178 { |
|
179 |
|
180 /* release arrays here */ |
|
181 if (indices) |
|
182 { |
|
183 /* Release indices int array */ |
|
184 aEnv->ReleaseIntArrayElements(aIndices, indices, JNI_ABORT); |
|
185 } |
|
186 if (weights) |
|
187 { |
|
188 /* Release indices int array */ |
|
189 aEnv->ReleaseFloatArrayElements(aWeights, weights, JNI_ABORT); |
|
190 } |
|
191 |
|
192 return 0; |
|
193 } |
|
194 else |
|
195 { |
|
196 M3G_DO_LOCK |
|
197 vertices = m3gGetBoneVertices((M3GSkinnedMesh)aHandle, (M3GNode)aBone, indices, weights); |
|
198 M3G_DO_UNLOCK(aEnv) |
|
199 } |
|
200 |
|
201 if (indices) |
|
202 { |
|
203 /* Update array to java side and release arrays */ |
|
204 aEnv->ReleaseIntArrayElements(aIndices, indices, 0); |
|
205 } |
|
206 if (weights) |
|
207 { |
|
208 /* Update array to java side and release arrays */ |
|
209 aEnv->ReleaseFloatArrayElements(aWeights, weights, 0); |
|
210 } |
|
211 return vertices; |
|
212 } |
|
213 |