Skip to content

Commit

Permalink
VertexAttributes: add a constructor and 3 public setters
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 10, 2025
1 parent d2ca45b commit f81256b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024 Stephen Gold
Copyright (c) 2024-2025 Stephen Gold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -36,6 +36,14 @@ public class VertexAttributes
// *************************************************************************
// constructors

/**
* Instantiate default attributes.
*/
public VertexAttributes() {
long attributesVa = createDefault();
setVirtualAddress(attributesVa, () -> free(attributesVa));
}

/**
* Instantiate attributes as specified.
*
Expand Down Expand Up @@ -90,6 +98,48 @@ public VertexAttributes(float compliance, float shearCompliance,
setVirtualAddress(attributesVa, () -> free(attributesVa));
}
// *************************************************************************
// new methods exposed

/**
* Alter the compliance of normal/regular edges. (native attribute:
* mCompliance)
*
* @param compliance the desired compliance value
* @return the argument, for chaining
*/
public float setCompliance(float compliance) {
long attributesVa = va();
setCompliance(attributesVa, compliance);

return compliance;
}

/**
* Alter the type of the long-range attachment (LRA) constraint. (native
* attribute: mLRAType)
*
* @param type the desired type (not null)
*/
public void setLraType(ELraType type) {
long attributesVa = va();
int ordinal = type.ordinal();
setLraType(attributesVa, ordinal);
}

/**
* Alter the compliance of the shear edges. (native attribute:
* mShearCompliance)
*
* @param compliance the desired compliance value
* @return the argument, for chaining
*/
public float setShearCompliance(float compliance) {
long attributesVa = va();
setShearCompliance(attributesVa, compliance);

return compliance;
}
// *************************************************************************
// ConstVertexAttributes methods

/**
Expand Down Expand Up @@ -170,6 +220,8 @@ native private static long createAttributes(
float compliance, float shearCompliance, float bendCompliance,
int ordinal, float lraMultiplier);

native private static long createDefault();

native private static void free(long attributesVa);

native private static float getBendCompliance(long attributesVa);
Expand All @@ -181,4 +233,12 @@ native private static long createAttributes(
native private static int getLraType(long attributesVa);

native private static float getShearCompliance(long attributesVa);

native private static void setCompliance(
long attributesVa, float compliance);

native private static void setLraType(long attributesVa, int ordinal);

native private static void setShearCompliance(
long attributesVa, float compliance);
}
53 changes: 52 additions & 1 deletion src/main/native/glue/v/VertexAttributes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024 Stephen Gold
Copyright (c) 2024-2025 Stephen Gold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -47,6 +47,19 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_cre
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_VertexAttributes
* Method: createDefault
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_createDefault
(JNIEnv *, jclass) {
SoftBodySharedSettings::VertexAttributes * const pResult
= new SoftBodySharedSettings::VertexAttributes();
TRACE_NEW("SoftBodySharedSettings::VertexAttributes", pResult)
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_VertexAttributes
* Method: free
Expand Down Expand Up @@ -123,4 +136,42 @@ JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_ge
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
const float result = pAttributes->mShearCompliance;
return result;
}

/*
* Class: com_github_stephengold_joltjni_VertexAttributes
* Method: setCompliance
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_setCompliance
(JNIEnv *, jclass, jlong attributesVa, jfloat compliance) {
SoftBodySharedSettings::VertexAttributes * const pAttributes
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
pAttributes->mCompliance = compliance;
}

/*
* Class: com_github_stephengold_joltjni_VertexAttributes
* Method: setLraType
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_setLraType
(JNIEnv *, jclass, jlong attributesVa, jint ordinal) {
SoftBodySharedSettings::VertexAttributes * const pAttributes
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
const SoftBodySharedSettings::ELRAType value
= (SoftBodySharedSettings::ELRAType) ordinal;
pAttributes->mLRAType = value;
}

/*
* Class: com_github_stephengold_joltjni_VertexAttributes
* Method: setShearCompliance
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VertexAttributes_setShearCompliance
(JNIEnv *, jclass, jlong attributesVa, jfloat compliance) {
SoftBodySharedSettings::VertexAttributes * const pAttributes
= reinterpret_cast<SoftBodySharedSettings::VertexAttributes *> (attributesVa);
pAttributes->mShearCompliance = compliance;
}

0 comments on commit f81256b

Please sign in to comment.